aboutsummaryrefslogtreecommitdiff
path: root/src/opengl_mesh.cc
blob: 1d7d1b7bdf30c25794de3dd84884fcc6185a4f88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "opengl_mesh.hh"
#include "opengl_widget.hh"

#include <QOpenGLFunctions>


OpenGLMesh::OpenGLMesh(QVector<float> verts, QOpenGLTexture *tex)
	:tex(tex) {
	OpenGLWidget::instance->makeCurrent();
	QOpenGLFunctions_4_4_Core *glf = OpenGLWidget::instance;
	nverts = verts.size() / 5;
	glf->glGenVertexArrays(1, &vao);
	glf->glGenBuffers(1, &vbo);
	glf->glBindVertexArray(vao);
	glf->glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glf->glBufferData(GL_ARRAY_BUFFER, nverts * 5 * sizeof (float), verts.data(), GL_STATIC_DRAW);
	glf->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof (float), 0);
	glf->glEnableVertexAttribArray(0);
	glf->glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof (float), (void *) (3 * sizeof (float)));
	glf->glEnableVertexAttribArray(1);
	tex->bind();
	glf->glBindVertexArray(0);
	OpenGLWidget::instance->doneCurrent();
}