Improved bubbles
This commit is contained in:
parent
7669dca8d9
commit
95b2ec0acc
@ -41,6 +41,8 @@
|
|||||||
<None Include="shaders\shader_tex.vert" />
|
<None Include="shaders\shader_tex.vert" />
|
||||||
<None Include="shaders\skybox_tex.vert" />
|
<None Include="shaders\skybox_tex.vert" />
|
||||||
<None Include="shaders\skybox_tex.frag" />
|
<None Include="shaders\skybox_tex.frag" />
|
||||||
|
<None Include="shaders\bubbles_shader_color.vert" />
|
||||||
|
<None Include="shaders\bubbles_shader_color.frag" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{10701B86-9B0B-46A1-85DA-6238CBCC507B}</ProjectGuid>
|
<ProjectGuid>{10701B86-9B0B-46A1-85DA-6238CBCC507B}</ProjectGuid>
|
||||||
|
@ -102,6 +102,12 @@
|
|||||||
</None>
|
</None>
|
||||||
<None Include="shaders\skybox_tex.frag">
|
<None Include="shaders\skybox_tex.frag">
|
||||||
<Filter>Shader Files</Filter>
|
<Filter>Shader Files</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="shaders\bubbles_shader_color.vert">
|
||||||
|
<Filter>Shader Files</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="shaders\bubbles_shader_color.frag">
|
||||||
|
<Filter>Shader Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
13
cw 6/shaders/bubbles_shader_color.frag
Normal file
13
cw 6/shaders/bubbles_shader_color.frag
Normal file
@ -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);
|
||||||
|
}
|
16
cw 6/shaders/bubbles_shader_color.vert
Normal file
16
cw 6/shaders/bubbles_shader_color.vert
Normal file
@ -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;
|
||||||
|
}
|
@ -24,8 +24,6 @@ enum {
|
|||||||
PASS_NORMAL, PASS_CAUSTIC
|
PASS_NORMAL, PASS_CAUSTIC
|
||||||
};
|
};
|
||||||
|
|
||||||
void bubbleManager();
|
|
||||||
|
|
||||||
static GLboolean HaveTexObj = GL_FALSE;
|
static GLboolean HaveTexObj = GL_FALSE;
|
||||||
static int reportSpeed = 0;
|
static int reportSpeed = 0;
|
||||||
static int dinoDisplayList;
|
static int dinoDisplayList;
|
||||||
@ -60,6 +58,7 @@ glm::vec3 fishLocation2[fish2Number];
|
|||||||
GLuint programColor;
|
GLuint programColor;
|
||||||
GLuint programTexture;
|
GLuint programTexture;
|
||||||
GLuint skyboxTexture;
|
GLuint skyboxTexture;
|
||||||
|
GLuint bubblesColor;
|
||||||
|
|
||||||
Core::Shader_Loader shaderLoader;
|
Core::Shader_Loader shaderLoader;
|
||||||
|
|
||||||
@ -151,6 +150,8 @@ glm::vec3 starLocation;
|
|||||||
|
|
||||||
bool starIsPlaced = false;
|
bool starIsPlaced = false;
|
||||||
|
|
||||||
|
void bubbleManager();
|
||||||
|
|
||||||
void keyboard(unsigned char key, int x, int y)
|
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);
|
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)
|
void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuint textureId)
|
||||||
{
|
{
|
||||||
GLuint program = programTexture;
|
GLuint program = programTexture;
|
||||||
@ -561,7 +580,7 @@ void drawScene()
|
|||||||
|
|
||||||
drawObjectTexture(fish1Context, modelMatrix, textureFish01);
|
drawObjectTexture(fish1Context, modelMatrix, textureFish01);
|
||||||
|
|
||||||
bubbleManager();
|
//bubbleManager();
|
||||||
gameManager();
|
gameManager();
|
||||||
|
|
||||||
for (int i = 0; i < fish1Number; i++)
|
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);
|
drawPlaneTexture(planeContext, glm::rotate(glm::radians(90.f), glm::vec3(0.f, 0.f, 1.f)), groundTexture);
|
||||||
|
|
||||||
|
bubbleManager();
|
||||||
|
|
||||||
glUseProgram(skyboxTexture);
|
glUseProgram(skyboxTexture);
|
||||||
glUniform1i(glGetUniformLocation(skyboxTexture, "skybox"), 0);
|
glUniform1i(glGetUniformLocation(skyboxTexture, "skybox"), 0);
|
||||||
glm::mat4 transformation = perspectiveMatrix * glm::mat4(glm::mat3(cameraMatrix));
|
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
|
glHint(GL_FOG_HINT, GL_DONT_CARE); // Fog Hint Value
|
||||||
glFogf(GL_FOG_START, 1.0f); // Fog Start Depth
|
glFogf(GL_FOG_START, 1.0f); // Fog Start Depth
|
||||||
glFogf(GL_FOG_END, 5.0f); // Fog End Depth
|
glFogf(GL_FOG_END, 5.0f); // Fog End Depth
|
||||||
|
|
||||||
glEnable(GL_FOG);
|
glEnable(GL_FOG);
|
||||||
|
|
||||||
|
|
||||||
glDepthFunc(GL_LESS); // set depth function back to default
|
glDepthFunc(GL_LESS); // set depth function back to default
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
|
|
||||||
|
|
||||||
@ -739,10 +766,11 @@ void bubbleManager() {
|
|||||||
|
|
||||||
glm::mat4 modelMatrix = glm::translate(bubbleLocation[i]);
|
glm::mat4 modelMatrix = glm::translate(bubbleLocation[i]);
|
||||||
// Scaling models
|
// 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);
|
modelMatrix = glm::scale(modelMatrix, scale);
|
||||||
//drawObjectTexture(bubbleContext, modelMatrix, bubbleTexture);
|
//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);
|
glEnable(GL_BLEND);
|
||||||
|
|
||||||
drawSceneLight(PASS_CAUSTIC);
|
drawSceneLight(PASS_CAUSTIC);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
/* Restore fragment operations to normal. */
|
/* Restore fragment operations to normal. */
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
@ -833,6 +862,7 @@ void renderScene()
|
|||||||
}
|
}
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
|
|
||||||
if (reportSpeed) {
|
if (reportSpeed) {
|
||||||
@ -893,6 +923,7 @@ void init()
|
|||||||
programColor = shaderLoader.CreateProgram("shaders/shader_color.vert", "shaders/shader_color.frag");
|
programColor = shaderLoader.CreateProgram("shaders/shader_color.vert", "shaders/shader_color.frag");
|
||||||
programTexture = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
|
programTexture = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
|
||||||
skyboxTexture = shaderLoader.CreateProgram("shaders/skybox_tex.vert", "shaders/skybox_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
|
//Zaladowanie tekstur do skyboxa
|
||||||
cubemapTexture = loadCubemap(faces);
|
cubemapTexture = loadCubemap(faces);
|
||||||
@ -977,6 +1008,7 @@ int main(int argc, char** argv)
|
|||||||
glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
|
glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
|
||||||
|
|
||||||
glutCreateWindow("OpenGL Pierwszy Program");
|
glutCreateWindow("OpenGL Pierwszy Program");
|
||||||
|
|
||||||
glewInit();
|
glewInit();
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
Loading…
Reference in New Issue
Block a user