add an overdraw buffer to allow for layered rendering

This commit is contained in:
2026-10-10 10:33:56 +02:00
parent 9deb40d080
commit ea1e99f022
14 changed files with 176 additions and 38 deletions
+12 -3
View File
@@ -4,13 +4,22 @@
#include <stdbool.h>
#include <stdint.h>
typedef enum {
BASE,
OVERDRAW
} framebuffer_e;
typedef struct {
SDL_Event event;
bool is_running;
bool framebuffer_dirty;
bool framebuffer_base_dirty;
bool framebuffer_overdraw_dirty;
SDL_Rect dirty_rect;
uint16_t width, height;
uint32_t *framebuffer;
// base layer ~ layer 0
uint32_t *framebuffer_base;
// layer on top of that ~ layer 1
uint32_t *framebuffer_overdraw;
} game_state_t;
extern game_state_t *game_state;
@@ -28,4 +37,4 @@ void
engine_start();
void
engine_stop();
engine_stop();
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include <stdint.h>
/**
* animate a rectangle's position changing over time
* => x0 -> x1, y0 -> y1, all else stays the same
*/
void
anim_rect_pos(
uint32_t x0,
uint32_t y0,
uint32_t x1,
uint32_t y1,
uint32_t w,
uint32_t h,
uint32_t color
);
+5 -1
View File
@@ -1,9 +1,12 @@
#pragma once
#include <dangerzone/engine.h>
#include <stdint.h>
void
put_pixel(
framebuffer_e framebuffer,
unsigned int x,
unsigned int y,
uint32_t color
@@ -11,5 +14,6 @@ put_pixel(
void
clear_framebuffer(
framebuffer_e framebuffer,
uint32_t color
);
);
+5 -1
View File
@@ -1,9 +1,12 @@
#pragma once
#include <dangerzone/engine.h>
#include <stdint.h>
void
put_rect(
framebuffer_e framebuffer,
uint32_t x,
uint32_t y,
uint32_t w,
@@ -11,8 +14,9 @@ put_rect(
uint32_t color
);
// TODO: remove, deprecated, you can use put_rect for the same thing
void
clear_rect(int x, int y, int w, int h, uint32_t color);
void
mark_dirty_rect(int x, int y, int w, int h);
mark_dirty_rect(int x, int y, int w, int h);
+5 -1
View File
@@ -1,9 +1,12 @@
#pragma once
#include <dangerzone/engine.h>
#include <stdint.h>
void
put_char(
framebuffer_e framebuffer,
char c,
uint32_t x,
uint32_t y,
@@ -14,6 +17,7 @@ put_char(
void
put_string(
framebuffer_e framebuffer,
const char *text,
uint32_t x,
uint32_t y,
@@ -22,4 +26,4 @@ put_string(
uint32_t line_spacing,
uint32_t fg_color,
uint32_t bg_color
);
);