a-game

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

commit d13bfe83af471665b7b6d5533b3ae11226bd1ffc
parent c833ecd4cdee55419de0b4c42cfee2d0fddffcee
Author: amin <dev@aminmesbah.com>
Date:   Sat,  2 Jun 2018 06:14:05 +0000

Use an orthographic projection

FossilOrigin-Name: e5a533d408176619d55fc83dbd5ea4dcd5eb40d132c791284c25603a48990617
Diffstat:
Mshader/triangle_v.glsl | 3+--
Msrc/game.c | 15++++++---------
2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/shader/triangle_v.glsl b/shader/triangle_v.glsl @@ -7,10 +7,9 @@ out vec4 vertex_color; uniform mat4 model; uniform mat4 projection; -uniform mat4 view; void main() { - gl_Position = projection * view * model * vec4(position, 0.0f, 1.0f); + gl_Position = projection * model * vec4(position, 0.0f, 1.0f); vertex_color = vec4(color, 1.0f); } diff --git a/src/game.c b/src/game.c @@ -7,7 +7,7 @@ void game_init(struct GameState *game_state, uint32_t screen_width, uint32_t scr { glViewport(0, 0, screen_width, screen_height); - float circumradius = 0.5f; + float circumradius = 10.0f; float inradius = circumradius * sinf(glmth_rad(30.0f)); float half_side_length = circumradius * cosf(glmth_rad(30.0f)); @@ -47,23 +47,20 @@ void game_update_and_render(struct GameState *game_state, float dt, uint32_t scr glClear(GL_COLOR_BUFFER_BIT); m4 model = glmth_m4_init_id(); - model = glmth_translate(model, glmth_v3_init(1.5f * cosf(dt), 1.5f * sinf(dt), 0.0f)); + 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)); + model = glmth_rotate_z(model, -dt); + model = glmth_scale(model, glmth_v3_init(10.0f, 10.0f, 10.0f)); float scale_factor = fabs(1.0f * sinf(dt)); model = glmth_scale(model, glmth_v3_init(scale_factor, scale_factor, scale_factor)); - model = glmth_rotate_z(model, -dt); shader_use(&game_state->triangle_shader); shader_setm4(&game_state->triangle_shader, "model", &model); m4 projection = glmth_m4_init_id(); - projection = glmth_projection_perspective_fov(glmth_rad(45.0f), (float)screen_width / (float)screen_height, 0.1f, 100.0f); + projection = glmth_projection_ortho(0.0f, screen_width, screen_height, 0.0f, -1.0f, 1.0f); shader_setm4(&game_state->triangle_shader, "projection", &projection); - m4 view = glmth_m4_init_id(); - v3 camera_pos = glmth_v3_init(0.0f, 0.0f, 6.0f); - view = glmth_camera_look_at(camera_pos, glmth_v3_a(camera_pos, glmth_v3_init(0.0f, 0.0f, -1.0f)), glmth_v3_init(0.0f, 1.0f, 0.0f)); - shader_setm4(&game_state->triangle_shader, "view", &view); - glBindVertexArray(game_state->vao_id); glDrawArrays(GL_TRIANGLES, 0, 3); glBindVertexArray(0);