From 928d45c3fbfb6b00d8e0b79b63934ebd080b9456 Mon Sep 17 00:00:00 2001 From: ccolin Date: Sun, 3 Jan 2021 12:30:16 +0100 Subject: refactor drawing code --- src/opengl_mesh.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/opengl_mesh.cc') 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 -OpenGLMesh::OpenGLMesh(QVector verts, QOpenGLTexture *tex) - :tex(tex) { +OpenGLMesh::OpenGLMesh(QVector 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 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(); +} -- cgit v1.2.3-70-g09d2