make quad spin

This commit is contained in:
Josh Holtrop 2013-10-28 23:13:31 -04:00
parent ec149216ff
commit 6779466792

View File

@ -4,12 +4,15 @@ import derelict.opengl3.gl3;
import glamour.vao; import glamour.vao;
import glamour.shader; import glamour.shader;
import glamour.vbo; import glamour.vbo;
import gl3n.linalg;
enum int WIDTH = 800; enum int WIDTH = 800;
enum int HEIGHT = 600; enum int HEIGHT = 600;
GLint position_idx; GLint position_idx;
GLint color_idx; GLint color_idx;
GLint view_idx;
mat4 view_matrix;
void init() void init()
{ {
@ -17,12 +20,13 @@ void init()
glViewport(0, 0, WIDTH, HEIGHT); glViewport(0, 0, WIDTH, HEIGHT);
immutable string shader_src = ` immutable string shader_src = `
vertex: vertex:
uniform mat4 view;
in vec2 position; in vec2 position;
in vec3 color; in vec3 color;
out vec3 color_i; out vec3 color_i;
void main(void) void main(void)
{ {
gl_Position = vec4(position, 0.0, 1.0); gl_Position = view * vec4(position, 0.0, 1.0);
color_i = color; color_i = color;
} }
fragment: fragment:
@ -50,12 +54,16 @@ fragment:
glVertexAttribPointer(color_idx, 3, GL_FLOAT, GL_FALSE, 0, null); glVertexAttribPointer(color_idx, 3, GL_FLOAT, GL_FALSE, 0, null);
ElementBuffer ibo = new ElementBuffer(indices); ElementBuffer ibo = new ElementBuffer(indices);
ibo.bind(); ibo.bind();
view_idx = program.get_uniform_location("view");
} }
void display(SDL_Window * window) void display(SDL_Window * window)
{ {
glClear(GL_COLOR_BUFFER_BIT); 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); glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, null);
SDL_GL_SwapWindow(window); SDL_GL_SwapWindow(window);