a-game

2D platformer written from scratch.
Log | Files | Refs | README | LICENSE

commit 889027a1557f46a24ed39c2a223510da6e9a96e8
parent 551909ce974d3ba13b9f2ae107e0a73579b22f3b
Author: Amin Mesbah <dev@aminmesbah.com>
Date:   Fri,  1 Jun 2018 23:37:34 -0700

Update projection matrix w/ framebuffer dimensions

This removes distortion when resizing the window.

Diffstat:
Msrc/game.c | 1+
Msrc/platform_linux.c | 8++++++--
2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -46,6 +46,7 @@ void game_update_and_render(struct GameState *game_state, float dt, uint32_t scr glClearColor(0.1f, 0.1f, 0.1f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); + //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); m4 model = glmth_m4_init_id(); model = glmth_translate(model, glmth_v3_init(300.0f, 300.0f, 0.0f)); model = glmth_translate(model, glmth_v3_init(100.0f * cosf(dt), 100.0f * sinf(dt), 0.0f)); diff --git a/src/platform_linux.c b/src/platform_linux.c @@ -73,6 +73,10 @@ int main(void) lag += elapsed_ms; //printf("%" PRIu64 ", %" PRIu64 ", %f\n", elapsed_ms, lag, PLATFORM_MS_PER_UPDATE); + int32_t framebuffer_width = PLATFORM_SCR_WIDTH; + int32_t framebuffer_height = PLATFORM_SCR_HEIGHT; + glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height); + #ifdef PLATFORM_HOTLOAD_GAME_CODE time_t last_write_time = file_get_modified_time(PLATFORM_GAME_LIB_PATH); bool game_code_has_changed = last_write_time && (last_write_time != game_code.last_write_time); @@ -85,9 +89,9 @@ int main(void) // TODO: fall back to backup? } } - game_code.game_update_and_render(&game_state, lag/PLATFORM_SECOND, PLATFORM_SCR_WIDTH, PLATFORM_SCR_HEIGHT); + game_code.game_update_and_render(&game_state, lag/PLATFORM_SECOND, framebuffer_width, framebuffer_height); #else - game_update_and_render(&game_state, lag/PLATFORM_SECOND, PLATFORM_SCR_WIDTH, PLATFORM_SCR_HEIGHT); + game_update_and_render(&game_state, lag/PLATFORM_SECOND, framebuffer_width, framebuffer_height); #endif // PLATFORM_HOTLOAD_GAME_CODE glfwSwapBuffers(window);