X-Git-Url: http://git.mutantstargoat.com?p=demo;a=blobdiff_plain;f=src%2Fopengl%2Fmesh-gl.cc;h=119d043b884e1969e4e2c3e9c0c031764a79fb80;hp=42c2af9251e9dac300fe228188abf6206b2a932a;hb=63d7f3b0e70ab5e3d530c579b1881967c96b0b92;hpb=d03d86eb8489e7ab4c5460cea5ee265b0c1ee487 diff --git a/src/opengl/mesh-gl.cc b/src/opengl/mesh-gl.cc index 42c2af9..119d043 100644 --- a/src/opengl/mesh-gl.cc +++ b/src/opengl/mesh-gl.cc @@ -66,15 +66,12 @@ MeshGL::~MeshGL() void MeshGL::draw() const { - if(!vao) - return; - glBindVertexArray(vao); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); - glDrawElements(GL_TRIANGLES, num_indices, GL_UNSIGNED_INT, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glDrawElements(GL_TRIANGLES, num_indices, GL_UNSIGNED_SHORT, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindVertexArray(0); } @@ -85,8 +82,10 @@ void MeshGL::update_vertex_data() void MeshGL::update_vbo() { - if(!num_vertices) + if(vertices.empty()) { + printf("empty vertices\n"); return; + } /* vao */ if(!vao) @@ -130,6 +129,8 @@ void MeshGL::update_vbo() glBufferSubData(GL_ARRAY_BUFFER, 0, tex_coords.size() * sizeof(Vec2), &tex_coords[0]); glVertexAttribPointer(MESH_TEXTURE, 2, GL_FLOAT, GL_FALSE, sizeof(Vec2), 0); + num_vertices = vertices.size(); + /* indices */ if(!ibo) @@ -143,13 +144,11 @@ void MeshGL::update_vbo() &indices[0]); num_indices = indices.size(); - num_vertices = vertices.size(); glEnableVertexAttribArray(MESH_VERTEX); glEnableVertexAttribArray(MESH_NORMAL); glEnableVertexAttribArray(MESH_TEXTURE); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0);