use glamour for VAO, VBO, and Shader interfaces
This commit is contained in:
parent
063b9a4d3a
commit
ec149216ff
44
source/app.d
44
source/app.d
@ -1,19 +1,63 @@
|
|||||||
import std.stdio;
|
import std.stdio;
|
||||||
import derelict.sdl2.sdl;
|
import derelict.sdl2.sdl;
|
||||||
import derelict.opengl3.gl3;
|
import derelict.opengl3.gl3;
|
||||||
|
import glamour.vao;
|
||||||
|
import glamour.shader;
|
||||||
|
import glamour.vbo;
|
||||||
|
|
||||||
enum int WIDTH = 800;
|
enum int WIDTH = 800;
|
||||||
enum int HEIGHT = 600;
|
enum int HEIGHT = 600;
|
||||||
|
|
||||||
|
GLint position_idx;
|
||||||
|
GLint color_idx;
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
glClearColor (1.0, 0.7, 0.0, 0.0);
|
glClearColor (1.0, 0.7, 0.0, 0.0);
|
||||||
glViewport(0, 0, WIDTH, HEIGHT);
|
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)
|
void display(SDL_Window * window)
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, null);
|
||||||
|
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user