aboutsummaryrefslogtreecommitdiff
path: root/src/opengl_mesh.cc
diff options
context:
space:
mode:
authorccolin2021-01-03 12:30:16 +0100
committerccolin2021-01-03 12:30:16 +0100
commit928d45c3fbfb6b00d8e0b79b63934ebd080b9456 (patch)
tree9e6b4f457d3c3130aa57b183f868e378e9810f5a /src/opengl_mesh.cc
parent8ad1cf1b89b8acae55e36d6bd4562dffd1bcc714 (diff)
refactor drawing code
Diffstat (limited to 'src/opengl_mesh.cc')
-rw-r--r--src/opengl_mesh.cc15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/opengl_mesh.cc b/src/opengl_mesh.cc
index 01a73ff..a1f5a23 100644
--- a/src/opengl_mesh.cc
+++ b/src/opengl_mesh.cc
@@ -4,8 +4,9 @@
#include <QOpenGLFunctions>
-OpenGLMesh::OpenGLMesh(QVector<float> verts, QOpenGLTexture *tex)
- :tex(tex) {
+OpenGLMesh::OpenGLMesh(QVector<float> verts, QOpenGLTexture *tex, QOpenGLShaderProgram *program)
+ :tex(tex),
+ program(program) {
OpenGLWidget::instance->makeCurrent();
QOpenGLExtraFunctions *glf = OpenGLWidget::instance;
nverts = verts.size() / 8;
@@ -24,3 +25,13 @@ OpenGLMesh::OpenGLMesh(QVector<float> verts, QOpenGLTexture *tex)
glf->glBindVertexArray(0);
OpenGLWidget::instance->doneCurrent();
}
+
+
+void OpenGLMesh::draw(QOpenGLExtraFunctions *f, const QMatrix4x4 &mat) const {
+ program->bind();
+ program->setUniformValue("model", mat);
+ f->glBindVertexArray(vao);
+ tex->bind();
+ f->glDrawArrays(GL_TRIANGLES, 0, nverts);
+ tex->release();
+}