a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit 086772f2a33920ccb5fee0cf7f95a4d02d49234b
parent 8d9821e849317797b3b60a629b8578c4a841eb9c
Author: amin <dev@aminmesbah.com>
Date:   Thu, 18 Apr 2019 20:16:24 +0000

Render everything with the same projection matrix

FossilOrigin-Name: d458635f11ec1b4f553fe6a21723fddaa9fccf8cfd79180303adc25722217024
Diffstat:
Msrc/game.c | 30++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -112,6 +112,9 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + // Screen origin is in the upper left + m4 projection = glmth_projection_ortho(0.0f, framebuffer.width, framebuffer.height, 0.0f, -1.0f, 0.0f); + // render tiles { glBindVertexArray(game_state->tiles.vao); @@ -159,7 +162,6 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga } shader_setv3(&game_state->tiles.shader, "color", &color); - m4 projection = glmth_projection_ortho(0.0f, framebuffer.width, framebuffer.height, 0.0f, -1.0f, 0.0f); shader_setm4(&game_state->tiles.shader, "projection", &projection); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); @@ -190,8 +192,8 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga { game_state->player.pos.x += movement_speed; } - glmth_clamp(&(game_state->player.pos.x), 0, ROOM_TILE_DIM_X); - glmth_clamp(&(game_state->player.pos.y), 0, ROOM_TILE_DIM_Y); + //glmth_clamp(&(game_state->player.pos.x), 0, ROOM_TILE_DIM_X); + //glmth_clamp(&(game_state->player.pos.y), 0, ROOM_TILE_DIM_Y); } // render player @@ -205,15 +207,35 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga v2 player_dim = { 0.375f, 0.583f }; m4 model = glmth_m4_init_id(); + model = glmth_translate(model, (v3) {0.0f, framebuffer.height, 0.0f}); + model = glmth_scale(model, (v3) {1.0f, -1.0f, 1.0f}); model = glmth_translate(model, (v3) { viewport.min.x, viewport.min.y, 0.0f }); model = glmth_translate(model, (v3) { player.pos.x * ppm, player.pos.y * ppm, 0.0f }); model = glmth_scale(model, (v3) { player_dim.x * ppm, player_dim.y * ppm, 1.0f }); shader_setm4(&game_state->tiles.shader, "model", &model); + { + printf("Framebuffer :"); + glmth_v2_print((v2) {framebuffer.width, framebuffer.height}); + printf("Viewport min:"); + glmth_v2_print(viewport.min); + printf("Viewport max:"); + glmth_v2_print(viewport.max); + printf("World :"); + glmth_v2_print(game_state->player.pos); + // TODO: Why does screen get larger than the framebuffer dimensions? + v4 screen = glmth_m4v4_m(model, (v4) {player.pos.x, player.pos.y, 0.0f, 1.0f}); + printf("Screen :"); + glmth_v2_print((v2) {screen.x, screen.y}); + v4 ndc = glmth_m4v4_m(projection, screen); + // TODO: Why isn't NDC between -1.0 an 1.0? + printf("NDC :"); + glmth_v2_print((v2) {ndc.x, ndc.y}); + } + v3 color = (v3) { 1.0f, 0.0f, 1.0f }; shader_setv3(&game_state->tiles.shader, "color", &color); - m4 projection = glmth_projection_ortho(0.0f, framebuffer.width, 0.0f, framebuffer.height, -1.0f, 0.0f); shader_setm4(&game_state->tiles.shader, "projection", &projection); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);