From 38242fc60b1050fe5f8000fcd14f504c0077dd3d Mon Sep 17 00:00:00 2001 From: GolfOcean334 <130740013+GolfOcean334@users.noreply.github.com> Date: Fri, 5 Apr 2024 15:39:00 +0200 Subject: [PATCH] =?UTF-8?q?Light=20=C3=A0=20reparer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- enginecustom/applicationclass.cpp | 62 ++++++++++++++++++++++++++++++- enginecustom/applicationclass.h | 6 +++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index ed372d8..563a6e1 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -85,7 +85,25 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) m_Camera->Render(); m_Camera->GetViewMatrix(m_baseViewMatrix); - + // Create and initialize the specular map shader object. + m_SpecMapShader = new SpecMapShaderClass; + + result = m_SpecMapShader->Initialize(m_Direct3D->GetDevice(), hwnd); + if (!result) + { + MessageBox(hwnd, L"Could not initialize the specular map shader object.", L"Error", MB_OK); + return false; + } + + // Create and initialize the normal map shader object. + m_NormalMapShader = new NormalMapShaderClass; + + result = m_NormalMapShader->Initialize(m_Direct3D->GetDevice(), hwnd); + if (!result) + { + MessageBox(hwnd, L"Could not initialize the normal map shader object.", L"Error", MB_OK); + return false; + } // Create and initialize the font shader object. m_FontShader = new FontShaderClass; @@ -275,6 +293,25 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) m_Light->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f); m_Light->SetSpecularPower(16.0f); + // Set the number of lights we will use. + m_numLights = 4; + + // Create and initialize the light objects array. + m_Lights = new LightClass[m_numLights]; + + // Manually set the color and position of each light. + m_Lights[0].SetDiffuseColor(1.0f, 0.0f, 0.0f, 1.0f); // Red + m_Lights[0].SetPosition(-3.0f, 1.0f, 3.0f); + + m_Lights[1].SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f); // Green + m_Lights[1].SetPosition(3.0f, 1.0f, 3.0f); + + m_Lights[2].SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue + m_Lights[2].SetPosition(-3.0f, 1.0f, -3.0f); + + m_Lights[3].SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // White + m_Lights[3].SetPosition(3.0f, 1.0f, -3.0f); + // Create and initialize the normal map shader object. m_ShaderManager = new ShaderManagerClass; @@ -509,6 +546,13 @@ void ApplicationClass::Shutdown() m_Sprite = 0; } + // Release the light objects. + if (m_Lights) + { + delete[] m_Lights; + m_Lights = 0; + } + // Release the light object. if (m_Light) { @@ -524,6 +568,22 @@ void ApplicationClass::Shutdown() m_LightShader = 0; } + // Release the normal map shader object. + if (m_NormalMapShader) + { + m_NormalMapShader->Shutdown(); + delete m_NormalMapShader; + m_NormalMapShader = 0; + } + + // Release the specular map shader object. + if (m_SpecMapShader) + { + m_SpecMapShader->Shutdown(); + delete m_SpecMapShader; + m_SpecMapShader = 0; + } + // Release the model object. if (m_Model) { diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index f8f11a3..865123c 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -15,12 +15,15 @@ #include "alphamapshaderclass.h" #include "bitmapclass.h" #include "spriteclass.h" +#include "textureshaderclass.h" #include "timerclass.h" #include "fontshaderclass.h" #include "fontclass.h" #include "textclass.h" #include "fpsclass.h" #include "inputclass.h" +#include "normalmapshaderclass.h" +#include "specmapshaderclass.h" #include "shadermanagerclass.h" #include "modellistclass.h" #include "positionclass.h" @@ -65,6 +68,7 @@ private: CameraClass* m_Camera; LightShaderClass* m_LightShader; LightClass* m_Light; + LightClass* m_Lights; LightMapShaderClass* m_LightMapShader; MultiTextureShaderClass* m_MultiTextureShader; AlphaMapShaderClass* m_AlphaMapShader; @@ -82,6 +86,8 @@ private: FpsClass* m_Fps; TextClass* m_FpsString; int m_previousFps; + NormalMapShaderClass* m_NormalMapShader; + SpecMapShaderClass* m_SpecMapShader; ShaderManagerClass* m_ShaderManager; ModelListClass* m_ModelList; PositionClass* m_Position;