summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2023-07-08 15:03:05 -0700
committer3gg <3gg@shellblade.net>2023-07-08 15:03:05 -0700
commit4fd6b58064bd26df93b05e39438dab649a65633c (patch)
tree4f7394f204933bdd6816d6dc5a38a2c16407c6d7
parent21a0d0c1c424f7db90c3282aad4bf6ad4ef809b7 (diff)
Add pixel scaling.
-rw-r--r--gfx-iso/app/app.h1
-rw-r--r--gfx-iso/app/isogfx-demo.c9
-rw-r--r--gfx-iso/app/main.c16
-rw-r--r--gfx-iso/include/isogfx/isogfx.h5
-rw-r--r--gfx-iso/src/isogfx.c21
5 files changed, 45 insertions, 7 deletions
diff --git a/gfx-iso/app/app.h b/gfx-iso/app/app.h
index 160da47..25e55eb 100644
--- a/gfx-iso/app/app.h
+++ b/gfx-iso/app/app.h
@@ -4,6 +4,7 @@ typedef struct IsoGfx IsoGfx;
4typedef struct IsoGfxApp IsoGfxApp; 4typedef struct IsoGfxApp IsoGfxApp;
5 5
6typedef struct IsoGfxApp { 6typedef struct IsoGfxApp {
7 int pixel_scale; // 0 or 1 for 1:1 scale.
7 void* state; 8 void* state;
8 void (*shutdown)(IsoGfx*, void* state); 9 void (*shutdown)(IsoGfx*, void* state);
9 void (*update)(IsoGfx*, void* state, double t, double dt); 10 void (*update)(IsoGfx*, void* state, double t, double dt);
diff --git a/gfx-iso/app/isogfx-demo.c b/gfx-iso/app/isogfx-demo.c
index 15ab6be..d463d1c 100644
--- a/gfx-iso/app/isogfx-demo.c
+++ b/gfx-iso/app/isogfx-demo.c
@@ -54,10 +54,11 @@ bool make_demo_app(IsoGfx* iso, IsoGfxApp* app) {
54 goto cleanup; 54 goto cleanup;
55 } 55 }
56 56
57 app->state = state; 57 app->pixel_scale = 2;
58 app->shutdown = shutdown; 58 app->state = state;
59 app->update = update; 59 app->shutdown = shutdown;
60 app->render = render; 60 app->update = update;
61 app->render = render;
61 62
62 return true; 63 return true;
63 64
diff --git a/gfx-iso/app/main.c b/gfx-iso/app/main.c
index fa5a76b..5b441d3 100644
--- a/gfx-iso/app/main.c
+++ b/gfx-iso/app/main.c
@@ -43,6 +43,18 @@ static bool init(const GfxAppDesc* desc, void** app_state) {
43 if (!make_demo_app(state->iso, &state->app)) { 43 if (!make_demo_app(state->iso, &state->app)) {
44 goto cleanup; 44 goto cleanup;
45 } 45 }
46
47 // Apply pixel scaling if requested by the app.
48 int texture_width, texture_height;
49 if (state->app.pixel_scale > 1) {
50 texture_width = SCREEN_WIDTH / state->app.pixel_scale;
51 texture_height = SCREEN_HEIGHT / state->app.pixel_scale;
52 isogfx_resize(state->iso, texture_width, texture_height);
53 } else {
54 texture_width = SCREEN_WIDTH;
55 texture_height = SCREEN_HEIGHT;
56 }
57
46 if (!(state->gfx = gfx_init())) { 58 if (!(state->gfx = gfx_init())) {
47 goto cleanup; 59 goto cleanup;
48 } 60 }
@@ -50,8 +62,8 @@ static bool init(const GfxAppDesc* desc, void** app_state) {
50 62
51 if (!(state->screen_texture = gfx_make_texture( 63 if (!(state->screen_texture = gfx_make_texture(
52 render_backend, &(TextureDesc){ 64 render_backend, &(TextureDesc){
53 .width = SCREEN_WIDTH, 65 .width = texture_width,
54 .height = SCREEN_HEIGHT, 66 .height = texture_height,
55 .dimension = Texture2D, 67 .dimension = Texture2D,
56 .format = TextureSRGBA8, 68 .format = TextureSRGBA8,
57 .filtering = NearestFiltering, 69 .filtering = NearestFiltering,
diff --git a/gfx-iso/include/isogfx/isogfx.h b/gfx-iso/include/isogfx/isogfx.h
index 22c8fd5..5c44310 100644
--- a/gfx-iso/include/isogfx/isogfx.h
+++ b/gfx-iso/include/isogfx/isogfx.h
@@ -93,7 +93,10 @@ void isogfx_render(IsoGfx*);
93/// position (x,y) instead, use isogfx_set_tile(). 93/// position (x,y) instead, use isogfx_set_tile().
94void isogfx_draw_tile(IsoGfx*, int x, int y, Tile); 94void isogfx_draw_tile(IsoGfx*, int x, int y, Tile);
95 95
96/// Return a pointer to the internal colour buffer. 96/// Resize the virtual screen's dimensions.
97bool isogfx_resize(IsoGfx*, int screen_width, int screen_height);
98
99/// Return a pointer to the virtual screen's colour buffer.
97/// 100///
98/// Call after each call to isogfx_render() to retrieve the render output. 101/// Call after each call to isogfx_render() to retrieve the render output.
99const Pixel* isogfx_get_screen_buffer(const IsoGfx*); 102const Pixel* isogfx_get_screen_buffer(const IsoGfx*);
diff --git a/gfx-iso/src/isogfx.c b/gfx-iso/src/isogfx.c
index 17b88b2..ee33cad 100644
--- a/gfx-iso/src/isogfx.c
+++ b/gfx-iso/src/isogfx.c
@@ -603,6 +603,27 @@ void isogfx_draw_tile(IsoGfx* iso, int x, int y, Tile tile) {
603 draw_tile(iso, so, tile); 603 draw_tile(iso, so, tile);
604} 604}
605 605
606bool isogfx_resize(IsoGfx* iso, int screen_width, int screen_height) {
607 assert(iso);
608 assert(iso->screen);
609
610 const int current_size = iso->screen_width * iso->screen_height;
611 const int new_size = screen_width * screen_height;
612
613 if (new_size > current_size) {
614 Pixel* new_screen = calloc(new_size, sizeof(Pixel));
615 if (new_screen) {
616 free(iso->screen);
617 iso->screen = new_screen;
618 } else {
619 return false;
620 }
621 }
622 iso->screen_width = screen_width;
623 iso->screen_height = screen_height;
624 return true;
625}
626
606const Pixel* isogfx_get_screen_buffer(const IsoGfx* iso) { 627const Pixel* isogfx_get_screen_buffer(const IsoGfx* iso) {
607 assert(iso); 628 assert(iso);
608 return iso->screen; 629 return iso->screen;