From 677946679209cca008294da5ed64ccecf6be8966 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 28 Oct 2013 23:13:31 -0400 Subject: [PATCH] make quad spin --- source/app.d | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/app.d b/source/app.d index 360d423..9da9003 100644 --- a/source/app.d +++ b/source/app.d @@ -4,12 +4,15 @@ import derelict.opengl3.gl3; import glamour.vao; import glamour.shader; import glamour.vbo; +import gl3n.linalg; enum int WIDTH = 800; enum int HEIGHT = 600; GLint position_idx; GLint color_idx; +GLint view_idx; +mat4 view_matrix; void init() { @@ -17,12 +20,13 @@ void init() glViewport(0, 0, WIDTH, HEIGHT); immutable string shader_src = ` vertex: + uniform mat4 view; in vec2 position; in vec3 color; out vec3 color_i; void main(void) { - gl_Position = vec4(position, 0.0, 1.0); + gl_Position = view * vec4(position, 0.0, 1.0); color_i = color; } fragment: @@ -50,12 +54,16 @@ fragment: glVertexAttribPointer(color_idx, 3, GL_FLOAT, GL_FALSE, 0, null); ElementBuffer ibo = new ElementBuffer(indices); ibo.bind(); + view_idx = program.get_uniform_location("view"); } void display(SDL_Window * window) { glClear(GL_COLOR_BUFFER_BIT); + view_matrix.make_identity(); + view_matrix.rotate(SDL_GetTicks() / 500.0, vec3(0.0, 0.0, 1.0)); + glUniformMatrix4fv(view_idx, 1, GL_TRUE, view_matrix.value_ptr); glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, null); SDL_GL_SwapWindow(window);