Added ground and improved lighting

This commit is contained in:
s452662 2022-02-08 18:50:42 +01:00
parent c8ab95d27b
commit 7ba6ca9918
27 changed files with 279 additions and 9 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,8 @@
 main_6_1.cpp  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(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(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(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(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(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” 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 grk-cw6.vcxproj -> C:\Users\Michal\source\repos\GRK\Debug\grk-cw6.exe

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -12,6 +12,38 @@
#include "Texture.h" #include "Texture.h"
#include "SOIL/stb_image_aug.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 programColor;
GLuint programTexture; GLuint programTexture;
GLuint skyboxTexture; GLuint skyboxTexture;
@ -20,6 +52,7 @@ Core::Shader_Loader shaderLoader;
Core::RenderContext shipContext; Core::RenderContext shipContext;
Core::RenderContext fishContext; Core::RenderContext fishContext;
Core::RenderContext planeContext;
glm::vec3 cameraPos = glm::vec3(0, 0, 0); glm::vec3 cameraPos = glm::vec3(0, 0, 0);
glm::vec3 cameraDir; // Wektor "do przodu" kamery glm::vec3 cameraDir; // Wektor "do przodu" kamery
@ -40,6 +73,9 @@ glm::quat rotation = glm::quat(1, 0, 0, 0);
GLuint textureAsteroid; GLuint textureAsteroid;
GLuint textureFish01; GLuint textureFish01;
GLuint groundTexture;
obj::Model planeModel;
int WIN_WIDTH = 1280; int WIN_WIDTH = 1280;
@ -166,6 +202,25 @@ void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuin
glUseProgram(0); 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 //Zmienna z teksturami skyboxa
std::vector<std::string> faces = { std::vector<std::string> faces = {
@ -258,8 +313,203 @@ float skyboxVertices[] = {
skyboxSize, -skyboxSize, skyboxSize 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() void renderScene()
{ {
// Aktualizacja macierzy widoku i rzutowania // Aktualizacja macierzy widoku i rzutowania
@ -297,6 +547,8 @@ void renderScene()
drawObjectTexture(fishContext, modelMatrix, textureFish01); drawObjectTexture(fishContext, modelMatrix, textureFish01);
} }
drawPlaneTexture(planeContext, glm::rotate(glm::radians(90.f), glm::vec3(0.f, 0.f, 1.f)), groundTexture);
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));
@ -324,7 +576,7 @@ void renderScene()
glutSwapBuffers(); glutSwapBuffers();
} }**/
void loadModelToContext(std::string path, Core::RenderContext& context) void loadModelToContext(std::string path, Core::RenderContext& context)
{ {
@ -367,6 +619,9 @@ void init()
loadModelToContext("models/TropicalFish01.3ds", fishContext); loadModelToContext("models/TropicalFish01.3ds", fishContext);
textureAsteroid = Core::LoadTexture("textures/asteroid.png"); textureAsteroid = Core::LoadTexture("textures/asteroid.png");
textureFish01 = Core::LoadTexture("textures/TropicalFish01.jpg"); textureFish01 = Core::LoadTexture("textures/TropicalFish01.jpg");
loadModelToContext("models/plane.obj", planeContext);
groundTexture = Core::LoadTexture("textures/sand.jpg");
} }
void shutdown() void shutdown()
@ -374,6 +629,8 @@ void shutdown()
shaderLoader.DeleteProgram(programColor); shaderLoader.DeleteProgram(programColor);
shaderLoader.DeleteProgram(programTexture); shaderLoader.DeleteProgram(programTexture);
shaderLoader.DeleteProgram(skyboxTexture); shaderLoader.DeleteProgram(skyboxTexture);
planeContext.initFromOBJ(planeModel);
} }
void idle() void idle()

BIN
cw 6/textures/floor.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 KiB

BIN
cw 6/textures/sand.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 KiB

View File

@ -1,9 +1,9 @@
 main_8_1.cpp  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(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” 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(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(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 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 grk-cw8.vcxproj -> C:\Users\Michal\source\repos\GRK\Debug\grk-cw8.exe

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -379,9 +379,12 @@ void renderScene()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.1f, 0.3f, 1.0f); 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() drawObjectTexture(boxContext, boxModelMatrix, boxTexture); // boxModelMatrix was updated in updateTransforms()
glUseProgram(skyboxTexture); glUseProgram(skyboxTexture);
@ -405,6 +408,14 @@ void renderScene()
glFogf(GL_FOG_END, 5.0f); // Fog End Depth glFogf(GL_FOG_END, 5.0f); // Fog End Depth
glEnable(GL_FOG); 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 glDepthFunc(GL_LESS); // set depth function back to default
glUseProgram(0); glUseProgram(0);