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.cc27
1 files changed, 13 insertions, 14 deletions
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();
-
}