fix rendering glitches

This commit is contained in:
ccolin 2021-01-03 16:37:22 +01:00
parent 0a6b133c19
commit 14b5993f0f
3 changed files with 2472 additions and 3222 deletions

File diff suppressed because it is too large Load Diff

View File

@ -77,11 +77,11 @@ void MainWindow::open(const QString &path) {
connect(slider, &QSlider::sliderReleased, dc, &DroneController::resume); connect(slider, &QSlider::sliderReleased, dc, &DroneController::resume);
connect(slider, &QSlider::valueChanged, dc, &DroneController::seek); connect(slider, &QSlider::valueChanged, dc, &DroneController::seek);
connect(dc, &DroneController::frameChanged, slider, &QSlider::setValue); connect(dc, &DroneController::frameChanged, slider, &QSlider::setValue);
connect(settings_pane, &SettingsPane::collisionClicked,
slider, &QSlider::setValue);
slider->setEnabled(true); slider->setEnabled(true);
// Settings pane // Settings pane
connect(settings_pane, &SettingsPane::collisionClicked,
slider, &QSlider::setValue);
connect(dc, &DroneController::collision, settings_pane, &SettingsPane::addCollision); connect(dc, &DroneController::collision, settings_pane, &SettingsPane::addCollision);
connect(settings_pane, &SettingsPane::sphereRadiusChanged, connect(settings_pane, &SettingsPane::sphereRadiusChanged,
[&](double _) { settings_pane->clearCollisions(); }); [&](double _) { settings_pane->clearCollisions(); });

View File

@ -4,6 +4,7 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QOpenGLBuffer> #include <QOpenGLBuffer>
#include <QSurfaceFormat>
static void GLAPIENTRY opengl_debug_cb(GLenum source, GLenum type, GLuint id, static void GLAPIENTRY opengl_debug_cb(GLenum source, GLenum type, GLuint id,
@ -98,14 +99,15 @@ void OpenGLWidget::loadSkybox() {
void OpenGLWidget::loadGround() { void OpenGLWidget::loadGround() {
QOpenGLTexture *ground_tex = new QOpenGLTexture(QImage(":/img/ground.jpg").mirrored()); 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->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
ground_tex->setWrapMode(QOpenGLTexture::MirroredRepeat); ground_tex->setWrapMode(QOpenGLTexture::MirroredRepeat);
ground = new OpenGLMesh({ 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, 0, 1000,
1000, 0, -1000, 0, 1000, 0, 1000, 0, 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, 0, 1000,
1000, 0, 1000, 0, 1000, 0, 1000, 1000, 1000, 0, 1000, 0, 1000, 0, 1000, 1000,
}, ground_tex, &main_program); }, ground_tex, &main_program);
@ -113,6 +115,10 @@ void OpenGLWidget::loadGround() {
void OpenGLWidget::initializeGL() { void OpenGLWidget::initializeGL() {
QSurfaceFormat format;
format.setProfile(QSurfaceFormat::CoreProfile);
format.setDepthBufferSize(24);
setFormat(format);
initializeOpenGLFunctions(); initializeOpenGLFunctions();
GLint major, minor; GLint major, minor;
glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MAJOR_VERSION, &major);
@ -142,8 +148,8 @@ void OpenGLWidget::initializeGL() {
loadGround(); loadGround();
glClearColor(1, 1, 1, 0); glClearColor(1, 1, 1, 0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_MULTISAMPLE); glCullFace(GL_BACK);
emit initialized(); emit initialized();
} }
@ -156,6 +162,8 @@ void OpenGLWidget::resizeGL(int w, int h) {
void OpenGLWidget::paintGL() { 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); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QMatrix4x4 trans; QMatrix4x4 trans;
trans.translate(0, 0, -cam_dist); trans.translate(0, 0, -cam_dist);
@ -179,18 +187,9 @@ void OpenGLWidget::paintGL() {
main_program.setUniformValue("proj", proj); main_program.setUniformValue("proj", proj);
main_program.setUniformValue("view", view); main_program.setUniformValue("view", view);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
ground->draw(this, QMatrix4x4()); ground->draw(this, QMatrix4x4());
if (painter) painter->draw(this); 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(); main_program.release();
} }