]> git.sur5r.net Git - fstl/blob - src/glmesh.cpp
Mostly complete from the Python original
[fstl] / src / glmesh.cpp
1 #include "glmesh.h"
2 #include "mesh.h"
3
4 GLMesh::GLMesh(const Mesh* const mesh)
5     : vertices(QGLBuffer::VertexBuffer), indices(QGLBuffer::IndexBuffer)
6 {
7     vertices.create();
8     indices.create();
9
10     vertices.setUsagePattern(QGLBuffer::StaticDraw);
11     indices.setUsagePattern(QGLBuffer::StaticDraw);
12
13     vertices.bind();
14     vertices.allocate(mesh->vertices.data(),
15                       mesh->vertices.size() * sizeof(float));
16     vertices.release();
17
18     indices.bind();
19     indices.allocate(mesh->indices.data(),
20                      mesh->indices.size() * sizeof(uint32_t));
21     indices.release();
22 }
23
24 void GLMesh::draw(GLuint vp)
25 {
26     vertices.bind();
27     indices.bind();
28
29     glVertexAttribPointer(vp, 3, GL_FLOAT, false, 3*sizeof(float), NULL);
30     glDrawElements(GL_TRIANGLES, indices.size() / sizeof(uint32_t),
31                    GL_UNSIGNED_INT, NULL);
32
33     vertices.release();
34     indices.release();
35 }