use glamour for VAO, VBO, and Shader interfaces

This commit is contained in:
Josh Holtrop 2013-10-28 22:49:20 -04:00
parent 063b9a4d3a
commit ec149216ff

View File

@ -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);
}