aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorccolin2021-01-03 16:37:22 +0100
committerccolin2021-01-03 16:50:22 +0100
commit14b5993f0f4bb4fc2d33394780e6d8911c8783d7 (patch)
treec30f3349f0bf23d7f7cf053e3bbd82b47f304719 /src
parent0a6b133c19ccc69ecc6bcf6be83e8ec7f5f8150f (diff)
fix rendering glitches
Diffstat (limited to 'src')
-rw-r--r--src/main_window.cc4
-rw-r--r--src/opengl_widget.cc27
2 files changed, 15 insertions, 16 deletions
diff --git a/src/main_window.cc b/src/main_window.cc
index 1e9f054..9b4dff0 100644
--- a/src/main_window.cc
+++ b/src/main_window.cc
@@ -77,11 +77,11 @@ void MainWindow::open(const QString &path) {
connect(slider, &QSlider::sliderReleased, dc, &DroneController::resume);
connect(slider, &QSlider::valueChanged, dc, &DroneController::seek);
connect(dc, &DroneController::frameChanged, slider, &QSlider::setValue);
- connect(settings_pane, &SettingsPane::collisionClicked,
- slider, &QSlider::setValue);
slider->setEnabled(true);
// Settings pane
+ connect(settings_pane, &SettingsPane::collisionClicked,
+ slider, &QSlider::setValue);
connect(dc, &DroneController::collision, settings_pane, &SettingsPane::addCollision);
connect(settings_pane, &SettingsPane::sphereRadiusChanged,
[&](double _) { settings_pane->clearCollisions(); });
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 <QMouseEvent>
#include <QOpenGLBuffer>
+#include <QSurfaceFormat>
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();
-
}