commit c98c53c473cfc7cca9eae14ddf5e292f8e6beaed
parent 5ba65bf7abac4f84677c3edf3acda7868f5831e4
Author: amin <dev@aminmesbah.com>
Date: Sun, 23 Jun 2019 20:02:53 +0000
Add some uniforms
FossilOrigin-Name: 0aea7a477f487133c5a4bf8eb2145891c7d3e2f9b83e0ea44d339702fa13ec8b
Diffstat:
3 files changed, 32 insertions(+), 38 deletions(-)
diff --git a/shader/cube_f.glsl b/shader/cube_f.glsl
@@ -1,25 +1,14 @@
#version 300 es
+
precision highp float;
-in vec4 vertex_color;
+uniform float alpha;
+
+in vec3 color;
-out vec4 color;
+out vec4 frag_color;
void main()
{
- color = vertex_color;
+ frag_color = vec4(color, alpha);
}
-//#version 300 es
-//
-//precision highp float;
-//
-//uniform float alpha;
-//
-//in vec3 color;
-//
-//out vec4 frag_color;
-//
-//void main()
-//{
-// frag_color = vec4(color, alpha);
-//}
diff --git a/shader/cube_v.glsl b/shader/cube_v.glsl
@@ -1,28 +1,16 @@
#version 300 es
-layout (location = 0) in vec2 position;
-layout (location = 1) in vec3 color;
+layout (location = 0) in vec3 a_position;
+layout (location = 1) in vec3 a_color;
-out vec4 vertex_color;
+uniform mat4 model;
+uniform mat4 view;
+uniform mat4 projection;
+
+out vec3 color;
void main()
{
- gl_Position = vec4(position, 0.0f, 1.0f);
- vertex_color = vec4(color, 1.0f);
+ gl_Position = projection * view * model * vec4(a_position, 1.0f);
+ color = a_color;
}
-//#version 300 es
-//
-//layout (location = 0) in vec3 a_position;
-//layout (location = 1) in vec3 a_color;
-//
-//uniform mat4 model;
-//uniform mat4 view;
-//uniform mat4 projection;
-//
-//out vec3 color;
-//
-//void main()
-//{
-// gl_Position = projection * view * model * vec4(a_position, 1.0f);
-// color = a_color;
-//}
diff --git a/src/game.c b/src/game.c
@@ -123,10 +123,27 @@ void game_update_and_render(struct GameState *game_state, float dt, u32 screen_w
{
#if 1
{
+ m4 view = glmth_m4_init_id();
+ m4 projection = glmth_m4_init_id();
+ //TODO: make these transforms work on webgl like the do natively
+ //view = glmth_translate(view, glmth_v3_init(0.0f, 0.0f, -3.0f));
+ //projection = glmth_projection_perspective_fov(glmth_rad(45.0f), (float)screen_width / (float)screen_height, 0.1f, 100.0f);
+
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
+ m4 model = glmth_m4_init_id();
+ f32 angle = 20.0f;
+ f32 rot_rad = dt * glmth_rad(angle);
+ model = glmth_rotate(model, rot_rad, glmth_v3_init(0.0f, 0.0f, 1.0f));
+ model = glmth_rotate(model, rot_rad, glmth_v3_init(0.0f, 1.0f, 0.0f));
+ model = glmth_rotate(model, rot_rad, glmth_v3_init(1.0f, 0.0f, 0.0f));
+
shader_use(&game_state->cube_shader);
+ shader_setm4(&game_state->cube_shader, "model", &model);
+ shader_setm4(&game_state->cube_shader, "view", &view);
+ shader_setm4(&game_state->cube_shader, "projection", &projection);
+ shader_setf(&game_state->cube_shader, "alpha", 1.0f);
//glDrawArrays(GL_TRIANGLES, 0, 3);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);