summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-08-29 20:11:29 -0700
committer3gg <3gg@shellblade.net>2024-08-29 20:11:29 -0700
commit7a59d85dfead20dc34081badad6c8940e7190001 (patch)
treeef1b47f5fb68c6f7b1b77bcef281a73cdd0b5f08
parent4e545b237f0f306c21073bc646aa7fe00ed71136 (diff)
Sort out window vs screen dimensions.
-rw-r--r--gfx-iso/include/isogfx/app.h4
-rw-r--r--gfx-iso/src/app.c30
2 files changed, 16 insertions, 18 deletions
diff --git a/gfx-iso/include/isogfx/app.h b/gfx-iso/include/isogfx/app.h
index 769af6d..fe60d04 100644
--- a/gfx-iso/include/isogfx/app.h
+++ b/gfx-iso/include/isogfx/app.h
@@ -4,13 +4,15 @@
4 4
5#include <stdbool.h> 5#include <stdbool.h>
6 6
7// TODO: Define an isogfx-gl backend library. Remove all these callbacks.
8
7typedef struct IsoGfx IsoGfx; 9typedef struct IsoGfx IsoGfx;
8typedef struct IsoGfxApp IsoGfxApp; 10typedef struct IsoGfxApp IsoGfxApp;
9 11
10typedef struct IsoGfxAppState IsoGfxAppState; 12typedef struct IsoGfxAppState IsoGfxAppState;
11 13
12typedef struct IsoGfxApp { 14typedef struct IsoGfxApp {
13 int pixel_scale; // 0 or 1 for 1:1 scale. 15 int pixel_scale; // Use 0 or 1 for 1:1 scaling.
14 IsoGfxAppState* state; 16 IsoGfxAppState* state;
15 17
16 bool (*init)(IsoGfxAppState*, IsoGfx*, int argc, const char** argv); 18 bool (*init)(IsoGfxAppState*, IsoGfx*, int argc, const char** argv);
diff --git a/gfx-iso/src/app.c b/gfx-iso/src/app.c
index e07f318..aaeb205 100644
--- a/gfx-iso/src/app.c
+++ b/gfx-iso/src/app.c
@@ -13,8 +13,8 @@
13#include <stdbool.h> 13#include <stdbool.h>
14#include <stdlib.h> 14#include <stdlib.h>
15 15
16static const int SCREEN_WIDTH = 1408; 16static const int WINDOW_WIDTH = 1408;
17static const int SCREEN_HEIGHT = 960; 17static const int WINDOW_HEIGHT = 960;
18static const int MAX_FPS = 60; 18static const int MAX_FPS = 60;
19 19
20typedef struct AppState { 20typedef struct AppState {
@@ -35,8 +35,13 @@ static bool init(GfxAppState* gfx_app_state, int argc, const char** argv) {
35 35
36 IsoGfxApp* app = state->app; 36 IsoGfxApp* app = state->app;
37 37
38 // Virtual screen dimensions.
39 const int scale = app->pixel_scale == 0 ? 1 : app->pixel_scale;
40 const int screen_width = WINDOW_WIDTH / scale;
41 const int screen_height = WINDOW_HEIGHT / scale;
42
38 if (!(state->iso = isogfx_new(&(IsoGfxDesc){ 43 if (!(state->iso = isogfx_new(&(IsoGfxDesc){
39 .screen_width = SCREEN_WIDTH, .screen_height = SCREEN_HEIGHT}))) { 44 .screen_width = screen_width, .screen_height = screen_height}))) {
40 goto cleanup; 45 goto cleanup;
41 } 46 }
42 47
@@ -44,16 +49,7 @@ static bool init(GfxAppState* gfx_app_state, int argc, const char** argv) {
44 goto cleanup; 49 goto cleanup;
45 } 50 }
46 51
47 // Apply pixel scaling if requested by the app. 52 isogfx_resize(state->iso, screen_width, screen_height);
48 int texture_width, texture_height;
49 if (app->pixel_scale > 1) {
50 texture_width = SCREEN_WIDTH / app->pixel_scale;
51 texture_height = SCREEN_HEIGHT / 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 53
58 if (!(state->gfx = gfx_init())) { 54 if (!(state->gfx = gfx_init())) {
59 goto cleanup; 55 goto cleanup;
@@ -62,8 +58,8 @@ static bool init(GfxAppState* gfx_app_state, int argc, const char** argv) {
62 58
63 if (!(state->screen_texture = gfx_make_texture( 59 if (!(state->screen_texture = gfx_make_texture(
64 gfxcore, &(TextureDesc){ 60 gfxcore, &(TextureDesc){
65 .width = texture_width, 61 .width = screen_width,
66 .height = texture_height, 62 .height = screen_height,
67 .dimension = Texture2D, 63 .dimension = Texture2D,
68 .format = TextureSRGBA8, 64 .format = TextureSRGBA8,
69 .filtering = NearestFiltering, 65 .filtering = NearestFiltering,
@@ -183,8 +179,8 @@ void iso_run(int argc, const char** argv, IsoGfxApp* app) {
183 &(GfxAppDesc){ 179 &(GfxAppDesc){
184 .argc = argc, 180 .argc = argc,
185 .argv = argv, 181 .argv = argv,
186 .width = SCREEN_WIDTH, 182 .width = WINDOW_WIDTH,
187 .height = SCREEN_HEIGHT, 183 .height = WINDOW_HEIGHT,
188 .max_fps = MAX_FPS, 184 .max_fps = MAX_FPS,
189 .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0, 185 .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0,
190 .title = "Isometric Renderer", 186 .title = "Isometric Renderer",