diff options
| -rw-r--r-- | game/src/game.c | 10 | ||||
| -rw-r--r-- | game/src/game.h | 2 | ||||
| -rw-r--r-- | game/src/plugins/gltf_view.c | 16 | ||||
| -rw-r--r-- | game/src/plugins/plugin.h | 2 | ||||
| -rw-r--r-- | game/src/plugins/texture_view.c | 3 |
5 files changed, 28 insertions, 5 deletions
diff --git a/game/src/game.c b/game/src/game.c index 64be4f3..c720656 100644 --- a/game/src/game.c +++ b/game/src/game.c | |||
| @@ -197,6 +197,10 @@ void app_update(Game* game, double t, double dt) { | |||
| 197 | shutdown_plugin(game); | 197 | shutdown_plugin(game); |
| 198 | const bool result = init_plugin(game); | 198 | const bool result = init_plugin(game); |
| 199 | assert(result); // TODO: handle error better. | 199 | assert(result); // TODO: handle error better. |
| 200 | |||
| 201 | // Trigger a resize just like the initial resize that occurs when the gfx | ||
| 202 | // application starts. | ||
| 203 | resize_plugin(game, game->width, game->height); | ||
| 200 | } | 204 | } |
| 201 | 205 | ||
| 202 | update_plugin(game, t, dt); | 206 | update_plugin(game, t, dt); |
| @@ -210,6 +214,12 @@ void app_render(const Game* game) { | |||
| 210 | } | 214 | } |
| 211 | 215 | ||
| 212 | void app_resize(Game* game, int width, int height) { | 216 | void app_resize(Game* game, int width, int height) { |
| 217 | game->width = width; | ||
| 218 | game->height = height; | ||
| 219 | |||
| 220 | RenderBackend* render_backend = gfx_get_render_backend(game->gfx); | ||
| 221 | gfx_set_viewport(render_backend, width, height); | ||
| 222 | |||
| 213 | resize_plugin(game, width, height); | 223 | resize_plugin(game, width, height); |
| 214 | } | 224 | } |
| 215 | 225 | ||
diff --git a/game/src/game.h b/game/src/game.h index 93a5e39..579ba3c 100644 --- a/game/src/game.h +++ b/game/src/game.h | |||
| @@ -16,4 +16,6 @@ typedef struct { | |||
| 16 | PluginEngine* plugin_engine; | 16 | PluginEngine* plugin_engine; |
| 17 | Plugin* plugin; | 17 | Plugin* plugin; |
| 18 | Gfx* gfx; | 18 | Gfx* gfx; |
| 19 | int width; | ||
| 20 | int height; | ||
| 19 | } Game; | 21 | } Game; |
diff --git a/game/src/plugins/gltf_view.c b/game/src/plugins/gltf_view.c index c19d1b8..4ffdd1e 100644 --- a/game/src/plugins/gltf_view.c +++ b/game/src/plugins/gltf_view.c | |||
| @@ -169,7 +169,7 @@ static void render_bounding_boxes(ImmRenderer* imm, const SceneNode* node) { | |||
| 169 | const SceneObject* obj = gfx_get_node_object(node); | 169 | const SceneObject* obj = gfx_get_node_object(node); |
| 170 | const aabb3 box = gfx_calc_object_aabb(obj); | 170 | const aabb3 box = gfx_calc_object_aabb(obj); |
| 171 | gfx_imm_set_model_matrix(imm, &model); | 171 | gfx_imm_set_model_matrix(imm, &model); |
| 172 | gfx_imm_draw_aabb(imm, box); | 172 | gfx_imm_draw_aabb3(imm, box); |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | // Render children's boxes. | 175 | // Render children's boxes. |
| @@ -194,3 +194,17 @@ void render(const Game* game, const State* state) { | |||
| 194 | render_bounding_boxes(imm, gfx_get_scene_root(state->scene)); | 194 | render_bounding_boxes(imm, gfx_get_scene_root(state->scene)); |
| 195 | gfx_imm_end(imm); | 195 | gfx_imm_end(imm); |
| 196 | } | 196 | } |
| 197 | |||
| 198 | void resize(Game* game, State* state, int width, int height) { | ||
| 199 | assert(game); | ||
| 200 | assert(state); | ||
| 201 | |||
| 202 | const R fovy = 90 * TO_RAD; | ||
| 203 | const R aspect = (R)width / (R)height; | ||
| 204 | const R near = 0.1; | ||
| 205 | const R far = 1000; | ||
| 206 | const mat4 projection = mat4_perspective(fovy, aspect, near, far); | ||
| 207 | |||
| 208 | Camera* camera = gfx_get_camera_camera(state->camera); | ||
| 209 | camera->projection = projection; | ||
| 210 | } | ||
diff --git a/game/src/plugins/plugin.h b/game/src/plugins/plugin.h index a2632cd..f7219c6 100644 --- a/game/src/plugins/plugin.h +++ b/game/src/plugins/plugin.h | |||
| @@ -41,7 +41,7 @@ void update(Game*, State*, double t, double dt); | |||
| 41 | void render(const Game*, const State*); | 41 | void render(const Game*, const State*); |
| 42 | 42 | ||
| 43 | /// Called when the game's window is resized. | 43 | /// Called when the game's window is resized. |
| 44 | void resize(Game* game, State* state, int width, int height); | 44 | void resize(Game*, State*, int width, int height); |
| 45 | 45 | ||
| 46 | // Signatures for the plugin's exposed functions. | 46 | // Signatures for the plugin's exposed functions. |
| 47 | typedef bool (*plugin_init)(Game*, State**); | 47 | typedef bool (*plugin_init)(Game*, State**); |
diff --git a/game/src/plugins/texture_view.c b/game/src/plugins/texture_view.c index b424158..31bf23e 100644 --- a/game/src/plugins/texture_view.c +++ b/game/src/plugins/texture_view.c | |||
| @@ -133,9 +133,6 @@ void resize(Game* game, State* state, int width, int height) { | |||
| 133 | assert(game); | 133 | assert(game); |
| 134 | assert(state); | 134 | assert(state); |
| 135 | 135 | ||
| 136 | RenderBackend* render_backend = gfx_get_render_backend(game->gfx); | ||
| 137 | gfx_set_viewport(render_backend, width, height); | ||
| 138 | |||
| 139 | const R fovy = 90 * TO_RAD; | 136 | const R fovy = 90 * TO_RAD; |
| 140 | const R aspect = (R)width / (R)height; | 137 | const R aspect = (R)width / (R)height; |
| 141 | const R near = 0.1; | 138 | const R near = 0.1; |
