From f328282289015b0cdf9c9a19d597a98ad5facc94 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 17 Nov 2013 18:28:25 -0500 Subject: [PATCH] initial logo.draw() attempt --- src/logo.d | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/logo.d b/src/logo.d index 05316d7..ede1961 100644 --- a/src/logo.d +++ b/src/logo.d @@ -1,3 +1,4 @@ +import derelict.opengl3.gl3; import glamour.vao; import glamour.vbo; static import logoobj; @@ -8,30 +9,43 @@ immutable enum int WIRE = 1; immutable enum int GENTEX = 0; immutable enum int CORPORATION = 1; +int[][][][][] object_indices; /* Indexed by: face/wire, word, character */ VAO[][2][2] object_vaos; void init() { + object_indices = [[logoobj.fg, logoobj.fc], [logoobj.lg, logoobj.lc]]; Buffer vertices_buffer = new Buffer(logoobj.vertices); - int[][][][] objects = [logoobj.fg, logoobj.fc, logoobj.lg, logoobj.lc]; - int objects_index; for (int draw_type = FACE; draw_type <= WIRE; draw_type++) { for (int word = GENTEX; word <= CORPORATION; word++) { - object_vaos[draw_type][word].length = objects[objects_index].length; + object_vaos[draw_type][word].length = object_indices[draw_type][word].length; for (int char_index = 0; - char_index < objects[objects_index].length; + char_index < object_indices[draw_type][word].length; char_index++) { VAO vao = new VAO(); + vao.bind(); + vertices_buffer.bind(); - ElementBuffer ibo = new ElementBuffer(objects[objects_index][char_index]); + ElementBuffer ibo = new ElementBuffer(object_indices[draw_type][word][char_index]); ibo.bind(); + object_vaos[draw_type][word][char_index] = vao; } - objects_index++; } } } + +void draw(int draw_type, int word, int character, GLint position_idx) +{ + object_vaos[draw_type][word][character].bind(); + glEnableVertexAttribArray(position_idx); + glVertexAttribPointer(position_idx, 2, GL_FLOAT, GL_FALSE, 0, null); + glDrawElements(draw_type == FACE ? GL_TRIANGLES : GL_LINES, + object_indices[draw_type][word].length, + GL_UNSIGNED_INT, + null); +}