diff options
author | zlago | 2024-10-02 18:59:20 +0200 |
---|---|---|
committer | zlago | 2024-10-02 18:59:20 +0200 |
commit | 89f441dd4b07a507aedd1a61791e30b2ce337a34 (patch) | |
tree | 8e9a95fdfe9cdfb2a1a5b4c6261fbdf90ff27b41 | |
parent | fd0760ebf4a5950b62b8149b4e5c55825240c5f1 (diff) |
render to a buffer
-rw-r--r-- | src/main.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c index 42baa75..6b195b4 100644 --- a/src/main.c +++ b/src/main.c @@ -151,6 +151,8 @@ int main(int const argc, char *const *const argv) { } SDL_RenderSetLogicalSize(renderer, WINDOW_WIDTH, WINDOW_HEIGHT); SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); + + SDL_Texture *framebuffer = SDL_CreateTexture(renderer, SDL_PIXELTYPE_UNKNOWN, SDL_TEXTUREACCESS_TARGET, WINDOW_WIDTH, WINDOW_HEIGHT); { res_init(); @@ -297,9 +299,6 @@ int main(int const argc, char *const *const argv) { fprintf(stderr, "unknown event type %i\n", evt.type); } } - SDL_SetRenderTarget(renderer, NULL); - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); - SDL_RenderClear(renderer); //SDL_RenderCopy(renderer, tilemap->wang_tileset, &(SDL_Rect) {0, 0, 128, 90}, &(SDL_Rect) {0, 0, 128, 90}); if (player[0].update(player)) { @@ -313,10 +312,15 @@ int main(int const argc, char *const *const argv) { if (x < 0) {x = 0;} else if (x + WINDOW_WIDTH > tilemap->width * 8) {x = tilemap->width * 8 - WINDOW_WIDTH;} if (y < 0) {y = 0;} else if (y + WINDOW_HEIGHT > tilemap->height * 8) {y = tilemap->height * 8 - WINDOW_HEIGHT;} + SDL_SetRenderTarget(renderer, framebuffer); tilemap_background(tilemap, x, y, WINDOW_WIDTH, WINDOW_HEIGHT); player[0].draw(player, x, y); tilemap_foreground(tilemap, x, y, WINDOW_WIDTH, WINDOW_HEIGHT); //SDL_RenderCopy(renderer, res_get_texture("meow").data, &(SDL_Rect) {0, 0, 128, 90}, &(SDL_Rect) {0, 0, 128, 90}); + SDL_SetRenderTarget(renderer, NULL); + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); + SDL_RenderClear(renderer); + SDL_RenderCopy(renderer, framebuffer, &(SDL_Rect) {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}, &(SDL_Rect) {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}); // then we wait for the next video frame SDL_RenderPresent(renderer); } |