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/glwidget.cpp | 122 +++++++++++++++++++++++++++++++++++++++++++------ src/glwidget.h | 7 +++ src/graphics/shape.cpp | 8 ++-- 3 files changed, 120 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/glwidget.cpp b/src/glwidget.cpp index 263b7dd..472966b 100755 --- a/src/glwidget.cpp +++ b/src/glwidget.cpp @@ -70,12 +70,87 @@ void GLWidget::initializeGL() glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); - // glShadeModel(GL_SMOOTH); +// glShadeModel(GL_SMOOTH); // Initialize shaders m_defaultShader = new Shader(":resources/shaders/shader.vert", ":resources/shaders/shader.frag"); m_pointShader = new Shader(":resources/shaders/anchorPoint.vert", ":resources/shaders/anchorPoint.geom", ":resources/shaders/anchorPoint.frag"); +// m_texture_shader = new Shader(":/resources/shaders/texture.vert", ":/resources/shaders/texture.frag"); + + // INITIALIZE TEXTURE STUFF + + // Prepare filepath + QString kitten_filepath = QString(":/resources/images/kitten.png"); + + // TASK 1: Obtain image from filepath + m_image = QImage(kitten_filepath); + + // TASK 2: Format image to fit OpenGL + m_image = m_image.convertToFormat(QImage::Format_RGBA8888).mirrored(); + + auto bits = m_image.bits(); + + // TASK 3: Generate kitten texture + glGenTextures(1, &m_kitten_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_kitten_texture); + + // TASK 5: Load image into kitten texture + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_image.width(), m_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_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 +// glUseProgram(m_texture_shader->id()); +// glUniform1i(glGetUniformLocation(m_texture_shader->id(), "sampler"), 0); +// glUseProgram(0); + + glUseProgram(m_defaultShader->id()); + glUniform1i(glGetUniformLocation(m_defaultShader->id(), "sampler"), 0); + glUseProgram(0); + +// // TASK 11: Fix this "fullscreen" quad's vertex data +// // TASK 12: Play around with different values! +// // TASK 13: Add UV coordinates +// std::vector fullscreen_quad_data = +// { // POSITIONS // UVs // +// -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, +// -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, +// 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, +// 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, +// -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, +// 1.0f, -1.0f, 0.0f, 1.0f, 0.0f +// }; + +// // Generate and bind a VBO and a VAO for a fullscreen quad +// glGenBuffers(1, &m_fullscreen_vbo); +// glBindBuffer(GL_ARRAY_BUFFER, m_fullscreen_vbo); +// glBufferData(GL_ARRAY_BUFFER, fullscreen_quad_data.size()*sizeof(GLfloat), fullscreen_quad_data.data(), GL_STATIC_DRAW); +// glGenVertexArrays(1, &m_fullscreen_vao); +// glBindVertexArray(m_fullscreen_vao); + +// // TASK 14: modify the code below to add a second attribute to the vertex attribute array +// glEnableVertexAttribArray(0); +// glEnableVertexAttribArray(1); +// glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), nullptr); +// glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), reinterpret_cast(3 * sizeof(GLfloat))); + +// // Unbind the fullscreen quad's VBO and VAO +// glBindBuffer(GL_ARRAY_BUFFER, 0); +// glBindVertexArray(0); + + // END INITIALIZE TEXTURE STUFF + // Initialize ARAP, and get parameters needed to decide the camera position, etc Vector3f coeffMin, coeffMax; @@ -111,11 +186,30 @@ void GLWidget::initializeGL() m_arap.initGroundPlane(":resources/images/kitty.png", 2, m_defaultShader); } +//void GLWidget::paintTexture(GLuint texture, bool filtered){ +//// glUseProgram(m_texture_shader->id()); +// m_texture_shader->bind(); +// // TASK 32: Set your bool uniform on whether or not to filter the texture drawn +//// glUniform1i(glGetUniformLocation(m_texture_shader->id(), "filtered"), filtered); +// m_texture_shader->setUniform("filtered", filtered); +// // TASK 10: Bind "texture" to slot 0 +// glActiveTexture(GL_TEXTURE0); +// glBindTexture(GL_TEXTURE_2D, texture); +// glBindVertexArray(m_fullscreen_vao); +//// std::cout << texture << std::endl; +// glDrawArrays(GL_TRIANGLES, 0, 6); +// glBindTexture(GL_TEXTURE_2D, 0); +// glBindVertexArray(0); +// glUseProgram(0); +// m_texture_shader->unbind(); +//} + void GLWidget::paintGL() { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable( GL_BLEND ); +// paintTexture(m_kitten_texture, false); +// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +// glEnable( GL_BLEND ); m_defaultShader->bind(); m_defaultShader->setUniform("proj", m_camera.getProjection()); @@ -124,7 +218,9 @@ void GLWidget::paintGL() m_defaultShader->setUniform("inverseView", inverseView); m_defaultShader->setUniform("widthBounds", m_arap.minCorner[0], m_arap.maxCorner[0]); m_defaultShader->setUniform("lengthBounds", m_arap.minCorner[2], m_arap.maxCorner[2]); -// m_defaultShader->setUniform(""); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_kitten_texture); m_arap.draw(m_defaultShader, GL_TRIANGLES); m_defaultShader->unbind(); @@ -132,14 +228,14 @@ void GLWidget::paintGL() glClear(GL_DEPTH_BUFFER_BIT); -// m_pointShader->bind(); -// m_pointShader->setUniform("proj", m_camera.getProjection()); -// m_pointShader->setUniform("view", m_camera.getView()); -// m_pointShader->setUniform("vSize", m_vSize); -// m_pointShader->setUniform("width", width()); -// m_pointShader->setUniform("height", height()); -// m_arap.draw(m_pointShader, GL_POINTS); -// m_pointShader->unbind(); +//// m_pointShader->bind(); +//// m_pointShader->setUniform("proj", m_camera.getProjection()); +//// m_pointShader->setUniform("view", m_camera.getView()); +//// m_pointShader->setUniform("vSize", m_vSize); +//// m_pointShader->setUniform("width", width()); +//// m_pointShader->setUniform("height", height()); +//// m_arap.draw(m_pointShader, GL_POINTS); +//// m_pointShader->unbind(); } void GLWidget::resizeGL(int w, int h) diff --git a/src/glwidget.h b/src/glwidget.h index b319756..6433e22 100755 --- a/src/glwidget.h +++ b/src/glwidget.h @@ -29,6 +29,7 @@ private: // Basic OpenGL Overrides void initializeGL() override; void paintGL() override; + void paintTexture(GLuint texture, bool filtered); void resizeGL(int w, int h) override; // Event Listeners @@ -48,6 +49,12 @@ private: Camera m_camera; Shader *m_defaultShader; Shader *m_pointShader; + Shader *m_texture_shader; + + GLuint m_fullscreen_vbo; + GLuint m_fullscreen_vao; + QImage m_image; + GLuint m_kitten_texture; float m_movementScaling; float m_vertexSelectionThreshold; 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 afeffed93532c42540636c79cd9ae832656efef4 Mon Sep 17 00:00:00 2001 From: Sebastian Park Date: Tue, 23 Apr 2024 03:34:26 -0400 Subject: Add more textures. --- CMakeLists.txt | 2 ++ resources/images/anamorphic.jpg | Bin 0 -> 29950 bytes resources/images/caustic_sample.jpg | Bin 0 -> 87477 bytes resources/shaders/shader.frag | 2 +- src/glwidget.cpp | 2 +- 5 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 resources/images/anamorphic.jpg create mode 100644 resources/images/caustic_sample.jpg (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index cdacb7f..2a726bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,8 @@ qt6_add_resources(${PROJECT_NAME} "Resources" resources/images/kitten.png resources/images/hello.png resources/images/sand_text.jpg + resources/images/caustic_sample.jpg + resources/images/anamorphic.jpg # resources/images/ground.png resources/shaders/shader.frag resources/shaders/shader.vert diff --git a/resources/images/anamorphic.jpg b/resources/images/anamorphic.jpg new file mode 100644 index 0000000..c3dceaf Binary files /dev/null and b/resources/images/anamorphic.jpg differ diff --git a/resources/images/caustic_sample.jpg b/resources/images/caustic_sample.jpg new file mode 100644 index 0000000..b6fec46 Binary files /dev/null and b/resources/images/caustic_sample.jpg differ diff --git a/resources/shaders/shader.frag b/resources/shaders/shader.frag index 2e4e780..970d443 100755 --- a/resources/shaders/shader.frag +++ b/resources/shaders/shader.frag @@ -64,7 +64,7 @@ void main() { vec4 diffuse = vec4(red * d, green * d, blue * d, 1.0f); vec4 specular = vec4(1, 1, 1, 1) * pow(spec, 10.f); // vec4 transmissive = vec4(vec3(refrUV, 1.f - refrUV.y), 1.f); - float waterBlurriness = 0.1f; + float waterBlurriness = 0.f; vec2 refrUVBlurry = (1 - beerAtt) * vec2(rand(refrUV), rand(vec4(pos, d))) * waterBlurriness + refrUV; vec4 transmissive = texture(sampler, vec2(refrUVBlurry)); diff --git a/src/glwidget.cpp b/src/glwidget.cpp index 472966b..5356bb3 100755 --- a/src/glwidget.cpp +++ b/src/glwidget.cpp @@ -81,7 +81,7 @@ void GLWidget::initializeGL() // INITIALIZE TEXTURE STUFF // Prepare filepath - QString kitten_filepath = QString(":/resources/images/kitten.png"); + QString kitten_filepath = QString(":/resources/images/anamorphic.jpg"); // TASK 1: Obtain image from filepath m_image = QImage(kitten_filepath); -- cgit v1.2.3-70-g09d2 From 040a37e1a7546075b25db08ed036f4772a0abf42 Mon Sep 17 00:00:00 2001 From: Sebastian Park Date: Tue, 23 Apr 2024 03:37:06 -0400 Subject: Change texture name and use shader class abstractions. --- src/glwidget.cpp | 14 +++++++------- src/glwidget.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/glwidget.cpp b/src/glwidget.cpp index 5356bb3..3d02949 100755 --- a/src/glwidget.cpp +++ b/src/glwidget.cpp @@ -92,13 +92,13 @@ void GLWidget::initializeGL() auto bits = m_image.bits(); // TASK 3: Generate kitten texture - glGenTextures(1, &m_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_kitten_texture); + glBindTexture(GL_TEXTURE_2D, m_ground_texture); // TASK 5: Load image into kitten texture glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_image.width(), m_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_image.bits()); @@ -115,9 +115,9 @@ void GLWidget::initializeGL() // glUniform1i(glGetUniformLocation(m_texture_shader->id(), "sampler"), 0); // glUseProgram(0); - glUseProgram(m_defaultShader->id()); - glUniform1i(glGetUniformLocation(m_defaultShader->id(), "sampler"), 0); - glUseProgram(0); + 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! @@ -206,7 +206,7 @@ void GLWidget::initializeGL() void GLWidget::paintGL() { -// paintTexture(m_kitten_texture, false); +// paintTexture(m_ground_texture, false); // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // glEnable( GL_BLEND ); @@ -220,7 +220,7 @@ void GLWidget::paintGL() m_defaultShader->setUniform("lengthBounds", m_arap.minCorner[2], m_arap.maxCorner[2]); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_kitten_texture); + glBindTexture(GL_TEXTURE_2D, m_ground_texture); m_arap.draw(m_defaultShader, GL_TRIANGLES); m_defaultShader->unbind(); diff --git a/src/glwidget.h b/src/glwidget.h index 6433e22..d875cd1 100755 --- a/src/glwidget.h +++ b/src/glwidget.h @@ -54,7 +54,7 @@ private: GLuint m_fullscreen_vbo; GLuint m_fullscreen_vao; QImage m_image; - GLuint m_kitten_texture; + GLuint m_ground_texture; float m_movementScaling; float m_vertexSelectionThreshold; -- cgit v1.2.3-70-g09d2 From afea13471ff50d0c8500210c0a15fcf686a77832 Mon Sep 17 00:00:00 2001 From: Sebastian Park Date: Tue, 23 Apr 2024 03:38:57 -0400 Subject: replace variable names. --- src/glwidget.cpp | 14 +++++--------- src/glwidget.h | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/glwidget.cpp b/src/glwidget.cpp index 3d02949..d172868 100755 --- a/src/glwidget.cpp +++ b/src/glwidget.cpp @@ -81,15 +81,15 @@ void GLWidget::initializeGL() // INITIALIZE TEXTURE STUFF // Prepare filepath - QString kitten_filepath = QString(":/resources/images/anamorphic.jpg"); + QString ground_texture_filepath = QString(":/resources/images/anamorphic.jpg"); // TASK 1: Obtain image from filepath - m_image = QImage(kitten_filepath); + m_ground_image = QImage(ground_texture_filepath); // TASK 2: Format image to fit OpenGL - m_image = m_image.convertToFormat(QImage::Format_RGBA8888).mirrored(); + m_ground_image = m_ground_image.convertToFormat(QImage::Format_RGBA8888).mirrored(); - auto bits = m_image.bits(); + auto bits = m_ground_image.bits(); // TASK 3: Generate kitten texture glGenTextures(1, &m_ground_texture); @@ -101,7 +101,7 @@ void GLWidget::initializeGL() glBindTexture(GL_TEXTURE_2D, m_ground_texture); // TASK 5: Load image into kitten texture - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_image.width(), m_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_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); @@ -111,10 +111,6 @@ void GLWidget::initializeGL() glBindTexture(GL_TEXTURE_2D, 0); // // TASK 10: set the texture.frag uniform for our texture -// glUseProgram(m_texture_shader->id()); -// glUniform1i(glGetUniformLocation(m_texture_shader->id(), "sampler"), 0); -// glUseProgram(0); - m_defaultShader->bind(); m_defaultShader->setUniform("sampler", 0); m_defaultShader->unbind(); diff --git a/src/glwidget.h b/src/glwidget.h index d875cd1..91df32f 100755 --- a/src/glwidget.h +++ b/src/glwidget.h @@ -53,7 +53,7 @@ private: GLuint m_fullscreen_vbo; GLuint m_fullscreen_vao; - QImage m_image; + QImage m_ground_image; GLuint m_ground_texture; float m_movementScaling; -- 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') 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') 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