diff --git a/cw 6/grk-cw6.vcxproj b/cw 6/grk-cw6.vcxproj
index af61d3f..be4dfe3 100644
--- a/cw 6/grk-cw6.vcxproj
+++ b/cw 6/grk-cw6.vcxproj
@@ -41,6 +41,8 @@
+
+
{10701B86-9B0B-46A1-85DA-6238CBCC507B}
diff --git a/cw 6/grk-cw6.vcxproj.filters b/cw 6/grk-cw6.vcxproj.filters
index ff18640..8bc346a 100644
--- a/cw 6/grk-cw6.vcxproj.filters
+++ b/cw 6/grk-cw6.vcxproj.filters
@@ -102,6 +102,12 @@
Shader Files
+
+
+ Shader Files
+
+
+ Shader Files
\ No newline at end of file
diff --git a/cw 6/shaders/bubbles_shader_color.frag b/cw 6/shaders/bubbles_shader_color.frag
new file mode 100644
index 0000000..c791d67
--- /dev/null
+++ b/cw 6/shaders/bubbles_shader_color.frag
@@ -0,0 +1,13 @@
+#version 410 core
+
+uniform vec3 objectColor;
+uniform vec3 lightDir;
+
+in vec3 interpNormal;
+
+void main()
+{
+ vec3 normal = normalize(interpNormal);
+ float diffuse = 0.4;
+ gl_FragColor = vec4(objectColor * diffuse, 1.0);
+}
diff --git a/cw 6/shaders/bubbles_shader_color.vert b/cw 6/shaders/bubbles_shader_color.vert
new file mode 100644
index 0000000..ac46ad3
--- /dev/null
+++ b/cw 6/shaders/bubbles_shader_color.vert
@@ -0,0 +1,16 @@
+#version 410 core
+
+layout(location = 0) in vec3 vertexPosition;
+layout(location = 1) in vec3 vertexNormal;
+layout(location = 2) in vec2 vertexTexCoord;
+
+uniform mat4 modelViewProjectionMatrix;
+uniform mat4 modelMatrix;
+
+out vec3 interpNormal;
+
+void main()
+{
+ gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
+ interpNormal = (modelMatrix * vec4(vertexNormal, 0.0)).xyz;
+}
\ No newline at end of file
diff --git a/cw 6/src/main_6_1.cpp b/cw 6/src/main_6_1.cpp
index ac20f9b..e87b416 100644
--- a/cw 6/src/main_6_1.cpp
+++ b/cw 6/src/main_6_1.cpp
@@ -24,8 +24,6 @@ enum {
PASS_NORMAL, PASS_CAUSTIC
};
-void bubbleManager();
-
static GLboolean HaveTexObj = GL_FALSE;
static int reportSpeed = 0;
static int dinoDisplayList;
@@ -60,6 +58,7 @@ glm::vec3 fishLocation2[fish2Number];
GLuint programColor;
GLuint programTexture;
GLuint skyboxTexture;
+GLuint bubblesColor;
Core::Shader_Loader shaderLoader;
@@ -151,6 +150,8 @@ glm::vec3 starLocation;
bool starIsPlaced = false;
+void bubbleManager();
+
void keyboard(unsigned char key, int x, int y)
{
@@ -321,6 +322,24 @@ void drawObjectColor(Core::RenderContext context, glm::mat4 modelMatrix, glm::ve
glUseProgram(0);
}
+void drawBubbleColor(Core::RenderContext context, glm::mat4 modelMatrix, glm::vec3 color)
+{
+ GLuint program = bubblesColor;
+
+ glUseProgram(program);
+
+ glUniform3f(glGetUniformLocation(program, "objectColor"), color.x, color.y, color.z);
+ glUniform3f(glGetUniformLocation(program, "lightDir"), lightDir.x, lightDir.y, lightDir.z);
+
+ glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
+ glUniformMatrix4fv(glGetUniformLocation(program, "modelViewProjectionMatrix"), 1, GL_FALSE, (float*)&transformation);
+ glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
+
+ Core::DrawContext(context);
+
+ glUseProgram(0);
+}
+
void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuint textureId)
{
GLuint program = programTexture;
@@ -561,7 +580,7 @@ void drawScene()
drawObjectTexture(fish1Context, modelMatrix, textureFish01);
- bubbleManager();
+ //bubbleManager();
gameManager();
for (int i = 0; i < fish1Number; i++)
@@ -647,6 +666,8 @@ void drawScene()
drawPlaneTexture(planeContext, glm::rotate(glm::radians(90.f), glm::vec3(0.f, 0.f, 1.f)), groundTexture);
+ bubbleManager();
+
glUseProgram(skyboxTexture);
glUniform1i(glGetUniformLocation(skyboxTexture, "skybox"), 0);
glm::mat4 transformation = perspectiveMatrix * glm::mat4(glm::mat3(cameraMatrix));
@@ -667,9 +688,15 @@ void drawScene()
glHint(GL_FOG_HINT, GL_DONT_CARE); // Fog Hint Value
glFogf(GL_FOG_START, 1.0f); // Fog Start Depth
glFogf(GL_FOG_END, 5.0f); // Fog End Depth
+
glEnable(GL_FOG);
+
glDepthFunc(GL_LESS); // set depth function back to default
+
+
+
+
glUseProgram(0);
@@ -739,10 +766,11 @@ void bubbleManager() {
glm::mat4 modelMatrix = glm::translate(bubbleLocation[i]);
// Scaling models
- glm::vec3 scale = glm::vec3(0.05, 0.05, 0.05);
+ glm::vec3 scale = glm::vec3(0.02, 0.02, 0.02);
modelMatrix = glm::scale(modelMatrix, scale);
//drawObjectTexture(bubbleContext, modelMatrix, bubbleTexture);
- drawObjectColor(bubbleContext, modelMatrix, glm::vec3(.3f, .55f, 0.96f));
+ //drawBubbleColor(bubbleContext, modelMatrix, glm::vec4(.3f, .55f, 0.96f, 1.f));
+ drawBubbleColor(bubbleContext, modelMatrix, glm::vec3(.3f, .55f, 0.96f));
}
}
@@ -825,6 +853,7 @@ void renderScene()
glEnable(GL_BLEND);
drawSceneLight(PASS_CAUSTIC);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
/* Restore fragment operations to normal. */
glDepthMask(GL_TRUE);
@@ -833,6 +862,7 @@ void renderScene()
}
glPopMatrix();
+
glutSwapBuffers();
if (reportSpeed) {
@@ -893,6 +923,7 @@ void init()
programColor = shaderLoader.CreateProgram("shaders/shader_color.vert", "shaders/shader_color.frag");
programTexture = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
skyboxTexture = shaderLoader.CreateProgram("shaders/skybox_tex.vert", "shaders/skybox_tex.frag");
+ bubblesColor = shaderLoader.CreateProgram("shaders/bubbles_shader_color.vert", "shaders/bubbles_shader_color.frag");
//Zaladowanie tekstur do skyboxa
cubemapTexture = loadCubemap(faces);
@@ -977,6 +1008,7 @@ int main(int argc, char** argv)
glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
glutCreateWindow("OpenGL Pierwszy Program");
+
glewInit();
init();