added simple terrain
This commit is contained in:
parent
7d852ae1fb
commit
0f6005dd4d
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(513,5): warning MSB8028: Katalog pośredni (Debug\) zawiera pliki udostępnione z innego projektu (grk-cw6.vcxproj). Może to spowodować niepoprawne zachowanie podczas oczyszczania i ponownej kompilacji.
|
||||
main.cpp
|
||||
C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\cw 6\src\main.cpp(134,23): warning C4244: "=": konwersja z "int" do "float", możliwa utrata danych
|
||||
C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\cw 6\src\main.cpp(135,23): warning C4244: "=": konwersja z "int" do "float", możliwa utrata danych
|
||||
C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\cw 6\src\main.cpp(382,12): warning C4244: "argument": konwersja z "time_t" do "unsigned int", możliwa utrata danych
|
||||
C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\cw 6\src\main.cpp(137,23): warning C4244: "=": konwersja z "int" do "float", możliwa utrata danych
|
||||
C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\cw 6\src\main.cpp(138,23): warning C4244: "=": konwersja z "int" do "float", możliwa utrata danych
|
||||
C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\cw 6\src\main.cpp(431,12): warning C4244: "argument": konwersja z "time_t" do "unsigned int", możliwa utrata danych
|
||||
Camera.obj : warning LNK4075: zignorowano opcję „/EDITANDCONTINUE” z powodu określenia opcji „/INCREMENTAL:NO”
|
||||
grk-cw6.vcxproj -> C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\Debug\Projekt.exe
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
@ -1,13 +1,17 @@
|
||||
#version 410 core
|
||||
|
||||
uniform vec3 objectColor;
|
||||
uniform vec4 objectColorTransparent;
|
||||
uniform vec3 lightDir;
|
||||
|
||||
in vec3 interpNormal;
|
||||
|
||||
out vec4 Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 normal = normalize(interpNormal);
|
||||
float diffuse = max(dot(normal, -lightDir), 0.0);
|
||||
gl_FragColor = vec4(objectColor * diffuse, 1.0);
|
||||
//gl_FragColor = vec4(objectColor * diffuse, 1.0);
|
||||
Color = objectColorTransparent * diffuse;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
|
||||
in vec3 texCoords;
|
||||
|
||||
uniform samplerCube skybox;
|
||||
|
@ -16,7 +16,7 @@
|
||||
float width = 600;
|
||||
float height = 600;
|
||||
|
||||
float moveTime = glutGet(GLUT_ELAPSED_TIME) / 100000000000.f;
|
||||
float moveTime = glutGet(GLUT_ELAPSED_TIME) / 10000000000.0f;
|
||||
|
||||
GLuint programColor;
|
||||
GLuint programTexture;
|
||||
@ -28,6 +28,8 @@ Core::RenderContext shipContext;
|
||||
Core::RenderContext fishContext;
|
||||
Core::RenderContext skyboxContext;
|
||||
Core::RenderContext bubbleContext;
|
||||
Core::RenderContext terrainContext;
|
||||
Core::RenderContext planeContext;
|
||||
|
||||
glm::vec3 cameraPos = glm::vec3(0, 0, 5);
|
||||
glm::vec3 cameraDir; // Wektor "do przodu" kamery
|
||||
@ -43,6 +45,7 @@ glm::quat rotation = glm::quat(1, 0, 0, 0);
|
||||
GLuint textureFish;
|
||||
GLuint textureBubble;
|
||||
GLuint textureShip;
|
||||
GLuint textureGround;
|
||||
|
||||
glm::vec3 fishLocation[20];
|
||||
bool fishChangeDirection[20];
|
||||
@ -51,7 +54,7 @@ glm::mat4 fishTransformation[20];
|
||||
int fishDirection[20];
|
||||
// 0 - prosto, 1 - prawo, 2 - do ty³u, 3 - lewo
|
||||
|
||||
glm::vec3 bubbleLocation[30];
|
||||
glm::vec3 bubbleLocation[100];
|
||||
|
||||
|
||||
|
||||
@ -197,6 +200,73 @@ void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuin
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void drawObjectTransparent(Core::RenderContext context, glm::mat4 modelMatrix, glm::vec4 color)
|
||||
{
|
||||
GLuint program = programColor;
|
||||
|
||||
glUseProgram(program);
|
||||
|
||||
glUniform4f(glGetUniformLocation(program, "objectColorTransparent"), color.x, color.y, color.z, color.a);
|
||||
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 drawObjectSkybox(Core::RenderContext context)
|
||||
{
|
||||
glUseProgram(programSkybox);
|
||||
|
||||
glUniform1i(glGetUniformLocation(programSkybox, "skybox"), 0);
|
||||
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
glm::mat4 view = glm::mat4(1.0f);
|
||||
glm::mat4 projection = glm::mat4(1.0f);
|
||||
// We make the mat4 into a mat3 and then a mat4 again in order to get rid of the last row and column
|
||||
// The last row and column affect the translation of the skybox (which we don't want to affect)
|
||||
view = glm::mat4(glm::mat3(glm::lookAt(cameraPos, cameraPos + cameraDir, glm::vec3(0, 1, 0))));
|
||||
projection = glm::perspective(glm::radians(45.0f), (float)width / height, 0.1f, 100.0f);
|
||||
glUniformMatrix4fv(glGetUniformLocation(programSkybox, "view"), 1, GL_FALSE, glm::value_ptr(view));
|
||||
glUniformMatrix4fv(glGetUniformLocation(programSkybox, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
|
||||
|
||||
// Draws the cubemap as the last object so we can save a bit of performance by discarding all fragments
|
||||
// where an object is present (a depth of 1.0f will always fail against any object's depth value)
|
||||
glBindVertexArray(skyboxVAO);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
|
||||
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
// Switch back to the normal depth function
|
||||
glDepthFunc(GL_LESS);
|
||||
}
|
||||
|
||||
void drawPlaneTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuint textureId)
|
||||
{
|
||||
|
||||
modelMatrix = glm::translate(modelMatrix, glm::vec3(-10.f, 0.f, 0.f));
|
||||
GLuint program = programTexture;
|
||||
|
||||
glUseProgram(program);
|
||||
|
||||
glUniform3f(glGetUniformLocation(program, "lightDir"), lightDir.x, lightDir.y, lightDir.z);
|
||||
Core::SetActiveTexture(textureId, "textureSampler", program, 0);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
glm::vec3 moveBubble(glm::vec3 location, int index)
|
||||
{
|
||||
location.y = location.y + moveTime * 4;
|
||||
@ -229,8 +299,8 @@ glm::mat4 moveFish(glm::vec3 location, int index)
|
||||
fishChangeDirection[index] = true;
|
||||
}
|
||||
else {
|
||||
location.z = location.z - moveTime * 5;
|
||||
fishRadianDirection[index] = 0.0f;
|
||||
location.z = location.z - moveTime * 10;
|
||||
fishRadianDirection[index] = 180.0f;
|
||||
}
|
||||
}
|
||||
else if (fishDirection[index] == 1)
|
||||
@ -252,7 +322,7 @@ glm::mat4 moveFish(glm::vec3 location, int index)
|
||||
}
|
||||
else {
|
||||
location.z = location.z - moveTime * 10;
|
||||
fishRadianDirection[index] = 180.0f;
|
||||
fishRadianDirection[index] = 0.0f;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -272,35 +342,6 @@ glm::mat4 moveFish(glm::vec3 location, int index)
|
||||
return fishTransformation[index];
|
||||
}
|
||||
|
||||
void drawObjectSkybox(Core::RenderContext context)
|
||||
{
|
||||
glUseProgram(programSkybox);
|
||||
|
||||
glUniform1i(glGetUniformLocation(programSkybox, "skybox"), 0);
|
||||
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
glm::mat4 view = glm::mat4(1.0f);
|
||||
glm::mat4 projection = glm::mat4(1.0f);
|
||||
// We make the mat4 into a mat3 and then a mat4 again in order to get rid of the last row and column
|
||||
// The last row and column affect the translation of the skybox (which we don't want to affect)
|
||||
view = glm::mat4(glm::mat3(glm::lookAt(cameraPos, cameraPos + cameraDir, glm::vec3(0, 1, 0))));
|
||||
projection = glm::perspective(glm::radians(45.0f), (float)width / height, 0.1f, 100.0f);
|
||||
glUniformMatrix4fv(glGetUniformLocation(programSkybox, "view"), 1, GL_FALSE, glm::value_ptr(view));
|
||||
glUniformMatrix4fv(glGetUniformLocation(programSkybox, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
|
||||
|
||||
// Draws the cubemap as the last object so we can save a bit of performance by discarding all fragments
|
||||
// where an object is present (a depth of 1.0f will always fail against any object's depth value)
|
||||
glBindVertexArray(skyboxVAO);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
|
||||
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
// Switch back to the normal depth function
|
||||
glDepthFunc(GL_LESS);
|
||||
}
|
||||
|
||||
void renderScene()
|
||||
{
|
||||
// Aktualizacja macierzy widoku i rzutowania
|
||||
@ -308,10 +349,10 @@ void renderScene()
|
||||
perspectiveMatrix = Core::createPerspectiveMatrix();
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClearColor(0.0f, 0.1f, 0.3f, 1.0f);
|
||||
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
// rysowanie statku
|
||||
glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0, 0, 0)) * glm::rotate(glm::radians(270.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.001f));
|
||||
glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0, 0, 0)) * glm::rotate(glm::radians(270.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0015f));
|
||||
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir) * glm::rotate(-cameraAngle, glm::vec3(0, 1, 0)) * shipInitialTransformation;
|
||||
drawObjectTexture(shipContext, shipModelMatrix, textureShip);
|
||||
|
||||
@ -323,15 +364,23 @@ void renderScene()
|
||||
drawObjectTexture(fishContext, moveFish(fishLocation[i], i), textureFish);
|
||||
}
|
||||
|
||||
// rysowanie b¹belków powietrza
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
drawObjectTexture(bubbleContext, glm::translate(moveBubble(bubbleLocation[i], i)) * glm::rotate(glm::radians(0.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.1f)), textureBubble);
|
||||
}
|
||||
// narysuj teren z pliku terenu
|
||||
drawObjectTexture(terrainContext, glm::translate(glm::vec3(0, -20, 0)) * glm::rotate(glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(1.5f)), textureGround);
|
||||
drawObjectTexture(terrainContext, glm::translate(glm::vec3(130, -20, 0)) * glm::rotate(glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(1.5f)), textureGround);
|
||||
drawObjectTexture(terrainContext, glm::translate(glm::vec3(-130, -20, 0)) * glm::rotate(glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(1.5f)), textureGround);
|
||||
|
||||
// narysuj p³ask¹ powierzchniê
|
||||
//drawPlaneTexture(planeContext, glm::rotate(glm::radians(120.f), glm::vec3(1.f, 1.f, 1.f)), textureGround);
|
||||
|
||||
// rysowanie skyboxa
|
||||
drawObjectSkybox(skyboxContext);
|
||||
|
||||
// rysowanie b¹belków powietrza
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
drawObjectTransparent(bubbleContext, glm::translate(moveBubble(bubbleLocation[i], i)) * glm::rotate(glm::radians(0.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.05f)), glm::vec4(1.f, 1.f, 1.f, 0.7f));
|
||||
}
|
||||
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
@ -357,7 +406,7 @@ void init()
|
||||
fishDirection[i] = rand() % 4 + 0;
|
||||
if (fishDirection[i] == 0)
|
||||
{
|
||||
fishRadianDirection[i] = 0.0f;
|
||||
fishRadianDirection[i] = 180.0f;
|
||||
}
|
||||
else if (fishDirection[i] == 1)
|
||||
{
|
||||
@ -365,7 +414,7 @@ void init()
|
||||
}
|
||||
else if (fishDirection[i] == 3)
|
||||
{
|
||||
fishRadianDirection[i] = 180.0f;
|
||||
fishRadianDirection[i] = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -374,7 +423,7 @@ void init()
|
||||
fishChangeDirection[i] = false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 30; i++)
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
bubbleLocation[i] = glm::ballRand(15.0);
|
||||
}
|
||||
@ -387,9 +436,12 @@ void init()
|
||||
loadModelToContext("models/submarine.obj", shipContext);
|
||||
loadModelToContext("models/TropicalFish01.obj", fishContext);
|
||||
loadModelToContext("models/sphere.obj", bubbleContext);
|
||||
loadModelToContext("models/seafloor.obj", terrainContext);
|
||||
loadModelToContext("models/plane.obj", planeContext);
|
||||
textureFish = Core::LoadTexture("textures/TropicalFish01.jpg");
|
||||
textureBubble = Core::LoadTexture("textures/bubble.png");
|
||||
textureShip = Core::LoadTexture("textures/txt-subm-1.jpg");
|
||||
textureGround = Core::LoadTexture("textures/terrain.jpg");
|
||||
|
||||
// SKYBOX
|
||||
// Create VAO, VBO, and EBO for the skybox
|
||||
@ -482,6 +534,10 @@ int main(int argc, char** argv)
|
||||
glutInitWindowSize(600, 600);
|
||||
glutCreateWindow("Projekt - Grafika komputerowa");
|
||||
|
||||
// dodanie przezroczystoœci obiektów
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
glewInit();
|
||||
|
||||
init();
|
||||
|
Loading…
Reference in New Issue
Block a user