commit 055819cc19b9b3d317927ffc126b24e4f79b3fee
parent 086772f2a33920ccb5fee0cf7f95a4d02d49234b
Author: amin <dev@aminmesbah.com>
Date: Fri, 19 Apr 2019 23:17:53 +0000
Use a view matrix
FossilOrigin-Name: 7d17b5c216a8347470c434c0153dedc2fd745fcb7f89e7953176275995ff4f47
Diffstat:
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/shader/main_v.glsl b/shader/main_v.glsl
@@ -5,11 +5,12 @@ layout (location = 0) in vec2 position;
out vec4 vertex_color;
uniform mat4 model;
+uniform mat4 view;
uniform mat4 projection;
uniform vec3 color;
void main()
{
- gl_Position = projection * model * vec4(position, 0.0f, 1.0f);
+ gl_Position = projection * view * model * vec4(position, 0.0f, 1.0f);
vertex_color = vec4(color, 1.0f);
}
diff --git a/src/game.c b/src/game.c
@@ -150,7 +150,8 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
model = glmth_translate(model, (v3) { viewport.min.x + (tile_size * x), viewport.min.y + (tile_size * y), 0.0f });
model = glmth_scale(model, (v3) {tile_size, tile_size, 1.0f});
- shader_setm4(&game_state->tiles.shader, "model", &model);
+ m4 view = glmth_m4_init_id();
+
v3 color;
if (tile_id > 0)
{
@@ -162,6 +163,8 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
}
shader_setv3(&game_state->tiles.shader, "color", &color);
+ shader_setm4(&game_state->tiles.shader, "model", &model);
+ shader_setm4(&game_state->tiles.shader, "view", &view);
shader_setm4(&game_state->tiles.shader, "projection", &projection);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
@@ -192,8 +195,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
@@ -206,14 +209,17 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
// these dimensions are relative to a square 'meter', one tile
v2 player_dim = { 0.375f, 0.583f };
+ // TODO: move ppm out of this matrix
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 });
+ 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);
+ m4 view = glmth_m4_init_id();
+ view = glmth_translate(view, (v3) {0.0f, framebuffer.height, 0.0f});
+ view = glmth_scale(view, (v3) {1.0f, -1.0f, 1.0f});
+ view = glmth_translate(view, (v3) {viewport.min.x, viewport.min.y, 0.0f});
+
{
printf("Framebuffer :");
glmth_v2_print((v2) {framebuffer.width, framebuffer.height});
@@ -234,8 +240,10 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
}
v3 color = (v3) { 1.0f, 0.0f, 1.0f };
- shader_setv3(&game_state->tiles.shader, "color", &color);
+ shader_setv3(&game_state->tiles.shader, "color", &color);
+ shader_setm4(&game_state->tiles.shader, "model", &model);
+ shader_setm4(&game_state->tiles.shader, "view", &view);
shader_setm4(&game_state->tiles.shader, "projection", &projection);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);