summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.DS_Storebin10244 -> 10244 bytes
-rw-r--r--CMakeLists.txt7
-rw-r--r--CMakeLists.txt.user2
-rw-r--r--resources/images/anamorphic.jpgbin0 -> 29950 bytes
-rw-r--r--resources/images/caustic_sample.jpgbin0 -> 87477 bytes
-rw-r--r--resources/images/sand_text.jpgbin0 -> 23150 bytes
-rw-r--r--resources/images/uv1 copy.pngbin48020 -> 0 bytes
-rw-r--r--resources/images/uv1.pngbin86064 -> 48020 bytes
-rw-r--r--resources/images/uv1_cut.pngbin0 -> 86064 bytes
-rwxr-xr-xresources/shaders/shader.frag44
-rwxr-xr-xresources/shaders/shader.vert19
-rw-r--r--resources/shaders/texture.frag24
-rw-r--r--resources/shaders/texture.vert15
-rwxr-xr-xsrc/glwidget.cpp119
-rwxr-xr-xsrc/glwidget.h7
-rw-r--r--src/graphics/shape.cpp77
-rw-r--r--src/graphics/shape.h5
17 files changed, 240 insertions, 79 deletions
diff --git a/.DS_Store b/.DS_Store
index e355160..a6de465 100644
--- a/.DS_Store
+++ b/.DS_Store
Binary files differ
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7d7f314..2a726bc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -85,12 +85,17 @@ qt6_add_resources(${PROJECT_NAME} "Resources"
resources/images/uv1.png
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
resources/shaders/anchorPoint.vert
resources/shaders/anchorPoint.geom
resources/shaders/anchorPoint.frag
+ resources/shaders/texture.vert
+ resources/shaders/texture.frag
)
# GLEW: this provides support for Windows (including 64-bit)
diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user
index cca3cf6..59a90d4 100644
--- a/CMakeLists.txt.user
+++ b/CMakeLists.txt.user
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 8.0.1, 2024-04-22T04:03:29. -->
+<!-- Written by QtCreator 8.0.1, 2024-04-23T11:54:14. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
diff --git a/resources/images/anamorphic.jpg b/resources/images/anamorphic.jpg
new file mode 100644
index 0000000..c3dceaf
--- /dev/null
+++ b/resources/images/anamorphic.jpg
Binary files differ
diff --git a/resources/images/caustic_sample.jpg b/resources/images/caustic_sample.jpg
new file mode 100644
index 0000000..b6fec46
--- /dev/null
+++ b/resources/images/caustic_sample.jpg
Binary files differ
diff --git a/resources/images/sand_text.jpg b/resources/images/sand_text.jpg
new file mode 100644
index 0000000..6a64486
--- /dev/null
+++ b/resources/images/sand_text.jpg
Binary files differ
diff --git a/resources/images/uv1 copy.png b/resources/images/uv1 copy.png
deleted file mode 100644
index fcf4825..0000000
--- a/resources/images/uv1 copy.png
+++ /dev/null
Binary files differ
diff --git a/resources/images/uv1.png b/resources/images/uv1.png
index 82ff8ac..fcf4825 100644
--- a/resources/images/uv1.png
+++ b/resources/images/uv1.png
Binary files differ
diff --git a/resources/images/uv1_cut.png b/resources/images/uv1_cut.png
new file mode 100644
index 0000000..82ff8ac
--- /dev/null
+++ b/resources/images/uv1_cut.png
Binary files differ
diff --git a/resources/shaders/shader.frag b/resources/shaders/shader.frag
index fc78890..7df2588 100755
--- a/resources/shaders/shader.frag
+++ b/resources/shaders/shader.frag
@@ -8,6 +8,7 @@ in vec3 pos;
in vec3 refrPos;
in float refrProb;
in vec2 uv;
+in float matIor;
uniform sampler2D texture_img;
@@ -22,6 +23,20 @@ uniform vec2 widthBounds;
uniform vec2 lengthBounds;
//uniform float test = 0;
+float rand(vec2 n) {
+ return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
+}
+
+float rand(float n) {
+ return fract(sin(n) * 43758.5453123);
+}
+
+float rand(vec4 n) {
+// vec2 first2 = vec2(n[0], n[1]);
+//// return 1.f;
+ return rand(vec2(n[0] * rand(n[2]), n[1] * rand(n[3])));
+}
+
vec2 uvFromWorldPoint(vec3 point) {
float u = (point.x - widthBounds[0]) / (widthBounds[1] - widthBounds[0]);
float v = (point.z - lengthBounds[0]) / (lengthBounds[1] - lengthBounds[0]);
@@ -47,21 +62,32 @@ void main() {
// fragColor = vec4(fragColor.x, 0.f, fragColor.z, 1.f);
// fragColor = vec4(test, test, test, 1.f);
vec2 refrUV = uvFromWorldPoint(refrPos);
- vec4 transmissive = vec4(vec3(refrUV, 1.f - refrUV.y), 1.f);
+ float beerAtt = exp(-length((pos - refrPos)) * 0.2f); // TODO: Make uniform
+
+ 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.f;
+ vec2 refrUVBlurry = (1 - beerAtt) * vec2(rand(refrUV), rand(vec4(pos, d))) * waterBlurriness + refrUV;
+ vec4 transmissive = texture(sampler, vec2(refrUVBlurry));
+
+// refrProb *= beerAtt;
- fragColor = 0.25f * vec4(red * d, green * d, blue * d, 1.0f); // Diffuse
- fragColor += 0.75f * vec4(1, 1, 1, 1) * pow(spec, 10.f); // Specular TODO: Pass multiplications as uniforms.
+ fragColor = 0.75f * diffuse; // Diffuse
+ fragColor += 0.6f * specular; // Specular TODO: Pass multiplications as uniforms.
fragColor = clamp(fragColor, 0.f, 1.f); // Clamp
- fragColor *= (1 - (refrProb / 1.f));
- fragColor += (refrProb / 1.5f) * transmissive;
+ fragColor *= (1 - ((beerAtt * refrProb) / 1.f));
+ fragColor += ((beerAtt * refrProb) / 1.5f) * transmissive;
// fragColor = transmissive * refrProb;
fragColor = vec4(vec3(fragColor), 1.5f);
// Dividing refrProb by 2 just for heuristic. Want more phong to show through.
// fragColor = clamp(fragColor, 0.f, 1.f);
// fragColor = vec4(refrProb, 0.f, 0.f, 1.f);
-
- // assign texture
- fragColor = texture(texture_img, uv);
-
+ // TODO: ACTUAL LIGHTING MODEL SHOULD BE SOMETHING LIKE
+ // VELOCITY * DIFFUSE
+ // (1 - refrProb) * SPECULAR
+ // refrProb * (BEER * TRANSMISSIVE + (1 - beerAtt) * VOLUME (which is somewhat diffuse too?))
+ // Transmissive shouldn't just get darker, but blurrier as beer attenuation lowers.
+// fragColor = texture(sampler, vec2(refrUV));
}
diff --git a/resources/shaders/shader.vert b/resources/shaders/shader.vert
index 8447dd9..750a4da 100755
--- a/resources/shaders/shader.vert
+++ b/resources/shaders/shader.vert
@@ -21,13 +21,15 @@ out vec3 pos;
out vec3 refrPos;
out float refrProb;
out vec2 uv;
+out float matIor;
vec4 getRefrPos() {
- float depth = -1.f; // TODO: Pass as uniform
+ float depth = -3.f; // TODO: Pass as uniform
vec3 w_o = normalize(pos - camera_worldSpace);
float cos_theta_i = dot(-w_o, normal_worldSpace);
float n_i = 1;
float n_t = 1.33f;
+// matIor = n_t;
float determinant = 1.f - (pow((n_i / n_t), 2.f) * (1.f - pow(cos_theta_i, 2.f)));
float r0 = pow((n_i - n_t) / (n_i + n_t), 2.f); // variable required to calculate probability of reflection
@@ -52,10 +54,11 @@ vec4 getRefrPos() {
}
void main() {
- float depth = -2.f;
- float dist = position.y - depth;
+// float depth = -4.f;
+// float dist = position.y - depth;
float width = 81.f * 2.f;
float length = 81.f * 2.f;
+ matIor = 1.33f;
normal_cameraSpace = normalize(inverse(transpose(mat3(view))) * inverseTransposeModel * normal);
camera_worldSpace = vec3(inverseView * vec4(0.f, 0.f, 0.f, 1.f));
@@ -63,11 +66,11 @@ void main() {
pos = vec3(model * vec4(position, 1.f)); //vec3(model * vec4(objSpacePos, 1.f));
// pos = position;
- float depthScale = dist / normal.y;
- vec3 groundContactPoint = -(normal * depthScale) + position; // carries down to ground
- groundContactPoint = vec3(model * vec4(position, 1));
- uv = vec2((position.x + 81.f) / (162.f), groundContactPoint.z);
- uv = vec2(texCoords);
+// float depthScale = dist / normal.y;
+// vec3 groundContactPoint = -(normal * depthScale) + position; // carries down to ground
+// groundContactPoint = vec3(model * vec4(position, 1));
+// uv = vec2((position.x + 81.f) / (162.f), groundContactPoint.z);
+// uv = vec2(normal);
vec4 refrPos_and_prob = getRefrPos();
refrPos = vec3(refrPos_and_prob);
refrProb = clamp(refrPos_and_prob.w, 0.f, 1.f);
diff --git a/resources/shaders/texture.frag b/resources/shaders/texture.frag
new file mode 100644
index 0000000..c7a5956
--- /dev/null
+++ b/resources/shaders/texture.frag
@@ -0,0 +1,24 @@
+#version 330 core
+
+// TASK 16: Create a UV coordinate in variable
+in vec2 uv;
+
+// TASK 8: Add a sampler2D uniform
+uniform sampler2D sampler;
+
+// TASK 29: Add a bool on whether or not to filter the texture
+uniform bool filtered;
+
+out vec4 fragColor;
+
+void main()
+{
+ // TASK 17: Set fragColor using the sampler2D at the UV coordinate
+ fragColor = texture(sampler, uv);
+
+ // TASK 33: Invert fragColor's r, g, and b color channels if your bool is true
+ if(filtered){
+ fragColor = vec4(1) - fragColor;
+ fragColor.w = 1;
+ }
+}
diff --git a/resources/shaders/texture.vert b/resources/shaders/texture.vert
new file mode 100644
index 0000000..c87f366
--- /dev/null
+++ b/resources/shaders/texture.vert
@@ -0,0 +1,15 @@
+#version 330 core
+
+// TASK 15: add a second layout variable representing a UV coordinate
+layout (location = 0) in vec3 position;
+layout (location = 1) in vec2 uv_raw;
+
+// TASK 16: create an "out" variable representing a UV coordinate
+out vec2 uv;
+
+void main() {
+ // TASK 16: assign the UV layout variable to the UV "out" variable
+ uv = uv_raw;
+
+ gl_Position = vec4(position, 1.0);
+}
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;