ho3/Template/main.cpp

661 lines
21 KiB
C++
Raw Normal View History

2024-06-06 13:25:38 +00:00
#include "main.h"
float CONST_CAM_ALPHA_MOUSE_SENSITIVETY = 0.005f;
float CONST_CAM_PHI_MOUSE_SENSITIVETY = 0.005f;
float CONST_CAM_ZOOM_SENSITIVITY = 1.0f/120.0f;
cardinal CONST_CUBEMAP_UPDATE_INTERVAL = 5000;
void TMyApplication::DrawToCubemap()
{
Renderer->PushShader("Directlight");
Renderer->SwitchToCubemapBuffer("Skybox",0);
2024-06-08 22:09:17 +00:00
Renderer->SetGlPosXView(false, true);
2024-06-09 18:42:23 +00:00
//DrawCubemapDay();
DrawCubemapNight();
Renderer->PushShader("Directlight2");
2024-06-08 22:09:17 +00:00
Renderer->SetGlPosXView(true, true);
GameMap.DrawVBO();
2024-06-09 18:42:23 +00:00
Renderer->PopShader();
2024-06-08 20:24:26 +00:00
//glClearColor()
//glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
//glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
2024-06-06 13:25:38 +00:00
Renderer->SwitchToCubemapBuffer("Skybox",1);
2024-06-08 22:09:17 +00:00
Renderer->SetGlNegXView(false, true);
2024-06-09 18:42:23 +00:00
//DrawCubemapDay();
DrawCubemapNight();
Renderer->PushShader("Directlight2");
2024-06-08 22:09:17 +00:00
Renderer->SetGlNegXView(true, true);
2024-06-08 20:24:26 +00:00
//glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
//glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
2024-06-08 22:09:17 +00:00
GameMap.DrawVBO();
2024-06-09 18:42:23 +00:00
Renderer->PopShader();
2024-06-06 13:25:38 +00:00
Renderer->SwitchToCubemapBuffer("Skybox",2);
2024-06-08 22:09:17 +00:00
Renderer->SetGlPosYView(false, true);
2024-06-09 18:42:23 +00:00
//DrawCubemapDay();
DrawCubemapNight();
Renderer->PushShader("Directlight2");
2024-06-08 22:09:17 +00:00
Renderer->SetGlPosYView(true, true);
GameMap.DrawVBO();
2024-06-08 20:24:26 +00:00
//glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
//glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
2024-06-09 18:42:23 +00:00
Renderer->PopShader();
2024-06-06 13:25:38 +00:00
Renderer->SwitchToCubemapBuffer("Skybox",3);
2024-06-08 22:09:17 +00:00
Renderer->SetGlNegYView(false, true);
2024-06-09 18:42:23 +00:00
//DrawCubemapDay();
DrawCubemapNight();
Renderer->PushShader("Directlight2");
2024-06-08 22:09:17 +00:00
Renderer->SetGlNegYView(true, true);
2024-06-08 20:24:26 +00:00
//glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
//glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
2024-06-08 22:09:17 +00:00
GameMap.DrawVBO();
2024-06-09 18:42:23 +00:00
Renderer->PopShader();
2024-06-06 13:25:38 +00:00
Renderer->SwitchToCubemapBuffer("Skybox",4);
2024-06-08 22:09:17 +00:00
Renderer->SetGlPosZView(false, true);
2024-06-09 18:42:23 +00:00
//DrawCubemapDay();
DrawCubemapNight();
Renderer->PushShader("Directlight2");
2024-06-08 22:09:17 +00:00
Renderer->SetGlPosZView(true, true);
GameMap.DrawVBO();
2024-06-08 20:24:26 +00:00
//glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
//glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
2024-06-09 18:42:23 +00:00
Renderer->PopShader();
2024-06-06 13:25:38 +00:00
Renderer->SwitchToCubemapBuffer("Skybox",5);
2024-06-08 22:09:17 +00:00
Renderer->SetGlNegZView(false, true);
2024-06-09 18:42:23 +00:00
//DrawCubemapDay();
DrawCubemapNight();
Renderer->PushShader("Directlight2");
2024-06-08 22:09:17 +00:00
Renderer->SetGlNegZView(true, true);
2024-06-08 20:24:26 +00:00
//glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
//glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
2024-06-08 22:09:17 +00:00
GameMap.DrawVBO();
2024-06-09 18:42:23 +00:00
Renderer->PopShader();
2024-06-06 13:25:38 +00:00
Renderer->SwitchToScreen();
Renderer->PopShader();
}
void TMyApplication::DrawToShadowMap()
{
Renderer->PushShader("Lightview");
Renderer->BeginDrawToDepthBufferGlobal(std::string("ShadowBufferGlobal"));
DrawSceneWithoutWater();
Renderer->BeginDrawToDepthBufferLocal(std::string("ShadowBufferLocal"));
DrawSceneWithoutWater();
Renderer->EndDrawToDepthBuffer();
Renderer->PopShader();
}
void TMyApplication::DrawSceneWithoutWater()
{
2024-06-08 22:09:17 +00:00
Renderer->SetGLCamAngleView();
2024-06-09 18:42:23 +00:00
//DrawCubemapDay();
DrawCubemapNight();
Renderer->PushShader("Directlight2");
2024-06-08 22:09:17 +00:00
Renderer->SetGLCamView();
2024-06-06 13:25:38 +00:00
GameMap.DrawVBO();
2024-06-09 18:42:23 +00:00
Renderer->PopShader();
2024-06-06 13:25:38 +00:00
}
void TMyApplication::DrawWaterSurface()
{
Renderer->PushShader("Water");
RenderUniform1f("WaterTimer", WaterTimer);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, ResourceManager->TexList["normalmap.bmp"]);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, ResourceManager->FrameManager.GetFrameTexture("Skybox"));
2024-06-08 20:24:26 +00:00
RenderUniformMatrix3fv(CONST_STRING_MODELROTATEMATRIX_UNIFORM, false, (float*)IdentityMatrix.m);
RenderUniform3fv(CONST_STRING_MODELTRANSLATEVECTOR_UNIFORM, (float*)ZeroVec3.v);
EnableVertexAttribArray("vPosition");
EnableVertexAttribArray("vTexCoord");
//Renderer->DrawTriangleList(TriangleList);
DrawVertexDataStruct(waterVertexDataStruct);
DisableVertexAttribArray("vPosition");
DisableVertexAttribArray("vTexCoord");
2024-06-06 13:25:38 +00:00
Renderer->PopShader();
}
2024-06-08 17:55:56 +00:00
void TMyApplication::DrawCubemap()
{
Renderer->PushShader("Env");
2024-06-08 20:24:26 +00:00
//Renderer->SetGLCamAngleView();
2024-06-08 17:55:56 +00:00
Renderer->SetGLCamAngleView();
//Renderer->LoadIdentity();
RenderUniformMatrix3fv(CONST_STRING_MODELROTATEMATRIX_UNIFORM, false, (float*)IdentityMatrix.m);
RenderUniform3fv(CONST_STRING_MODELTRANSLATEVECTOR_UNIFORM, (float*)ZeroVec3.v);
glBindTexture(GL_TEXTURE_CUBE_MAP, ResourceManager->FrameManager.GetFrameTexture("Skybox"));
//glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
EnableVertexAttribArray("vPosition");
DrawVertexDataStruct(cubemapVertexDataStruct);
DisableVertexAttribArray("vPosition");
Renderer->PopShader();
}
2024-06-08 22:09:17 +00:00
void TMyApplication::DrawCubemapDay()
{
Renderer->PushShader("EnvReverse");
//Renderer->SetGLCamAngleView();
//Renderer->SetGLCamAngleView();
//Renderer->LoadIdentity();
RenderUniformMatrix3fv(CONST_STRING_MODELROTATEMATRIX_UNIFORM, false, (float*)IdentityMatrix.m);
RenderUniform3fv(CONST_STRING_MODELTRANSLATEVECTOR_UNIFORM, (float*)ZeroVec3.v);
//glBindTexture(GL_TEXTURE_CUBE_MAP, ResourceManager->FrameManager.GetFrameTexture("Skybox"));
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTextureDay);
EnableVertexAttribArray("vPosition");
DrawVertexDataStruct(cubemapVertexDataStruct);
DisableVertexAttribArray("vPosition");
glClear(GL_DEPTH_BUFFER_BIT);
Renderer->PopShader();
}
2024-06-09 18:42:23 +00:00
void TMyApplication::DrawCubemapNight()
{
Renderer->PushShader("EnvReverseNight");
//Renderer->SetGLCamAngleView();
//Renderer->SetGLCamAngleView();
//Renderer->LoadIdentity();
RenderUniformMatrix3fv(CONST_STRING_MODELROTATEMATRIX_UNIFORM, false, (float*)IdentityMatrix.m);
RenderUniform3fv(CONST_STRING_MODELTRANSLATEVECTOR_UNIFORM, (float*)ZeroVec3.v);
//glBindTexture(GL_TEXTURE_CUBE_MAP, ResourceManager->FrameManager.GetFrameTexture("Skybox"));
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTextureNight);
EnableVertexAttribArray("vPosition");
DrawVertexDataStruct(cubemapVertexDataStruct);
DisableVertexAttribArray("vPosition");
glClear(GL_DEPTH_BUFFER_BIT);
Renderer->PopShader();
}
2024-06-09 07:38:02 +00:00
void TMyApplication::DrawFrameFullScreen()
{
}
2024-06-06 13:25:38 +00:00
//What to do on init
void TMyApplication::InnerInit()
{
ResourceManager->PathToResources = "C:\\Work\\OldProjects\\ho3\\resources\\";
2024-06-08 17:55:56 +00:00
glDisable(GL_CULL_FACE);
2024-06-06 13:25:38 +00:00
ResourceManager->ShaderManager.AddShader("GUI", "shaders/gui_transparent.vertex", "shaders/gui_transparent.fragment");
ResourceManager->ShaderManager.AddShader("Parallax", "shaders/directlight_parallax_shadow.vertex", "shaders/directlight_parallax_shadow.fragment");
ResourceManager->ShaderManager.AddShader("Directlight", "shaders/directlight.vertex", "shaders/directlight.fragment");
2024-06-09 18:42:23 +00:00
ResourceManager->ShaderManager.AddShader("Directlight2", "shaders/directlight2.vertex", "shaders/directlight2.fragment");
2024-06-10 19:17:41 +00:00
ResourceManager->ShaderManager.AddShader("Directlight3", "shaders/directlight3.vertex", "shaders/directlight3.fragment");
2024-06-06 13:25:38 +00:00
ResourceManager->ShaderManager.AddShader("Env", "shaders/env.vertex", "shaders/env.fragment");
2024-06-08 22:09:17 +00:00
ResourceManager->ShaderManager.AddShader("EnvReverse", "shaders/env_reverse.vertex", "shaders/env_reverse.fragment");
2024-06-09 18:42:23 +00:00
ResourceManager->ShaderManager.AddShader("EnvReverseNight", "shaders/env_reverse_night.vertex", "shaders/env_reverse_night.fragment");
2024-06-06 13:25:38 +00:00
ResourceManager->ShaderManager.AddShader("Water", "shaders/water.vertex", "shaders/water.fragment");
ResourceManager->ShaderManager.AddShader("Frame", "shaders/frame.vertex", "shaders/frame.fragment");
ResourceManager->ShaderManager.AddShader("Lightview", "shaders/lightview.vertex", "shaders/lightview.fragment");
ResourceManager->ShaderManager.AddShader("Simple3D", "shaders/simple3d.vertex", "shaders/simple3d.fragment");
Renderer->SetBackgroundShader("Env");
Renderer->PushShader("Parallax");
//Renderer->PushShader("GUI");
ResourceManager->ModelManager.AddLiteModel("models/bt_box_yellow.lm1");
2024-06-08 22:38:37 +00:00
ResourceManager->ModelManager.AddLiteModel("models/bt_box_red.lm1");
ResourceManager->ModelManager.AddLiteModel("models/bt_box_blue.lm1");
2024-06-06 13:25:38 +00:00
ResourceManager->ModelManager.AddLiteModel("models/bt_cone.lm1");
ResourceManager->ModelManager.AddLiteModel("models/girl.lm1");
ResourceManager->ModelAnimManager.AddAnimationToModel("girl.lm1","models/girl.bn2");
ResourceManager->ModelAnimManager["girl.lm1"]->LoadAnimSequenceFromFileAn1("models/girl.an1");
ResourceManager->ModelManager.AddLiteModel("models/bonemodel.lm1");
ResourceManager->ModelAnimManager.AddAnimationToModel("bonemodel.lm1","models/bonemodel.bn2");
ResourceManager->ModelAnimManager["bonemodel.lm1"]->LoadAnimSequenceFromFileAn1("models/bonemodel.an1");
GameMap.LoadMap();
Renderer->SetLandToCalcCollision(GameMap.GetLand());
Renderer->MoveDist(15.0f);
Renderer->MovePhi(pi/6);
float len = 50.0f;
//ResourceManager->LightManager.SetLightPos(0, vec4(-len * cos(pi/4), len * sin(pi/4), 0.0f, 0.0f));
2024-06-08 22:09:17 +00:00
ResourceManager->FrameManager.AddCubemapBuffer("Skybox",512,512);
2024-06-06 13:25:38 +00:00
Renderer->SetBackgroundCubemap(ResourceManager->FrameManager.GetFrameTexture("Skybox"));
ResourceManager->TexList.AddTexture("../resources/normalmap.bmp");
2024-06-08 17:55:56 +00:00
std::array<std::string, 6> cubemapTextureStr = {
2024-06-08 22:09:17 +00:00
"../resources/sky/posx.bmp", "../resources/sky/negx.bmp", "../resources/sky/posy.bmp", "../resources/sky/negy.bmp", "../resources/sky/posz.bmp", "../resources/sky/negz.bmp"
2024-06-08 17:55:56 +00:00
};
cubemapTexture = ResourceManager->TexList.AddCubemapTexture(cubemapTextureStr);
2024-06-08 22:09:17 +00:00
//!!!! for some reason up and down switched
std::array<std::string, 6> cubemapTextureDayStr = {
"../resources/sky/yavin_rt.bmp", "../resources/sky/yavin_lf.bmp", "../resources/sky/yavin_dn.bmp", "../resources/sky/yavin_up.bmp", "../resources/sky/yavin_bk.bmp", "../resources/sky/yavin_ft.bmp"
};
cubemapTextureDay = ResourceManager->TexList.AddCubemapTexture(cubemapTextureDayStr);
std::array<std::string, 6> cubemapTextureNightStr = {
"../resources/sky/space_rt.bmp", "../resources/sky/space_lf.bmp", "../resources/sky/space_up.bmp", "../resources/sky/space_dn.bmp", "../resources/sky/space_bk.bmp", "../resources/sky/space_ft.bmp"
};
cubemapTextureNight = ResourceManager->TexList.AddCubemapTexture(cubemapTextureNightStr);
2024-06-08 17:55:56 +00:00
//."posx.bmp","negx.bmp","posy.bmp","negy.bmp","posz.bmp","negz.bmp"
2024-06-06 13:25:38 +00:00
ResourceManager->FrameManager.AddFrameRenderBuffer("ScreenBlur", 512, 512);
ResourceManager->FrameManager.AddDepthBuffer("ShadowBufferGlobal", 512, 512);
ResourceManager->FrameManager.AddDepthBuffer("ShadowBufferLocal", 1024, 1024);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, ResourceManager->FrameManager.GetFrameTexture("ShadowBufferGlobal"));
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, ResourceManager->FrameManager.GetFrameTexture("ShadowBufferLocal"));
glActiveTexture(GL_TEXTURE0);
glClearColor(0.2f, 0.5f, 1.0f, 1.0f);
//Renderer->SetShadowClampValue(0.3f);
2024-06-08 17:55:56 +00:00
//Renderer->SetShadowClampValue(0.0f);
Renderer->SetFogBeginDistance(15.f);
Renderer->SetFogEndDistance(30.f);
// +x
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, 10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, 10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, 10.0f });
// -x
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, 10.0f });
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, 10.0f });
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, 10.0f });
// +y
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, 10.0f });
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, 10.0f });
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, 10.0f });
// -y
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, 10.0f });
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, 10.0f });
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, 10.0f });
// +z
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, 10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, 10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, 10.0f });
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, 10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, 10.0f });
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, 10.0f });
2024-06-06 13:25:38 +00:00
2024-06-08 17:55:56 +00:00
// -z
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, -10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, -10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ 10.0f, 10.0f, -10.0f });
cubemapVertexDataStruct.PositionData.push_back({ -10.0f, 10.0f, -10.0f });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
cubemapVertexDataStruct.RefreshVBO();
2024-06-08 20:24:26 +00:00
/*
glBegin(GL_POLYGON);
glTexCoord2f(2, 2);
glVertex3f(20, 0, 20);
glTexCoord2f(2, 0);
glVertex3f(20, 0, -20);
glTexCoord2f(0, 0);
glVertex3f(-20, 0, -20);
glTexCoord2f(0, 2);
glVertex3f(-20, 0, 20);
glEnd();*/
waterVertexDataStruct.PositionData.push_back({ -20, 0, -20 });
waterVertexDataStruct.PositionData.push_back({ 20, 0, -20 });
waterVertexDataStruct.PositionData.push_back({ 20, 0, 20 });
waterVertexDataStruct.PositionData.push_back({ -20, 0, -20 });
waterVertexDataStruct.PositionData.push_back({ 20, 0, 20 });
waterVertexDataStruct.PositionData.push_back({ -20, 0, 20 });
waterVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
waterVertexDataStruct.TexCoordData.push_back({ 2.0, 0.0 });
waterVertexDataStruct.TexCoordData.push_back({ 2.0, 2.0 });
waterVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
waterVertexDataStruct.TexCoordData.push_back({ 2.0, 2.0 });
waterVertexDataStruct.TexCoordData.push_back({ 0.0, 2.0 });
waterVertexDataStruct.RefreshVBO();
2024-06-09 07:38:02 +00:00
frameVertexDataStruct.PositionData.push_back({ 0, 0, 0 });
frameVertexDataStruct.PositionData.push_back({ 800, 0, 0});
frameVertexDataStruct.PositionData.push_back({800, 600, 0 });
frameVertexDataStruct.PositionData.push_back({ 0, 0, 0 });
frameVertexDataStruct.PositionData.push_back({ 800, 600, 0 });
frameVertexDataStruct.PositionData.push_back({ 0, 600, 0 });
frameVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
frameVertexDataStruct.TexCoordData.push_back({ 1.0, 0.0 });
frameVertexDataStruct.TexCoordData.push_back({ 1.0, 1.0 });
frameVertexDataStruct.TexCoordData.push_back({ 0.0, 0.0 });
frameVertexDataStruct.TexCoordData.push_back({ 1.0, 1.0 });
frameVertexDataStruct.TexCoordData.push_back({ 0.0, 1.0 });
frameVertexDataStruct.RefreshVBO();
2024-06-06 13:25:38 +00:00
}
//What to do on deinit
void TMyApplication::InnerDeinit()
{
GameMap.FreeMap();
ResourceManager->FrameManager.DeleteFrameRenderBuffer("Skybox");
}
//What to do on draw
void TMyApplication::InnerDraw()
{
Renderer->SwitchToScreen();
2024-06-08 17:55:56 +00:00
glClearColor(0.2f, 0.55f, 1.0f, 1.0f);
2024-06-06 13:25:38 +00:00
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
2024-06-08 17:55:56 +00:00
Renderer->PushShader("Directlight");
2024-06-08 22:09:17 +00:00
//DrawCubemapDay();
2024-06-08 17:55:56 +00:00
DrawToCubemap();
2024-06-09 07:38:02 +00:00
Renderer->SwitchToFrameBuffer(std::string("ScreenBlur"));
2024-06-08 20:24:26 +00:00
2024-06-08 22:09:17 +00:00
DrawSceneWithoutWater();
2024-06-08 20:24:26 +00:00
2024-06-08 17:55:56 +00:00
Renderer->PopShader();
2024-06-08 20:24:26 +00:00
2024-06-08 22:09:17 +00:00
DrawWaterSurface();
2024-06-08 17:55:56 +00:00
2024-06-09 07:38:02 +00:00
Renderer->SwitchToScreen();
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
Renderer->PushShader("Frame");
Renderer->PushProjectionMatrix(800, 600);
Renderer->LoadIdentity();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, ResourceManager->FrameManager.GetFrameTexture("ScreenBlur"));
RenderUniformMatrix3fv(CONST_STRING_MODELROTATEMATRIX_UNIFORM, false, (float*)IdentityMatrix.m);
RenderUniform3fv(CONST_STRING_MODELTRANSLATEVECTOR_UNIFORM, (float*)ZeroVec3.v);
EnableVertexAttribArray("vPosition");
EnableVertexAttribArray("vTexCoord");
DrawVertexDataStruct(frameVertexDataStruct);
DisableVertexAttribArray("vPosition");
DisableVertexAttribArray("vTexCoord");
Renderer->PopProjectionMatrix();
Renderer->PopShader();
2024-06-08 17:55:56 +00:00
/*
Renderer->PushShader("Directlight");
2024-06-06 13:25:38 +00:00
DrawSceneWithoutWater();
Renderer->PopShader();
2024-06-08 17:55:56 +00:00
*/
//DrawToCubemap();
2024-06-06 13:25:38 +00:00
/*
DrawToCubemap();
DrawToShadowMap();
Renderer->SwitchToFrameBuffer(std::string("ScreenBlur"));
DrawSceneWithoutWater();
DrawWaterSurface();
Renderer->SwitchToScreen();
Renderer->PushShader("Frame");
Renderer->DrawFrameFullScreen(std::string("ScreenBlur"));
Renderer->PopShader();*/
/*
Renderer->SwitchToFrameBuffer(std::string("ScreenBlur"));
Renderer->PushShader("GUI");
DrawSceneWithoutWater();
Renderer->PopShader();
Renderer->SwitchToScreen();
Renderer->PushShader("Frame");
Renderer->DrawFrameFullScreen(std::string("ScreenBlur"));
Renderer->PopShader();*/
}
//What to do on update. timer means how many ms passed since last update
void TMyApplication::InnerUpdate(cardinal timer)
{
WaterTimer += 0.001f * timer;
GameMap.Update(timer);
}
void TMyApplication::UpdateQuick()
{
if (GetKeyState(VK_UP) >> 15)
{
Renderer->MoveForward();
}
if (GetKeyState(VK_DOWN) >> 15)
{
Renderer->MoveBackward();
}
if (GetKeyState(VK_LEFT) >> 15)
{
Renderer->MoveLeft();
}
if (GetKeyState(VK_RIGHT) >> 15)
{
Renderer->MoveRight();
}
}
void TMyApplication::OnMouseMove(TMouseState& mouseState)
{
if (MouseRightButtonPressed)
{
int dx = mouseState.X - MouseX0;
int dy = mouseState.Y - MouseY0;
MouseX0 = mouseState.X;
MouseY0 = mouseState.Y;
Renderer->MoveAlpha(dx * CONST_CAM_ALPHA_MOUSE_SENSITIVETY);
Renderer->MovePhi(dy * CONST_CAM_PHI_MOUSE_SENSITIVETY);
}
}
void TMyApplication::OnMouseDown(TMouseState& mouseState)
{
if (mouseState.RightButtonPressed)
{
MouseRightButtonPressed = true;
MouseX0 = mouseState.X;
MouseY0 = mouseState.Y;
}
if (mouseState.LeftButtonPressed)
{
MouseLeftButtonPressed = true;
2024-06-08 17:55:56 +00:00
view += 1;
if (view == 7)
{
view = 0;
}
2024-06-06 13:25:38 +00:00
}
}
void TMyApplication::OnMouseUp(TMouseState& mouseState)
{
MouseRightButtonPressed = false;
if (MouseLeftButtonPressed)
{
MouseLeftButtonPressed = false;
GameMap.PlayerClicked(mouseState.X, mouseState.Y);
}
}
void TMyApplication::OnMouseWheel(short int delta)
{
Renderer->MoveDist(-CONST_CAM_ZOOM_SENSITIVITY * delta);
}
int APIENTRY WinMain(HINSTANCE hCurrentInst, HINSTANCE hPreviousInst,
LPSTR lpszCmdLine, int nCmdShow)
{
//Create application
TMyApplication Application;
//Start application
return MainLoop(Application);
}