From ec149216ff307b9b03e0f5eb7c05c749acc0dbf8 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 28 Oct 2013 22:49:20 -0400 Subject: [PATCH] use glamour for VAO, VBO, and Shader interfaces --- source/app.d | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/source/app.d b/source/app.d index 8d6e6de..360d423 100644 --- a/source/app.d +++ b/source/app.d @@ -1,19 +1,63 @@ import std.stdio; import derelict.sdl2.sdl; import derelict.opengl3.gl3; +import glamour.vao; +import glamour.shader; +import glamour.vbo; enum int WIDTH = 800; enum int HEIGHT = 600; +GLint position_idx; +GLint color_idx; + void init() { glClearColor (1.0, 0.7, 0.0, 0.0); glViewport(0, 0, WIDTH, HEIGHT); + immutable string shader_src = ` +vertex: + in vec2 position; + in vec3 color; + out vec3 color_i; + void main(void) + { + gl_Position = vec4(position, 0.0, 1.0); + color_i = color; + } +fragment: + in vec3 color_i; + void main(void) + { + gl_FragColor = vec4(color_i, 1.0); + } + `; + VAO vao = new VAO(); + Shader program = new Shader("program", shader_src); + program.bind(); + position_idx = program.get_attrib_location("position"); + color_idx = program.get_attrib_location("color"); + float[] vertices = [0.4, 0.4, -0.4, 0.4, -0.4, -0.4, 0.4, -0.4]; + float[] colors = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0]; + ushort[] indices = [0, 1, 2, 3]; + Buffer vbo = new Buffer(vertices); + vbo.bind(); + glEnableVertexAttribArray(position_idx); + glVertexAttribPointer(position_idx, 2, GL_FLOAT, GL_FALSE, 0, null); + Buffer cbo = new Buffer(colors); + cbo.bind(); + glEnableVertexAttribArray(color_idx); + glVertexAttribPointer(color_idx, 3, GL_FLOAT, GL_FALSE, 0, null); + ElementBuffer ibo = new ElementBuffer(indices); + ibo.bind(); } void display(SDL_Window * window) { glClear(GL_COLOR_BUFFER_BIT); + + glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, null); + SDL_GL_SwapWindow(window); }