From 14b5993f0f4bb4fc2d33394780e6d8911c8783d7 Mon Sep 17 00:00:00 2001 From: ccolin Date: Sun, 3 Jan 2021 16:37:22 +0100 Subject: fix rendering glitches --- src/opengl_widget.cc | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/opengl_widget.cc') diff --git a/src/opengl_widget.cc b/src/opengl_widget.cc index d69af61..6919086 100644 --- a/src/opengl_widget.cc +++ b/src/opengl_widget.cc @@ -4,6 +4,7 @@ #include #include +#include static void GLAPIENTRY opengl_debug_cb(GLenum source, GLenum type, GLuint id, @@ -98,14 +99,15 @@ void OpenGLWidget::loadSkybox() { void OpenGLWidget::loadGround() { QOpenGLTexture *ground_tex = new QOpenGLTexture(QImage(":/img/ground.jpg").mirrored()); - ground_tex->setMagnificationFilter(QOpenGLTexture::LinearMipMapLinear); + ground_tex->generateMipMaps(); + ground_tex->setMagnificationFilter(QOpenGLTexture::Linear); 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, 0, + 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); @@ -113,6 +115,10 @@ void OpenGLWidget::loadGround() { void OpenGLWidget::initializeGL() { + QSurfaceFormat format; + format.setProfile(QSurfaceFormat::CoreProfile); + format.setDepthBufferSize(24); + setFormat(format); initializeOpenGLFunctions(); GLint major, minor; glGetIntegerv(GL_MAJOR_VERSION, &major); @@ -142,8 +148,8 @@ void OpenGLWidget::initializeGL() { loadGround(); glClearColor(1, 1, 1, 0); - glEnable(GL_DEPTH_TEST); - glEnable(GL_MULTISAMPLE); + + glCullFace(GL_BACK); emit initialized(); } @@ -156,6 +162,8 @@ void OpenGLWidget::resizeGL(int w, int h) { void OpenGLWidget::paintGL() { + glEnable(GL_CULL_FACE); // shouldn't have to do that each frame, weird + glEnable(GL_DEPTH_TEST); // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); QMatrix4x4 trans; trans.translate(0, 0, -cam_dist); @@ -179,18 +187,9 @@ void OpenGLWidget::paintGL() { main_program.setUniformValue("proj", proj); main_program.setUniformValue("view", view); glActiveTexture(GL_TEXTURE0); - 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(); - } -- cgit v1.2.3-70-g09d2