aboutsummaryrefslogtreecommitdiff
path: root/src/opengl_widget.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_widget.cc
parent8ad1cf1b89b8acae55e36d6bd4562dffd1bcc714 (diff)
refactor drawing code
Diffstat (limited to 'src/opengl_widget.cc')
-rw-r--r--src/opengl_widget.cc43
1 files changed, 36 insertions, 7 deletions
diff --git a/src/opengl_widget.cc b/src/opengl_widget.cc
index adc851e..d69af61 100644
--- a/src/opengl_widget.cc
+++ b/src/opengl_widget.cc
@@ -96,6 +96,22 @@ void OpenGLWidget::loadSkybox() {
}
+void OpenGLWidget::loadGround() {
+ QOpenGLTexture *ground_tex = new QOpenGLTexture(QImage(":/img/ground.jpg").mirrored());
+ ground_tex->setMagnificationFilter(QOpenGLTexture::LinearMipMapLinear);
+ ground_tex->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
+ ground_tex->setWrapMode(QOpenGLTexture::MirroredRepeat);
+ ground = new OpenGLMesh({
+ -1000, 0, -1000, 0, 1000, 0, 0, 0,
+ 1000, 0, -1000, 0, 1000, 0, 1000, 0,
+ -1000, 0, 1000, 0, 1000, 0, 0, 1000,
+ 1000, 0, -1000, 0, 1000, 0, 1000, 0,
+ -1000, 0, 1000, 0, 1000, 0, 0, 1000,
+ 1000, 0, 1000, 0, 1000, 0, 1000, 1000,
+ }, ground_tex, &main_program);
+}
+
+
void OpenGLWidget::initializeGL() {
initializeOpenGLFunctions();
GLint major, minor;
@@ -123,6 +139,7 @@ void OpenGLWidget::initializeGL() {
main_program.release();
loadSkybox();
+ loadGround();
glClearColor(1, 1, 1, 0);
glEnable(GL_DEPTH_TEST);
@@ -163,13 +180,15 @@ void OpenGLWidget::paintGL() {
main_program.setUniformValue("view", view);
glActiveTexture(GL_TEXTURE0);
- for (const OpenGLMesh &mesh : meshes) {
- main_program.setUniformValue("model", mesh.mat);
- glBindVertexArray(mesh.vao);
- mesh.tex->bind();
- glDrawArrays(GL_TRIANGLES, 0, mesh.nverts);
- mesh.tex->release();
- }
+ ground->draw(this, QMatrix4x4());
+ if (painter) painter->draw(this);
+ // for (const OpenGLMesh &mesh : meshes) {
+ // main_program.setUniformValue("model", mesh.mat);
+ // glBindVertexArray(mesh.vao);
+ // mesh.tex->bind();
+ // glDrawArrays(GL_TRIANGLES, 0, mesh.nverts);
+ // mesh.tex->release();
+ // }
main_program.release();
}
@@ -203,3 +222,13 @@ void OpenGLWidget::wheelEvent(QWheelEvent *e) {
cam_dist -= e->angleDelta().y() / 1000. * cam_dist;
update();
}
+
+
+void OpenGLWidget::setPainter(const Painter *p) {
+ painter = p;
+}
+
+
+QOpenGLShaderProgram *OpenGLWidget::getMainProgram() {
+ return &main_program;
+}