diff options
author | Sebastian Park <SebPark03@gmail.com> | 2024-04-23 03:47:11 -0400 |
---|---|---|
committer | Sebastian Park <SebPark03@gmail.com> | 2024-04-23 03:47:11 -0400 |
commit | 1a26bf6678822bc73d3eb0eb754fd4a01d25573f (patch) | |
tree | fb8c402b129f58d675705daae852a57377bc3eda /src | |
parent | afea13471ff50d0c8500210c0a15fcf686a77832 (diff) |
Add ground plane stuff to shape class instead of in main.
Diffstat (limited to 'src')
-rwxr-xr-x | src/glwidget.cpp | 38 | ||||
-rw-r--r-- | src/graphics/shape.cpp | 31 | ||||
-rw-r--r-- | src/graphics/shape.h | 4 |
3 files changed, 20 insertions, 53 deletions
diff --git a/src/glwidget.cpp b/src/glwidget.cpp index d172868..8fdd549 100755 --- a/src/glwidget.cpp +++ b/src/glwidget.cpp @@ -81,39 +81,7 @@ void GLWidget::initializeGL() // INITIALIZE TEXTURE STUFF // Prepare filepath - QString ground_texture_filepath = QString(":/resources/images/anamorphic.jpg"); - // TASK 1: Obtain image from filepath - m_ground_image = QImage(ground_texture_filepath); - - // TASK 2: Format image to fit OpenGL - m_ground_image = m_ground_image.convertToFormat(QImage::Format_RGBA8888).mirrored(); - - auto bits = m_ground_image.bits(); - - // TASK 3: Generate kitten texture - glGenTextures(1, &m_ground_texture); - - // TASK 9: Set the active texture slot to texture slot 0 - glActiveTexture(GL_TEXTURE0); - - // TASK 4: Bind kitten texture - glBindTexture(GL_TEXTURE_2D, m_ground_texture); - - // TASK 5: Load image into kitten texture - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_ground_image.width(), m_ground_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_ground_image.bits()); - - // TASK 6: Set min and mag filters' interpolation mode to linear - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - // TASK 7: Unbind kitten texture - glBindTexture(GL_TEXTURE_2D, 0); - -// // TASK 10: set the texture.frag uniform for our texture - m_defaultShader->bind(); - m_defaultShader->setUniform("sampler", 0); - m_defaultShader->unbind(); // // TASK 11: Fix this "fullscreen" quad's vertex data // // TASK 12: Play around with different values! @@ -127,6 +95,7 @@ void GLWidget::initializeGL() // -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // 1.0f, -1.0f, 0.0f, 1.0f, 0.0f // }; + m_arap.initGroundPlane(":/resources/images/anamorphic.jpg", 2, m_defaultShader); // // Generate and bind a VBO and a VAO for a fullscreen quad // glGenBuffers(1, &m_fullscreen_vbo); @@ -179,7 +148,6 @@ void GLWidget::initializeGL() m_deltaTimeProvider.start(); m_intervalTimer.start(1000 / 60); - m_arap.initGroundPlane(":resources/images/kitty.png", 2, m_defaultShader); } //void GLWidget::paintTexture(GLuint texture, bool filtered){ @@ -215,13 +183,9 @@ void GLWidget::paintGL() m_defaultShader->setUniform("widthBounds", m_arap.minCorner[0], m_arap.maxCorner[0]); m_defaultShader->setUniform("lengthBounds", m_arap.minCorner[2], m_arap.maxCorner[2]); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_ground_texture); m_arap.draw(m_defaultShader, GL_TRIANGLES); m_defaultShader->unbind(); - glBindTexture(GL_TEXTURE_2D, 0); - glClear(GL_DEPTH_BUFFER_BIT); //// m_pointShader->bind(); diff --git a/src/graphics/shape.cpp b/src/graphics/shape.cpp index 824a012..0cdfe75 100644 --- a/src/graphics/shape.cpp +++ b/src/graphics/shape.cpp @@ -113,6 +113,10 @@ void Shape::setColor(float r, float g, float b) { void Shape::draw(Shader *shader, GLenum mode) { + // Drawing the ground texture. + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_ground_texture); + Eigen::Matrix3f m3 = m_modelMatrix.topLeftCorner(3, 3); Eigen::Matrix3f inverseTransposeModel = m3.inverse().transpose(); @@ -145,6 +149,7 @@ void Shape::draw(Shader *shader, GLenum mode) break; } } + glBindTexture(GL_TEXTURE_2D, 0); } SelectMode Shape::select(Shader *shader, int closest_vertex) @@ -283,28 +288,27 @@ void Shape::updateMesh(const std::vector<Eigen::Vector3i> &faces, void Shape::initGroundPlane(std::string texturePath, float depth, Shader* shader) { - // Prepare filepath - QString ocean_floor_filepath = QString(texturePath.c_str()); + QString ground_texture_filepath = QString(texturePath.c_str()); // TASK 1: Obtain image from filepath - this->ocean_floor_image = QImage(ocean_floor_filepath); + m_ground_image = QImage(ground_texture_filepath); // TASK 2: Format image to fit OpenGL - ocean_floor_image = ocean_floor_image.convertToFormat(QImage::Format_RGBA8888).mirrored(); - auto bits = this->ocean_floor_image.bits(); - auto dat = ocean_floor_image.data_ptr(); + m_ground_image = m_ground_image.convertToFormat(QImage::Format_RGBA8888).mirrored(); + + auto bits = m_ground_image.bits(); - // TASK 3: Generate texture - glGenTextures(1, &ocean_floor_texture); + // TASK 3: Generate kitten texture + glGenTextures(1, &m_ground_texture); // TASK 9: Set the active texture slot to texture slot 0 glActiveTexture(GL_TEXTURE0); // TASK 4: Bind kitten texture - glBindTexture(GL_TEXTURE_2D, ocean_floor_texture); + glBindTexture(GL_TEXTURE_2D, m_ground_texture); // TASK 5: Load image into kitten texture - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ocean_floor_image.width(), ocean_floor_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, ocean_floor_image.bits()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_ground_image.width(), m_ground_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_ground_image.bits()); // TASK 6: Set min and mag filters' interpolation mode to linear glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -313,10 +317,9 @@ void Shape::initGroundPlane(std::string texturePath, float depth, Shader* shader // TASK 7: Unbind kitten texture glBindTexture(GL_TEXTURE_2D, 0); - // TASK 10: set the texture.frag uniform for our texture - glUseProgram(shader->id()); -// glUniform1i(glGetUniformLocation(shader->id(), "sampler"), 0); +// // TASK 10: set the texture.frag uniform for our texture + shader->bind(); shader->setUniform("sampler", 0); - glUseProgram(0); + shader->unbind(); } diff --git a/src/graphics/shape.h b/src/graphics/shape.h index b909606..d8ea0c1 100644 --- a/src/graphics/shape.h +++ b/src/graphics/shape.h @@ -51,8 +51,8 @@ private: GLuint m_surfaceVao; GLuint m_surfaceVbo; GLuint m_surfaceIbo; - GLuint ocean_floor_texture; - QImage ocean_floor_image; + GLuint m_ground_texture; + QImage m_ground_image; unsigned int m_numSurfaceVertices; unsigned int m_verticesSize; |