diff --git a/.vs/grk-cw/v16/.suo b/.vs/grk-cw/v16/.suo index e464372..cbde71f 100644 Binary files a/.vs/grk-cw/v16/.suo and b/.vs/grk-cw/v16/.suo differ diff --git a/.vs/grk-cw/v16/Browse.VC.db b/.vs/grk-cw/v16/Browse.VC.db index 8545e49..4447c39 100644 Binary files a/.vs/grk-cw/v16/Browse.VC.db and b/.vs/grk-cw/v16/Browse.VC.db differ diff --git a/Debug/grk-cw6.exe b/Debug/grk-cw6.exe index 71e7818..1e4b487 100644 Binary files a/Debug/grk-cw6.exe and b/Debug/grk-cw6.exe differ diff --git a/Debug/grk-cw6.pdb b/Debug/grk-cw6.pdb index d9f7acc..9acf377 100644 Binary files a/Debug/grk-cw6.pdb and b/Debug/grk-cw6.pdb differ diff --git a/Debug/grk-cw8.exe b/Debug/grk-cw8.exe index 49671d5..5d7c889 100644 Binary files a/Debug/grk-cw8.exe and b/Debug/grk-cw8.exe differ diff --git a/Debug/grk-cw8.pdb b/Debug/grk-cw8.pdb index 4786951..54ac73d 100644 Binary files a/Debug/grk-cw8.pdb and b/Debug/grk-cw8.pdb differ diff --git a/cw 6/.vs/grk-cw6/v16/.suo b/cw 6/.vs/grk-cw6/v16/.suo index 0346954..05fd2dc 100644 Binary files a/cw 6/.vs/grk-cw6/v16/.suo and b/cw 6/.vs/grk-cw6/v16/.suo differ diff --git a/cw 6/.vs/grk-cw6/v16/Browse.VC.db b/cw 6/.vs/grk-cw6/v16/Browse.VC.db index 8e759db..1e34e72 100644 Binary files a/cw 6/.vs/grk-cw6/v16/Browse.VC.db and b/cw 6/.vs/grk-cw6/v16/Browse.VC.db differ diff --git a/cw 6/Debug/Camera.obj b/cw 6/Debug/Camera.obj index be16bf0..978d77c 100644 Binary files a/cw 6/Debug/Camera.obj and b/cw 6/Debug/Camera.obj differ diff --git a/cw 6/Debug/Render_Utils.obj b/cw 6/Debug/Render_Utils.obj index c920ca0..8daafc4 100644 Binary files a/cw 6/Debug/Render_Utils.obj and b/cw 6/Debug/Render_Utils.obj differ diff --git a/cw 6/Debug/Shader_Loader.obj b/cw 6/Debug/Shader_Loader.obj index 252e33a..119e221 100644 Binary files a/cw 6/Debug/Shader_Loader.obj and b/cw 6/Debug/Shader_Loader.obj differ diff --git a/cw 6/Debug/Texture.obj b/cw 6/Debug/Texture.obj index 6aa3ca9..c72ec2f 100644 Binary files a/cw 6/Debug/Texture.obj and b/cw 6/Debug/Texture.obj differ diff --git a/cw 6/Debug/grk-cw6.log b/cw 6/Debug/grk-cw6.log index 86ac9ca..f34710c 100644 --- a/cw 6/Debug/grk-cw6.log +++ b/cw 6/Debug/grk-cw6.log @@ -1,6 +1,8 @@  main_6_1.cpp -C:\Users\Michal\source\repos\GRK\cw 6\src\main_6_1.cpp(96,23): warning C4244: "=": konwersja z "int" do "float", możliwa utrata danych -C:\Users\Michal\source\repos\GRK\cw 6\src\main_6_1.cpp(97,23): warning C4244: "=": konwersja z "int" do "float", możliwa utrata danych -C:\Users\Michal\source\repos\GRK\cw 6\src\main_6_1.cpp(349,12): warning C4244: "argument": konwersja z "time_t" do "unsigned int", możliwa utrata danych +C:\Users\Michal\source\repos\GRK\cw 6\src\main_6_1.cpp(132,23): warning C4244: "=": konwersja z "int" do "float", możliwa utrata danych +C:\Users\Michal\source\repos\GRK\cw 6\src\main_6_1.cpp(133,23): warning C4244: "=": konwersja z "int" do "float", możliwa utrata danych +C:\Users\Michal\source\repos\GRK\cw 6\src\main_6_1.cpp(326,33): warning C4244: "argument": konwersja z "double" do "GLfloat", możliwa utrata danych +C:\Users\Michal\source\repos\GRK\cw 6\src\main_6_1.cpp(327,44): warning C4244: "argument": konwersja z "double" do "GLfloat", możliwa utrata danych +C:\Users\Michal\source\repos\GRK\cw 6\src\main_6_1.cpp(601,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\Michal\source\repos\GRK\Debug\grk-cw6.exe diff --git a/cw 6/Debug/grk-cw6.tlog/CL.command.1.tlog b/cw 6/Debug/grk-cw6.tlog/CL.command.1.tlog index 0042a6d..e6cf639 100644 Binary files a/cw 6/Debug/grk-cw6.tlog/CL.command.1.tlog and b/cw 6/Debug/grk-cw6.tlog/CL.command.1.tlog differ diff --git a/cw 6/Debug/grk-cw6.tlog/CL.read.1.tlog b/cw 6/Debug/grk-cw6.tlog/CL.read.1.tlog index 2cb270e..c9d989d 100644 Binary files a/cw 6/Debug/grk-cw6.tlog/CL.read.1.tlog and b/cw 6/Debug/grk-cw6.tlog/CL.read.1.tlog differ diff --git a/cw 6/Debug/grk-cw6.tlog/CL.write.1.tlog b/cw 6/Debug/grk-cw6.tlog/CL.write.1.tlog index d4c3d55..38b1c86 100644 Binary files a/cw 6/Debug/grk-cw6.tlog/CL.write.1.tlog and b/cw 6/Debug/grk-cw6.tlog/CL.write.1.tlog differ diff --git a/cw 6/Debug/main_6_1.obj b/cw 6/Debug/main_6_1.obj index bf39774..46d9270 100644 Binary files a/cw 6/Debug/main_6_1.obj and b/cw 6/Debug/main_6_1.obj differ diff --git a/cw 6/Debug/vc142.idb b/cw 6/Debug/vc142.idb index 328ff55..9d0966f 100644 Binary files a/cw 6/Debug/vc142.idb and b/cw 6/Debug/vc142.idb differ diff --git a/cw 6/Debug/vc142.pdb b/cw 6/Debug/vc142.pdb index e7e3eed..a888f28 100644 Binary files a/cw 6/Debug/vc142.pdb and b/cw 6/Debug/vc142.pdb differ diff --git a/cw 6/src/main_6_1.cpp b/cw 6/src/main_6_1.cpp index ab91b96..9472825 100644 --- a/cw 6/src/main_6_1.cpp +++ b/cw 6/src/main_6_1.cpp @@ -12,6 +12,38 @@ #include "Texture.h" #include "SOIL/stb_image_aug.h" +#define M_PI 3.14159265358979323846 + +enum { + PASS_NORMAL, PASS_CAUSTIC +}; + + + +static GLboolean HaveTexObj = GL_FALSE; +static int reportSpeed = 0; +static int dinoDisplayList; +static GLfloat causticScale = 1.0; + +static GLfloat lightPosition[4]; +/* XXX Diffuse light color component > 1.0 to brighten caustics. */ + + +static int directionalLight = 1; +static int showCaustics = 1, causticMotion = 1; +static int useMipmaps = 1; +static int currentCaustic = 0; +static int causticIncrement = 1; + +static float lightAngle = 0.0, lightHeight = 20; +static GLfloat angle = -150; /* in degrees */ +static GLfloat angle2 = 30; /* in degrees */ + + + + + + GLuint programColor; GLuint programTexture; GLuint skyboxTexture; @@ -20,6 +52,7 @@ Core::Shader_Loader shaderLoader; Core::RenderContext shipContext; Core::RenderContext fishContext; +Core::RenderContext planeContext; glm::vec3 cameraPos = glm::vec3(0, 0, 0); glm::vec3 cameraDir; // Wektor "do przodu" kamery @@ -40,6 +73,9 @@ glm::quat rotation = glm::quat(1, 0, 0, 0); GLuint textureAsteroid; GLuint textureFish01; +GLuint groundTexture; + +obj::Model planeModel; int WIN_WIDTH = 1280; @@ -166,6 +202,25 @@ void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuin glUseProgram(0); } +void drawPlaneTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuint textureId) +{ + + modelMatrix = glm::translate(modelMatrix, glm::vec3(-20.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); +} //Zmienna z teksturami skyboxa std::vector faces = { @@ -258,8 +313,203 @@ float skyboxVertices[] = { skyboxSize, -skyboxSize, skyboxSize }; +void drawLightLocation() +{ + glPushMatrix(); + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glColor3f(1.0, 1.0, 0.0); + if (directionalLight) { + /* Draw an arrowhead. */ + glDisable(GL_CULL_FACE); + glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]); + glRotatef(lightAngle * -180.0 / M_PI, 0, 1, 0); + glRotatef(atan(lightHeight / 12) * 180.0 / M_PI, 0, 0, 1); + glBegin(GL_TRIANGLE_FAN); + glVertex3f(0, 0, 0); + glVertex3f(2, 1, 1); + glVertex3f(2, -1, 1); + glVertex3f(2, -1, -1); + glVertex3f(2, 1, -1); + glVertex3f(2, 1, 1); + glEnd(); + /* Draw a white line from light direction. */ + glColor3f(1.0, 1.0, 1.0); + glBegin(GL_LINES); + glVertex3f(0, 0, 0); + glVertex3f(5, 0, 0); + glEnd(); + glEnable(GL_CULL_FACE); + } + else { + /* Draw a yellow ball at the light source. */ + glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]); + glutSolidSphere(1.0, 5, 5); + } + glEnable(GL_TEXTURE_2D); + glEnable(GL_LIGHTING); + glPopMatrix(); +} + +void drawScene() +{ + glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0, 0, 0)); + // Scaling models + glm::vec3 shipScale = glm::vec3(0.01, 0.01, 0.01); + shipInitialTransformation = glm::scale(shipInitialTransformation, shipScale); + + shipInitialTransformation = shipInitialTransformation * glm::translate(glm::vec3(0, 0, 0)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.5f)); + glm::mat4 shipModelMatrix = glm::translate(vehiclePos + vehicleDir) * glm::rotate(-vehicleAngle, glm::vec3(0, 1, 0)) * shipInitialTransformation; + drawObjectColor(shipContext, shipModelMatrix, glm::vec3(0.6f)); + glm::mat4 modelMatrix = glm::translate(glm::vec3(0, 0, 0)); + // Scaling models + glm::vec3 scale = glm::vec3(0.001, 0.001, 0.001); + modelMatrix = glm::scale(modelMatrix, scale); + + drawObjectTexture(fishContext, modelMatrix, textureFish01); + + for (int i = 0; i < 10; i++) + { + + glm::mat4 modelMatrix = glm::translate(planetLocation[i]); + // Scaling models + glm::vec3 scale = glm::vec3(0.001, 0.001, 0.001); + modelMatrix = glm::scale(modelMatrix, scale); + + drawObjectTexture(fishContext, modelMatrix, textureFish01); + } + + drawPlaneTexture(planeContext, glm::rotate(glm::radians(90.f), glm::vec3(0.f, 0.f, 1.f)), groundTexture); + + glUseProgram(skyboxTexture); + glUniform1i(glGetUniformLocation(skyboxTexture, "skybox"), 0); + glm::mat4 transformation = perspectiveMatrix * glm::mat4(glm::mat3(cameraMatrix)); + glUniformMatrix4fv(glGetUniformLocation(skyboxTexture, "projectionView"), 1, GL_FALSE, (float*)&transformation); + //Przypisanie VAO i rysowanie skyboxa + glBindVertexArray(skyboxVAO); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture); + glDrawArrays(GL_TRIANGLES, 0, 36); + glBindVertexArray(0); + + glClearColor(0.5f, 0.5f, 0.5f, 1.0f); // We'll Clear To The Color Of The Fog ( Modified ) + float color[] = { 0.5f, 0.5f, 0.5f, 1.0f }; + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_EXP2); // Fog Mode + glFogfv(GL_FOG_COLOR, color); // Set Fog Color + glFogf(GL_FOG_DENSITY, 0.35f); // How Dense Will The Fog Be + 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); + + + +} + +void drawSceneLight(int pass) +{ + + + /* Set current color to "white" and disable lighting + to emulate OpenGL 1.1's GL_REPLACE texture environment. */ + glColor3f(1.0, 1.0, 1.0); + glDisable(GL_LIGHTING); + + /* Generate the S & T coordinates for the caustic textures + from the object coordinates. */ + + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + + + drawScene(); +} + + + + +void renderScene() +{ + + cameraMatrix = createCameraMatrix(); + perspectiveMatrix = Core::createPerspectiveMatrix(); + + + int startTime, endTime; + startTime = glutGet(GLUT_ELAPSED_TIME); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClearColor(0.0f, 0.1f, 0.3f, 1.0f); + + + + + lightPosition[0] = 12 * cos(lightAngle); + lightPosition[1] = lightHeight; + lightPosition[2] = 12 * sin(lightAngle); + if (directionalLight) { + lightPosition[3] = 0.0; + } + else { + lightPosition[3] = 1.0; + } + + + /* Draw the light location. */ + + glPushMatrix(); + + + glRotatef(angle2, 1.0, 0.0, 0.0); + glRotatef(angle, 0.0, 1.0, 0.0); + + /* Position the light again, after viewing rotation. */ + glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); + drawLightLocation(); + + drawSceneLight(PASS_NORMAL); + + if (showCaustics) { + /* Disable depth buffer update and exactly match depth + buffer values for slightly faster rendering. */ + glDepthMask(GL_FALSE); + glDepthFunc(GL_EQUAL); + + /* Multiply the source color (from the caustic luminance + texture) with the previous color from the normal pass. The + caustics are modulated into the scene. */ + glBlendFunc(GL_ZERO, GL_SRC_COLOR); + glEnable(GL_BLEND); + + drawSceneLight(PASS_CAUSTIC); + + /* Restore fragment operations to normal. */ + glDepthMask(GL_TRUE); + glDepthFunc(GL_LESS); + glDisable(GL_BLEND); + } + glPopMatrix(); + + glutSwapBuffers(); + + if (reportSpeed) { + glFinish(); + endTime = glutGet(GLUT_ELAPSED_TIME); + printf("Speed %.3g frames/sec (%d ms)\n", 1000.0 / (endTime - startTime), endTime - startTime); + fflush(stdout); + } + +} +/** void renderScene() { // Aktualizacja macierzy widoku i rzutowania @@ -297,6 +547,8 @@ void renderScene() drawObjectTexture(fishContext, modelMatrix, textureFish01); } + drawPlaneTexture(planeContext, glm::rotate(glm::radians(90.f), glm::vec3(0.f, 0.f, 1.f)), groundTexture); + glUseProgram(skyboxTexture); glUniform1i(glGetUniformLocation(skyboxTexture, "skybox"), 0); glm::mat4 transformation = perspectiveMatrix * glm::mat4(glm::mat3(cameraMatrix)); @@ -324,7 +576,7 @@ void renderScene() glutSwapBuffers(); -} +}**/ void loadModelToContext(std::string path, Core::RenderContext& context) { @@ -367,6 +619,9 @@ void init() loadModelToContext("models/TropicalFish01.3ds", fishContext); textureAsteroid = Core::LoadTexture("textures/asteroid.png"); textureFish01 = Core::LoadTexture("textures/TropicalFish01.jpg"); + + loadModelToContext("models/plane.obj", planeContext); + groundTexture = Core::LoadTexture("textures/sand.jpg"); } void shutdown() @@ -374,6 +629,8 @@ void shutdown() shaderLoader.DeleteProgram(programColor); shaderLoader.DeleteProgram(programTexture); shaderLoader.DeleteProgram(skyboxTexture); + + planeContext.initFromOBJ(planeModel); } void idle() diff --git a/cw 6/textures/floor.jpg b/cw 6/textures/floor.jpg new file mode 100644 index 0000000..bc1369e Binary files /dev/null and b/cw 6/textures/floor.jpg differ diff --git a/cw 6/textures/sand.jpg b/cw 6/textures/sand.jpg new file mode 100644 index 0000000..6c7f60c Binary files /dev/null and b/cw 6/textures/sand.jpg differ diff --git a/cw 8/Debug/grk-cw8.log b/cw 8/Debug/grk-cw8.log index ee0980f..032524f 100644 --- a/cw 8/Debug/grk-cw8.log +++ b/cw 8/Debug/grk-cw8.log @@ -1,9 +1,9 @@  main_8_1.cpp C:\Users\Michal\source\repos\GRK\cw 8\src\main_8_1.cpp(37,42): warning C4305: "argument": obcięcie z "double" do "float" -C:\Users\Michal\source\repos\GRK\cw 8\src\main_8_1.cpp(416,15): warning C4244: "argument": konwersja z "time_t" do "unsigned int", możliwa utrata danych +C:\Users\Michal\source\repos\GRK\cw 8\src\main_8_1.cpp(427,15): 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” PhysXExtensions_static_32.lib(ExtCpuWorkerThread.obj) : warning LNK4099: nie znaleziono pliku PDB „PhysXExtensions_static_32.pdb” z elementem „PhysXExtensions_static_32.lib(ExtCpuWorkerThread.obj)” lub w pozycji „C:\Users\Michal\source\repos\GRK\Debug\PhysXExtensions_static_32.pdb”; obiekt zostanie skonsolidowany bez informacji debugowania -PhysXExtensions_static_32.lib(ExtDefaultCpuDispatcher.obj) : warning LNK4099: nie znaleziono pliku PDB „” z elementem „PhysXExtensions_static_32.lib(ExtDefaultCpuDispatcher.obj)” lub w pozycji „”; obiekt zostanie skonsolidowany bez informacji debugowania +PhysXExtensions_static_32.lib(ExtDefaultCpuDispatcher.obj) : warning LNK4099: nie znaleziono pliku PDB „PhysXExtensions_static_32.pdb” z elementem „PhysXExtensions_static_32.lib(ExtDefaultCpuDispatcher.obj)” lub w pozycji „C:\Users\Michal\source\repos\GRK\Debug\PhysXExtensions_static_32.pdb”; obiekt zostanie skonsolidowany bez informacji debugowania PhysXExtensions_static_32.lib(ExtDefaultErrorCallback.obj) : warning LNK4099: nie znaleziono pliku PDB „PhysXExtensions_static_32.pdb” z elementem „PhysXExtensions_static_32.lib(ExtDefaultErrorCallback.obj)” lub w pozycji „C:\Users\Michal\source\repos\GRK\Debug\PhysXExtensions_static_32.pdb”; obiekt zostanie skonsolidowany bez informacji debugowania PhysXExtensions_static_32.lib(ExtDefaultSimulationFilterShader.obj) : warning LNK4099: nie znaleziono pliku PDB „PhysXExtensions_static_32.pdb” z elementem „PhysXExtensions_static_32.lib(ExtDefaultSimulationFilterShader.obj)” lub w pozycji „C:\Users\Michal\source\repos\GRK\Debug\PhysXExtensions_static_32.pdb”; obiekt zostanie skonsolidowany bez informacji debugowania grk-cw8.vcxproj -> C:\Users\Michal\source\repos\GRK\Debug\grk-cw8.exe diff --git a/cw 8/Debug/main_8_1.obj b/cw 8/Debug/main_8_1.obj index 5675ce3..0567248 100644 Binary files a/cw 8/Debug/main_8_1.obj and b/cw 8/Debug/main_8_1.obj differ diff --git a/cw 8/Debug/vc142.idb b/cw 8/Debug/vc142.idb index 3e0ff24..2d77d98 100644 Binary files a/cw 8/Debug/vc142.idb and b/cw 8/Debug/vc142.idb differ diff --git a/cw 8/Debug/vc142.pdb b/cw 8/Debug/vc142.pdb index 170e3d9..2fd4f62 100644 Binary files a/cw 8/Debug/vc142.pdb and b/cw 8/Debug/vc142.pdb differ diff --git a/cw 8/src/main_8_1.cpp b/cw 8/src/main_8_1.cpp index 586f150..99fc5f7 100644 --- a/cw 8/src/main_8_1.cpp +++ b/cw 8/src/main_8_1.cpp @@ -379,9 +379,12 @@ void renderScene() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0f, 0.1f, 0.3f, 1.0f); - + glDepthMask(GL_FALSE); + glDepthFunc(GL_EQUAL); - //drawObjectTexture(planeContext, glm::rotate(glm::radians(90.f), glm::vec3(0.f, 0.f, 1.f)), groundTexture); + + + drawObjectTexture(planeContext, glm::rotate(glm::radians(90.f), glm::vec3(0.f, 0.f, 1.f)), groundTexture); drawObjectTexture(boxContext, boxModelMatrix, boxTexture); // boxModelMatrix was updated in updateTransforms() glUseProgram(skyboxTexture); @@ -405,6 +408,14 @@ void renderScene() glFogf(GL_FOG_END, 5.0f); // Fog End Depth glEnable(GL_FOG); + + + + /* Restore fragment operations to normal. */ + glDepthMask(GL_TRUE); + glDepthFunc(GL_LESS); + glDisable(GL_BLEND); + glDepthFunc(GL_LESS); // set depth function back to default glUseProgram(0); @@ -433,7 +444,7 @@ void init() - + initRenderables(); initPhysicsScene();