aboutsummaryrefslogtreecommitdiff
path: root/gfx-iso/demos
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-06-27 10:18:39 -0700
committer3gg <3gg@shellblade.net>2025-06-27 10:18:39 -0700
commitbd57f345ed9dbed1d81683e48199626de2ea9044 (patch)
tree4221f2f2a7ad2244d2e93052bd68187ec91b8ea9 /gfx-iso/demos
parent9a82ce0083437a4f9f58108b2c23b957d2249ad8 (diff)
Restructure projectHEADmain
Diffstat (limited to 'gfx-iso/demos')
-rw-r--r--gfx-iso/demos/CMakeLists.txt2
-rw-r--r--gfx-iso/demos/checkerboard/CMakeLists.txt16
-rw-r--r--gfx-iso/demos/checkerboard/checkerboard.c166
-rw-r--r--gfx-iso/demos/isomap/CMakeLists.txt16
-rw-r--r--gfx-iso/demos/isomap/isomap.c105
5 files changed, 0 insertions, 305 deletions
diff --git a/gfx-iso/demos/CMakeLists.txt b/gfx-iso/demos/CMakeLists.txt
deleted file mode 100644
index c0a4101..0000000
--- a/gfx-iso/demos/CMakeLists.txt
+++ /dev/null
@@ -1,2 +0,0 @@
1add_subdirectory(checkerboard)
2add_subdirectory(isomap)
diff --git a/gfx-iso/demos/checkerboard/CMakeLists.txt b/gfx-iso/demos/checkerboard/CMakeLists.txt
deleted file mode 100644
index d1691c6..0000000
--- a/gfx-iso/demos/checkerboard/CMakeLists.txt
+++ /dev/null
@@ -1,16 +0,0 @@
1cmake_minimum_required(VERSION 3.0)
2
3project(checkerboard)
4
5set(CMAKE_C_STANDARD 17)
6set(CMAKE_C_STANDARD_REQUIRED On)
7set(CMAKE_C_EXTENSIONS Off)
8
9add_executable(checkerboard
10 checkerboard.c)
11
12target_link_libraries(checkerboard PRIVATE
13 gfx-app
14 isogfx-backend)
15
16target_compile_options(checkerboard PRIVATE -Wall -Wextra -Wpedantic)
diff --git a/gfx-iso/demos/checkerboard/checkerboard.c b/gfx-iso/demos/checkerboard/checkerboard.c
deleted file mode 100644
index dbc817c..0000000
--- a/gfx-iso/demos/checkerboard/checkerboard.c
+++ /dev/null
@@ -1,166 +0,0 @@
1#include <isogfx/backend.h>
2#include <isogfx/isogfx.h>
3
4#include <gfx/app.h>
5
6#include <assert.h>
7#include <stdbool.h>
8#include <stdio.h>
9
10static const int WINDOW_WIDTH = 1408;
11static const int WINDOW_HEIGHT = 960;
12static const int MAX_FPS = 60;
13
14// Virtual screen dimensions.
15static const int SCREEN_WIDTH = 704;
16static const int SCREEN_HEIGHT = 480;
17
18static const int TILE_WIDTH = 32;
19static const int TILE_HEIGHT = TILE_WIDTH / 2;
20static const int WORLD_WIDTH = 20;
21static const int WORLD_HEIGHT = 20;
22
23static const TileDesc tile_set[] = {
24 {.type = TileFromColour,
25 .width = TILE_WIDTH,
26 .height = TILE_HEIGHT,
27 .colour = (Pixel){.r = 0x38, .g = 0x3b, .b = 0x46, .a = 0xff}},
28 {.type = TileFromColour,
29 .width = TILE_WIDTH,
30 .height = TILE_HEIGHT,
31 .colour = (Pixel){.r = 0xA5, .g = 0xb3, .b = 0xc0, .a = 0xff}},
32 {.type = TileFromColour,
33 .width = TILE_WIDTH,
34 .height = TILE_HEIGHT,
35 .colour = (Pixel){.r = 0xdc, .g = 0x76, .b = 0x84, .a = 0xff}},
36};
37
38typedef enum Colour {
39 Black,
40 White,
41 Red,
42} Colour;
43
44typedef struct GfxAppState {
45 IsoBackend* backend;
46 IsoGfx* iso;
47 Tile red;
48 int xpick;
49 int ypick;
50} GfxAppState;
51
52static void make_checkerboard(IsoGfx* iso, Tile black, Tile white) {
53 assert(iso);
54 for (int y = 0; y < isogfx_world_height(iso); ++y) {
55 for (int x = 0; x < isogfx_world_width(iso); ++x) {
56 const int odd_col = x & 1;
57 const int odd_row = y & 1;
58 const Tile value = (odd_row ^ odd_col) == 0 ? black : white;
59 isogfx_set_tile(iso, x, y, value);
60 }
61 }
62}
63
64static bool init(GfxAppState* state, int argc, const char** argv) {
65 assert(state);
66
67 (void)argc;
68 (void)argv;
69
70 if (!(state->iso = isogfx_new(&(IsoGfxDesc){
71 .screen_width = SCREEN_WIDTH, .screen_height = SCREEN_HEIGHT}))) {
72 return false;
73 }
74 IsoGfx* iso = state->iso;
75
76 isogfx_resize(iso, SCREEN_WIDTH, SCREEN_HEIGHT);
77
78 if (!isogfx_make_world(
79 iso, &(WorldDesc){
80 .tile_width = TILE_WIDTH,
81 .tile_height = TILE_HEIGHT,
82 .world_width = WORLD_WIDTH,
83 .world_height = WORLD_HEIGHT})) {
84 return false;
85 }
86
87 const Tile black = isogfx_make_tile(iso, &tile_set[Black]);
88 const Tile white = isogfx_make_tile(iso, &tile_set[White]);
89 state->red = isogfx_make_tile(iso, &tile_set[Red]);
90 make_checkerboard(iso, black, white);
91
92 if (!(state->backend = IsoBackendInit(iso))) {
93 return false;
94 }
95
96 return true;
97}
98
99static void shutdown(GfxAppState* state) {
100 assert(state);
101
102 IsoBackendShutdown(&state->backend);
103 isogfx_del(&state->iso);
104}
105
106static void update(GfxAppState* state, double t, double dt) {
107 assert(state);
108 (void)dt;
109
110 IsoGfx* iso = state->iso;
111
112 isogfx_update(iso, t);
113
114 // Get mouse position in window coordinates.
115 double mouse_x, mouse_y;
116 gfx_app_get_mouse_position(&mouse_x, &mouse_y);
117
118 // Map from window coordinates to virtual screen coordinates.
119 IsoBackendGetMousePosition(
120 state->backend, mouse_x, mouse_y, &mouse_x, &mouse_y);
121
122 isogfx_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick);
123
124 printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick);
125}
126
127static void render(GfxAppState* state) {
128 assert(state);
129
130 IsoGfx* iso = state->iso;
131
132 isogfx_render(iso);
133
134 if ((state->xpick != -1) && (state->ypick != -1)) {
135 isogfx_draw_tile(iso, state->xpick, state->ypick, state->red);
136 }
137
138 IsoBackendRender(state->backend, iso);
139}
140
141static void resize(GfxAppState* state, int width, int height) {
142 assert(state);
143
144 IsoBackendResizeWindow(state->backend, state->iso, width, height);
145}
146
147int main(int argc, const char** argv) {
148 GfxAppState state = {0};
149 gfx_app_run(
150 &(GfxAppDesc){
151 .argc = argc,
152 .argv = argv,
153 .width = WINDOW_WIDTH,
154 .height = WINDOW_HEIGHT,
155 .max_fps = MAX_FPS,
156 .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0,
157 .title = "Isometric Renderer",
158 .app_state = &state},
159 &(GfxAppCallbacks){
160 .init = init,
161 .update = update,
162 .render = render,
163 .resize = resize,
164 .shutdown = shutdown});
165 return 0;
166}
diff --git a/gfx-iso/demos/isomap/CMakeLists.txt b/gfx-iso/demos/isomap/CMakeLists.txt
deleted file mode 100644
index 2dbfd32..0000000
--- a/gfx-iso/demos/isomap/CMakeLists.txt
+++ /dev/null
@@ -1,16 +0,0 @@
1cmake_minimum_required(VERSION 3.0)
2
3project(isomap)
4
5set(CMAKE_C_STANDARD 17)
6set(CMAKE_C_STANDARD_REQUIRED On)
7set(CMAKE_C_EXTENSIONS Off)
8
9add_executable(isomap
10 isomap.c)
11
12target_link_libraries(isomap PRIVATE
13 gfx-app
14 isogfx-backend)
15
16target_compile_options(isomap PRIVATE -Wall -Wextra -Wpedantic)
diff --git a/gfx-iso/demos/isomap/isomap.c b/gfx-iso/demos/isomap/isomap.c
deleted file mode 100644
index a233659..0000000
--- a/gfx-iso/demos/isomap/isomap.c
+++ /dev/null
@@ -1,105 +0,0 @@
1#include <isogfx/backend.h>
2#include <isogfx/isogfx.h>
3
4#include <gfx/app.h>
5
6#include <assert.h>
7#include <stdbool.h>
8
9static const int WINDOW_WIDTH = 1408;
10static const int WINDOW_HEIGHT = 960;
11static const int MAX_FPS = 60;
12
13// Virtual screen dimensions.
14static const int SCREEN_WIDTH = 704;
15static const int SCREEN_HEIGHT = 480;
16
17typedef struct GfxAppState {
18 IsoBackend* backend;
19 IsoGfx* iso;
20 int xpick;
21 int ypick;
22 SpriteSheet stag_sheet;
23 Sprite stag;
24} GfxAppState;
25
26static bool init(GfxAppState* state, int argc, const char** argv) {
27 assert(state);
28 (void)argc;
29 (void)argv;
30
31 if (!(state->iso = isogfx_new(&(IsoGfxDesc){
32 .screen_width = SCREEN_WIDTH, .screen_height = SCREEN_HEIGHT}))) {
33 return false;
34 }
35 IsoGfx* iso = state->iso;
36
37 isogfx_resize(iso, SCREEN_WIDTH, SCREEN_HEIGHT);
38
39 if (!isogfx_load_world(iso, "/home/jeanne/assets/tilemaps/demo1.tm")) {
40 return false;
41 }
42
43 if (!isogfx_load_sprite_sheet(
44 iso, "/home/jeanne/assets/tilesets/scrabling/critters/stag/stag.ss",
45 &state->stag_sheet)) {
46 return false;
47 }
48
49 state->stag = isogfx_make_sprite(iso, state->stag_sheet);
50 isogfx_set_sprite_position(iso, state->stag, 5, 4);
51
52 if (!(state->backend = IsoBackendInit(iso))) {
53 return false;
54 }
55
56 return true;
57}
58
59static void shutdown(GfxAppState* state) {
60 assert(state);
61 //
62}
63
64static void update(GfxAppState* state, double t, double dt) {
65 assert(state);
66 (void)dt;
67
68 IsoGfx* iso = state->iso;
69 isogfx_update(iso, t);
70}
71
72static void render(GfxAppState* state) {
73 assert(state);
74
75 IsoGfx* iso = state->iso;
76 isogfx_render(iso);
77 IsoBackendRender(state->backend, iso);
78}
79
80static void resize(GfxAppState* state, int width, int height) {
81 assert(state);
82
83 IsoBackendResizeWindow(state->backend, state->iso, width, height);
84}
85
86int main(int argc, const char** argv) {
87 GfxAppState state = {0};
88 gfx_app_run(
89 &(GfxAppDesc){
90 .argc = argc,
91 .argv = argv,
92 .width = WINDOW_WIDTH,
93 .height = WINDOW_HEIGHT,
94 .max_fps = MAX_FPS,
95 .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0,
96 .title = "Isometric Renderer",
97 .app_state = &state},
98 &(GfxAppCallbacks){
99 .init = init,
100 .update = update,
101 .render = render,
102 .resize = resize,
103 .shutdown = shutdown});
104 return 0;
105}