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/graphics/shape.cpp | |
parent | afea13471ff50d0c8500210c0a15fcf686a77832 (diff) |
Add ground plane stuff to shape class instead of in main.
Diffstat (limited to 'src/graphics/shape.cpp')
-rw-r--r-- | src/graphics/shape.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
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(); } |