aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mdl/cube.obj30
-rw-r--r--resources.qrc1
-rw-r--r--src/drone_controller.cc17
-rw-r--r--src/opengl_widget.cc69
-rw-r--r--src/opengl_widget.hh3
5 files changed, 21 insertions, 99 deletions
diff --git a/mdl/cube.obj b/mdl/cube.obj
deleted file mode 100644
index de4003f..0000000
--- a/mdl/cube.obj
+++ /dev/null
@@ -1,30 +0,0 @@
-# Blender v2.90.1 OBJ File: ''
-# www.blender.org
-o Cube
-v -1.000000 -1.000000 1.000000
-v -1.000000 1.000000 1.000000
-v -1.000000 -1.000000 -1.000000
-v -1.000000 1.000000 -1.000000
-v 1.000000 -1.000000 1.000000
-v 1.000000 1.000000 1.000000
-v 1.000000 -1.000000 -1.000000
-v 1.000000 1.000000 -1.000000
-vn -1.0000 0.0000 0.0000
-vn 0.0000 0.0000 -1.0000
-vn 1.0000 0.0000 0.0000
-vn 0.0000 0.0000 1.0000
-vn 0.0000 -1.0000 0.0000
-vn 0.0000 1.0000 0.0000
-s off
-f 2//1 3//1 1//1
-f 4//2 7//2 3//2
-f 8//3 5//3 7//3
-f 6//4 1//4 5//4
-f 7//5 1//5 3//5
-f 4//6 6//6 8//6
-f 2//1 4//1 3//1
-f 4//2 8//2 7//2
-f 8//3 6//3 5//3
-f 6//4 2//4 1//4
-f 7//5 5//5 1//5
-f 4//6 2//6 6//6
diff --git a/resources.qrc b/resources.qrc
index 2ff2adf..0e5ff85 100644
--- a/resources.qrc
+++ b/resources.qrc
@@ -3,7 +3,6 @@
<qresource>
<file>mdl/dji600.obj</file>
<file>mdl/dji600.mtl</file>
- <file>mdl/cube.obj</file>
<file>img/dji600.jpg</file>
<file>img/ground.jpg</file>
diff --git a/src/drone_controller.cc b/src/drone_controller.cc
index 9a6c5db..fc1cefe 100644
--- a/src/drone_controller.cc
+++ b/src/drone_controller.cc
@@ -26,8 +26,6 @@ Drone::Drone() {
if (!mesh_initialized) {
QVector<GLfloat> verts = load_obj(":/mdl/dji600.obj", LOAD_OBJ_NORMALS | LOAD_OBJ_UVS);
QOpenGLTexture *texture = new QOpenGLTexture(QImage(":/img/dji600.jpg").mirrored());
- // texture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
- // texture->setMagnificationFilter(QOpenGLTexture::Linear);
mesh = new OpenGLMesh(verts, texture);
mesh_initialized = true;
}
@@ -92,13 +90,16 @@ DroneController::DroneController(const QJsonObject &json)
OpenGLWidget::instance->makeCurrent();
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);
OpenGLMesh *ground = new OpenGLMesh({
- -100, 0, -100, 0, 1, 0, 0, 0,
- 100, 0, -100, 0, 1, 0, 1, 0,
- -100, 0, 100, 0, 1, 0, 0, 1,
- 100, 0, -100, 0, 1, 0, 1, 0,
- -100, 0, 100, 0, 1, 0, 0, 1,
- 100, 0, 100, 0, 1, 0, 1, 1,
+ -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);
OpenGLWidget::instance->meshes.append(*ground);
OpenGLWidget::instance->doneCurrent();
diff --git a/src/opengl_widget.cc b/src/opengl_widget.cc
index 8d7cab5..5a82d23 100644
--- a/src/opengl_widget.cc
+++ b/src/opengl_widget.cc
@@ -34,6 +34,7 @@ OpenGLWidget::~OpenGLWidget() {
void OpenGLWidget::loadSkybox() {
+ // Shader program
if (!skybox_program.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/skybox.vert")) {
qFatal("Error compiling skybox.vert: %s", skybox_program.log().toLocal8Bit().constData());
}
@@ -46,17 +47,17 @@ void OpenGLWidget::loadSkybox() {
skybox_program.bind();
skybox_program.setUniformValue("skybox", 0);
- // GLfloat skybox_verts[] = {
- // -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0,
- // -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0,
- // 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0,
- // -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, 1.0,
- // -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0,
- // -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0
- // };
- QVector<GLfloat> skybox_verts = load_obj(":/mdl/cube.obj", 0);
-
- // OpenGL native VAO version
+ QVector<GLfloat> skybox_verts {
+ -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0,
+ -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0,
+ 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0,
+ -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, 1.0,
+ -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0,
+ -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0
+ };
+ // QVector<GLfloat> skybox_verts = load_obj(":/mdl/cube.obj", 0);
+
+ // VAO
glGenVertexArrays(1, &skybox_vao);
glBindVertexArray(skybox_vao);
glGenBuffers(1, &skybox_vbo);
@@ -66,15 +67,6 @@ void OpenGLWidget::loadSkybox() {
glEnableVertexAttribArray(0);
glBindVertexArray(0);
- // // QOpenGLVertexArrayObject version
- // skybox_vao.create();
- // skybox_vao.bind();
- // QOpenGLBuffer skybox_vbo(QOpenGLBuffer::VertexBuffer);
- // skybox_vbo.setUsagePattern(QOpenGLBuffer::StaticDraw);
- // skybox_vbo.allocate((void *) skybox_verts.data(), skybox_verts.size() * sizeof (GLfloat));
- // skybox_program.setAttributeBuffer(0, GL_FLOAT, 0, 3, 0);
- // skybox_program.enableAttributeArray(0);
-
// Skybox texture images
QVector<QImage> skybox_img {
QImage(":/img/clouds1_west.jpg").convertToFormat(QImage::Format_RGB888),
@@ -86,8 +78,6 @@ void OpenGLWidget::loadSkybox() {
};
size_t width = skybox_img[0].width();
size_t height = skybox_img[0].height();
-
- // OpenGL native texture version
glGenTextures(1, &skybox_tex);
glBindTexture(GL_TEXTURE_CUBE_MAP, skybox_tex);
for (int i = 0; i < 6; i++) {
@@ -101,21 +91,6 @@ void OpenGLWidget::loadSkybox() {
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
- // // QOpenGLTexture skybox texture version
- // skybox_tex = new QOpenGLTexture(QOpenGLTexture::TargetCubeMap);
- // skybox_tex->create();
- // skybox_tex->setSize(width, skybox_img[0].height(), height);
- // skybox_tex->setFormat(QOpenGLTexture::RGBA8_UNorm);
- // skybox_tex->allocateStorage();
- // for (int i = 0; i < 6; i++) {
- // skybox_tex->setData(0, 0, (QOpenGLTexture::CubeMapFace) (QOpenGLTexture::CubeMapPositiveX + i),
- // QOpenGLTexture::RGBA, QOpenGLTexture::UInt8,
- // (const void*) skybox_img[i].constBits(), 0);
- // }
- // skybox_tex->setWrapMode(QOpenGLTexture::ClampToEdge);
- // skybox_tex->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
- // skybox_tex->setMagnificationFilter(QOpenGLTexture::LinearMipMapLinear);
-
skybox_program.release();
}
@@ -165,28 +140,16 @@ void OpenGLWidget::paintGL() {
trans.translate(0, 0, -cam_dist);
QMatrix4x4 view = trans * rot;
- // skybox_vao.bind();
- // glActiveTexture(GL_TEXTURE0);
- // glBindTexture(GL_TEXTURE_CUBE_MAP, skybox_tex);
- // // skybox_tex->bind();
- // glDrawArrays(GL_TRIANGLES, 0, 36);
- // // skybox_tex->release();
- // skybox_vao.release();
-
glDepthMask(GL_FALSE);
glDepthFunc(GL_LEQUAL);
skybox_program.bind();
skybox_program.setUniformValue("proj", proj);
skybox_program.setUniformValue("view", view);
- // skybox_program.setUniformValue("model", QMatrix4x4());
glBindVertexArray(skybox_vao);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, skybox_tex);
- // skybox_tex->bind();
- // skybox_vao.bind();
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
- // skybox_tex->release();
skybox_program.release();
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
@@ -196,14 +159,6 @@ void OpenGLWidget::paintGL() {
main_program.setUniformValue("view", view);
glActiveTexture(GL_TEXTURE0);
- // main_program.setUniformValue("model", QMatrix4x4());
- // skybox_vao.bind();
- // glDrawArrays(GL_TRIANGLES, 0, 36);
-
- // skybox_program.bind();
- // skybox_program.setUniformValue("proj", proj);
- // skybox_program.setUniformValue("view", view);
-
for (const OpenGLMesh &mesh : meshes) {
main_program.setUniformValue("model", mesh.mat);
glBindVertexArray(mesh.vao);
diff --git a/src/opengl_widget.hh b/src/opengl_widget.hh
index 5bd4a07..5ee1057 100644
--- a/src/opengl_widget.hh
+++ b/src/opengl_widget.hh
@@ -22,10 +22,7 @@ class OpenGLWidget : public QOpenGLWidget, public QOpenGLFunctions_4_4_Core {
QOpenGLShaderProgram main_program;
QOpenGLShaderProgram skybox_program;
- // QOpenGLTexture *skybox_tex;
GLuint skybox_tex;
- // QOpenGLVertexArrayObject skybox_vao;
- // QOpenGLBuffer skybox_vbo;
GLuint skybox_vao;
GLuint skybox_vbo;