From f2d61fc06387ccb22ecb5cb6c42210736ac64c9f Mon Sep 17 00:00:00 2001 From: Sebastian Park Date: Tue, 23 Apr 2024 00:30:37 -0400 Subject: Get ground textures working, but not yet abstracted to the shape class. --- src/graphics/shape.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/graphics/shape.cpp') diff --git a/src/graphics/shape.cpp b/src/graphics/shape.cpp index c5dde0d..824a012 100644 --- a/src/graphics/shape.cpp +++ b/src/graphics/shape.cpp @@ -127,12 +127,12 @@ void Shape::draw(Shader *shader, GLenum mode) shader->setUniform("blue", m_blue); shader->setUniform("alpha", m_alpha); glBindVertexArray(m_surfaceVao); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, ocean_floor_texture); - shader->setUniform("sampler", 1); +// glActiveTexture(GL_TEXTURE0); +// glBindTexture(GL_TEXTURE_2D, ocean_floor_texture); +// shader->setUniform("sampler", 0); glDrawElements(mode, m_numSurfaceVertices, GL_UNSIGNED_INT, reinterpret_cast(0)); glBindVertexArray(0); - glBindTexture(GL_TEXTURE_2D, 0); +// glBindTexture(GL_TEXTURE_2D, 0); break; } case GL_POINTS: -- cgit v1.2.3-70-g09d2 From 1a26bf6678822bc73d3eb0eb754fd4a01d25573f Mon Sep 17 00:00:00 2001 From: Sebastian Park Date: Tue, 23 Apr 2024 03:47:11 -0400 Subject: Add ground plane stuff to shape class instead of in main. --- src/glwidget.cpp | 38 +------------------------------------- src/graphics/shape.cpp | 31 +++++++++++++++++-------------- src/graphics/shape.h | 4 ++-- 3 files changed, 20 insertions(+), 53 deletions(-) (limited to 'src/graphics/shape.cpp') 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 &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; -- cgit v1.2.3-70-g09d2 From 6a5806b82c44a2cae481a6015d1a0f390e4b8445 Mon Sep 17 00:00:00 2001 From: Sebastian Park Date: Tue, 23 Apr 2024 12:03:06 -0400 Subject: Create init sky plane. --- CMakeLists.txt.user | 2 +- src/graphics/shape.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/graphics/shape.h | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) (limited to 'src/graphics/shape.cpp') diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index fdc72cf..d5db76a 100644 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/src/graphics/shape.cpp b/src/graphics/shape.cpp index 0cdfe75..6c7ea00 100644 --- a/src/graphics/shape.cpp +++ b/src/graphics/shape.cpp @@ -323,3 +323,41 @@ void Shape::initGroundPlane(std::string texturePath, float depth, Shader* shader shader->unbind(); } +void Shape::initSkyPlane(std::string texturePath, float depth, Shader* shader) { + //TODO: Complete + + QString ground_texture_filepath = QString(texturePath.c_str()); + + // 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_TEXTURE1); + + // TASK 4: Bind kitten texture + glBindTexture(GL_TEXTURE_2D, m_ground_texture); + + // TASK 5: Load image into kitten texture + glTexImage2D(GL_TEXTURE_2D, 1, 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 + shader->bind(); + shader->setUniform("sampler", 1); + shader->unbind(); +} + diff --git a/src/graphics/shape.h b/src/graphics/shape.h index d8ea0c1..4a3632c 100644 --- a/src/graphics/shape.h +++ b/src/graphics/shape.h @@ -36,6 +36,7 @@ public: void setColor(float r, float g, float b); void initGroundPlane(std::string texturePath, float depth, Shader* shader); + void initSkyPlane(std::string texturePath, float depth, Shader* shader); void draw(Shader *shader, GLenum mode); SelectMode select(Shader *shader, int vertex); -- cgit v1.2.3-70-g09d2