bubbles #10
Binary file not shown.
Binary file not shown.
2929
grafika_projekt/models/sphere.obj
Normal file
2929
grafika_projekt/models/sphere.obj
Normal file
File diff suppressed because it is too large
Load Diff
16
grafika_projekt/shaders/bubble.frag
Normal file
16
grafika_projekt/shaders/bubble.frag
Normal file
@ -0,0 +1,16 @@
|
||||
#version 410 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec3 Normal;
|
||||
in vec3 Position;
|
||||
|
||||
uniform vec3 cameraPos;
|
||||
uniform samplerCube skybox;
|
||||
|
||||
void main()
|
||||
{
|
||||
float ratio = 1.00 / 1.52;
|
||||
vec3 I = normalize(Position - cameraPos);
|
||||
vec3 R = refract(I, normalize(Normal), ratio);
|
||||
FragColor = vec4(texture(skybox, R).rgb, 1.0);
|
||||
}
|
17
grafika_projekt/shaders/bubble.vert
Normal file
17
grafika_projekt/shaders/bubble.vert
Normal file
@ -0,0 +1,17 @@
|
||||
#version 410 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
|
||||
out vec3 Normal;
|
||||
out vec3 Position;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
Position = vec3(model * vec4(aPos, 1.0));
|
||||
gl_Position = projection * view * vec4(Position, 1.0);
|
||||
}
|
@ -14,10 +14,13 @@
|
||||
#include "SOIL/stb_image_aug.h"
|
||||
|
||||
GLuint skyboxProgram, skyboxBuffer;
|
||||
GLuint cubeProgram, cubeBuffer;
|
||||
GLuint programColor;
|
||||
GLuint programTexture;
|
||||
GLuint textureSubmarine;
|
||||
GLuint textureBubble;
|
||||
unsigned int cubemapTexture, skyboxVAO;
|
||||
unsigned int cubeVAO, cubeVBO;
|
||||
|
||||
float old_x, old_y = -1;
|
||||
glm::vec3 cursorDiff;
|
||||
@ -33,6 +36,7 @@ glm::mat4 cameraMatrix, perspectiveMatrix;
|
||||
|
||||
Core::Shader_Loader shaderLoader;
|
||||
Core::RenderContext submarineContext;
|
||||
Core::RenderContext bubbleContext;
|
||||
|
||||
std::string skyboxTextures[6] = {
|
||||
"models/skybox/right.jpg",
|
||||
@ -46,6 +50,51 @@ std::string skyboxTextures[6] = {
|
||||
float skyboxVerticeParameter = 20.0f;
|
||||
float skyboxBoundary = 19.5f;
|
||||
|
||||
float cubeVertices[] = {
|
||||
// positions // normals
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
|
||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
|
||||
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
|
||||
|
||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
||||
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
||||
0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
||||
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
||||
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
||||
-0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
||||
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f
|
||||
};
|
||||
|
||||
float skyboxVertices[] = {
|
||||
-skyboxVerticeParameter, skyboxVerticeParameter, -skyboxVerticeParameter,
|
||||
-skyboxVerticeParameter, -skyboxVerticeParameter, -skyboxVerticeParameter,
|
||||
@ -212,12 +261,22 @@ void renderScene()
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
glUseProgram(skyboxProgram);
|
||||
glBindVertexArray(0);
|
||||
glBindVertexArray(cubeVAO);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
glBindVertexArray(0);
|
||||
|
||||
glm::mat4 submarineInitialTransformation = glm::translate(glm::vec3(-1, 0, -0.5)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.25f));
|
||||
glm::mat4 submarineModelMatrix = glm::translate(cameraPos + cameraDir) * glm::mat4_cast(glm::inverse(rotation)) * submarineInitialTransformation;
|
||||
//drawObjectColor(fishContext, fishModelMatrix, glm::vec3(0.6f));
|
||||
drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine);
|
||||
|
||||
glm::mat4 bubbleInitialTransformation = glm::translate(glm::vec3(1, 0, -0.5)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.005f));
|
||||
drawObjectTexture(bubbleContext, bubbleInitialTransformation, textureBubble);
|
||||
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
@ -284,16 +343,34 @@ void initSkybox()
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||
}
|
||||
|
||||
void initCube()
|
||||
{
|
||||
glGenVertexArrays(1, &cubeVAO);
|
||||
glGenBuffers(1, &cubeVBO);
|
||||
glBindVertexArray(cubeVAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVertices), &cubeVertices, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
programColor = shaderLoader.CreateProgram((char*) "shaders/shader_color.vert", (char*) "shaders/shader_color.frag");
|
||||
programTexture = shaderLoader.CreateProgram((char*) "shaders/shader_tex.vert", (char*) "shaders/shader_tex.frag");
|
||||
skyboxProgram = shaderLoader.CreateProgram((char *) "shaders/skybox.vert", (char *) "shaders/skybox.frag");
|
||||
cubeProgram = shaderLoader.CreateProgram((char*)"shaders/bubble.vert", (char*)"shaders/bubble.frag");
|
||||
cubemapTexture = loadCubemap();
|
||||
loadModelToContext("models/submarine.obj", submarineContext);
|
||||
textureSubmarine = Core::LoadTexture("textures/submarine.png");
|
||||
loadModelToContext("models/sphere.obj", bubbleContext);
|
||||
textureBubble = Core::LoadTexture("textures/fish.png");
|
||||
initCube();
|
||||
initSkybox();
|
||||
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
@ -309,6 +386,7 @@ void idle()
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
glutInit(&argc, argv);
|
||||
|
Loading…
Reference in New Issue
Block a user