aboutsummaryrefslogtreecommitdiff
path: root/src/opengl_widget.cc
diff options
context:
space:
mode:
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;
+}