summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastian Park <SebPark03@gmail.com>2024-04-23 12:06:00 -0400
committerSebastian Park <SebPark03@gmail.com>2024-04-23 12:06:00 -0400
commit12ec81fd1624e9b06e03d9a53a1873f63fe99c3b (patch)
treedb528688bbf888cf0f147a698d061f5c7ae89560 /src
parenta556b45abf18f1bd509daaf63b66b7d55e9fd291 (diff)
parent6a5806b82c44a2cae481a6015d1a0f390e4b8445 (diff)
Merge branch 'shaders'
Diffstat (limited to 'src')
-rwxr-xr-xsrc/glwidget.cpp119
-rwxr-xr-xsrc/glwidget.h7
-rw-r--r--src/graphics/shape.cpp77
-rw-r--r--src/graphics/shape.h5
4 files changed, 148 insertions, 60 deletions
diff --git a/src/glwidget.cpp b/src/glwidget.cpp
index f5fc941..8ab2115 100755
--- a/src/glwidget.cpp
+++ b/src/glwidget.cpp
@@ -73,12 +73,52 @@ 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
+
+
+// // TASK 11: Fix this "fullscreen" quad's vertex data
+// // TASK 12: Play around with different values!
+// // TASK 13: Add UV coordinates
+// std::vector<GLfloat> 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
+// };
+ 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);
+// 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<void *>(3 * sizeof(GLfloat)));
+
+// // Unbind the fullscreen quad's VBO and VAO
+// glBindBuffer(GL_ARRAY_BUFFER, 0);
+// glBindVertexArray(0);
+
+ // END INITIALIZE TEXTURE STUFF
+
// initialize texture
m_texture0 = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/hello.png").textureID;
@@ -118,22 +158,41 @@ void GLWidget::initializeGL()
//m_arap.initGroundPlane(":resources/images/kitty.png", 2, m_defaultShader);
//INIT FBO
- m_devicePixelRatio = this->devicePixelRatio();
+ // m_devicePixelRatio = this->devicePixelRatio();
- m_defaultFBO = 2;
- m_screen_width = size().width() * m_devicePixelRatio;
- m_screen_height = size().height() * m_devicePixelRatio;
- m_fbo_width = m_screen_width;
- m_fbo_height = m_screen_height;
+ // m_defaultFBO = 2;
+ // m_screen_width = size().width() * m_devicePixelRatio;
+ // m_screen_height = size().height() * m_devicePixelRatio;
+ // m_fbo_width = m_screen_width;
+ // m_fbo_height = m_screen_height;
- initFullScreenQuad();
+ // initFullScreenQuad();
}
+//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_ground_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());
@@ -143,39 +202,19 @@ 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]);
- // bind texture
- m_defaultShader->setUniform("texture_img", 0);
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, m_texture0);
-
-
-// m_defaultShader->setUniform("");
m_arap.draw(m_defaultShader, GL_TRIANGLES);
m_defaultShader->unbind();
- //glBindTexture(GL_TEXTURE_2D, 0);
-
-// glClear(GL_DEPTH_BUFFER_BIT);
-
-
-// glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
-// // Task 25: Bind the default framebuffer
-// glBindFramebuffer(GL_FRAMEBUFFER, m_defaultFBO);
-// glViewport(0, 0, m_screen_width, m_screen_height);
-
- // Task 26: Clear the color and depth buffers
-
- // Task 27: Call paintTexture to draw our FBO color attachment texture | Task 31: Set bool parameter to true
- paintTexture(m_texture0, true);
+ 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::paintTexture(GLuint texture, bool postProcessOn){
diff --git a/src/glwidget.h b/src/glwidget.h
index 71199d1..9dd3744 100755
--- a/src/glwidget.h
+++ b/src/glwidget.h
@@ -35,6 +35,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
@@ -63,6 +64,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_ground_image;
+ GLuint m_ground_texture;
float m_movementScaling;
float m_vertexSelectionThreshold;
diff --git a/src/graphics/shape.cpp b/src/graphics/shape.cpp
index c5dde0d..6c7ea00 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();
@@ -127,12 +131,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<GLvoid *>(0));
glBindVertexArray(0);
- glBindTexture(GL_TEXTURE_2D, 0);
+// glBindTexture(GL_TEXTURE_2D, 0);
break;
}
case GL_POINTS:
@@ -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,47 @@ 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();
+}
+
+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 b909606..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);
@@ -51,8 +52,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;