refactor drawing code
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user