Merge branch 'main' into Shader-Manager

This commit is contained in:
GolfOcean334 2024-04-11 09:14:29 +02:00
commit 1104f7adbe
16 changed files with 686 additions and 386 deletions

View File

@ -0,0 +1,4 @@
int main()
{
return 0;
}

View File

@ -15,7 +15,7 @@ This **DirectX11** based engine uses **ImGui** with an abstraction layer to enab
**Par la solution + Debogueur :** **Par la solution + Debogueur :**
1. Télécharger la branche Main 1. Télécharger la Release Beta
2. Dezip le Zip 2. Dezip le Zip
3. Ouvrir le fichier en .sln 3. Ouvrir le fichier en .sln
4. Lancer le déboguage 4. Lancer le déboguage
@ -24,7 +24,7 @@ This **DirectX11** based engine uses **ImGui** with an abstraction layer to enab
**From solution + Debugger** **From solution + Debugger**
1. Download the Main branch 1. Download the Beta Release
2. Unzip the Zip file 2. Unzip the Zip file
3. Open the .sln file 3. Open the .sln file
4. Launch the debugger 4. Launch the debugger

82
enginecustom/Logger.h Normal file
View File

@ -0,0 +1,82 @@
#pragma once
#include <fstream>
#include <string>
#include <Windows.h>
#include <chrono>
#include <iomanip>
#include <sstream>
class Logger
{
public:
enum class LogLevel
{
Info,
Warning,
Error
};
Logger()
{
char* appdata = nullptr;
size_t len;
_dupenv_s(&appdata, &len, "APPDATA");
if (appdata == 0 ||appdata == nullptr)
{
m_appdataPath = "log.log";
}
else
{
m_appdataPath = appdata;
}
free(appdata);
std::string directoryPath = m_appdataPath + "\\Khaotic Engine";
CreateDirectoryA(directoryPath.c_str(), NULL);
m_logFilePath = directoryPath + "\\" + m_logFileName;
}
void Log(const std::string& message, const std::string& fileName, int lineNumber, LogLevel level = LogLevel::Info)
{
auto now = std::chrono::system_clock::now();
auto in_time_t = std::chrono::system_clock::to_time_t(now);
std::tm buf;
localtime_s(&buf, &in_time_t);
std::string levelStr;
switch (level)
{
case LogLevel::Error:
levelStr = "ERROR";
break;
case LogLevel::Warning:
levelStr = "WARNING";
break;
case LogLevel::Info:
levelStr = "INFO";
break;
}
std::stringstream ss;
ss << "[" << std::put_time(&buf, "%Y-%m-%d") << "] "
<< "[" << std::put_time(&buf, "%X") << "] "
<< "[" << levelStr << "] "
<< "[" << fileName << ":" << lineNumber << "] "
<< message;
std::ofstream file(m_logFilePath, std::ios::app);
if (file.is_open())
{
file << ss.str() << std::endl;
file.close();
}
}
private:
std::string m_filename;
std::string m_appdataPath;
std::string m_logFileName = "enginecustom.log";
std::string m_logFilePath;
};

View File

@ -5,6 +5,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline,
{ {
SystemClass* System; SystemClass* System;
bool result; bool result;
Logger logger;
// Create the system object. // Create the system object.
@ -14,6 +15,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline,
result = System->Initialize(); result = System->Initialize();
if (result) if (result)
{ {
logger.Log("System initialized", __FILE__, __LINE__);
System->Run(); System->Run();
} }

View File

@ -4,18 +4,18 @@
#include <windows.h> #include <windows.h>
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
SystemClass::SystemClass() SystemClass::SystemClass() : logger()
{ {
m_Input = 0; m_Input = 0;
m_Application = 0; m_Application = 0;
m_imguiManager = 0; m_imguiManager = 0;
} }
SystemClass::SystemClass(const SystemClass& other) SystemClass::SystemClass(const SystemClass& other)
{ {
} }
SystemClass::~SystemClass() SystemClass::~SystemClass()
{ {
} }
@ -25,48 +25,63 @@ bool SystemClass::Initialize()
int screenWidth, screenHeight; int screenWidth, screenHeight;
bool result; bool result;
logger.Log("Initializing system class", __FILE__, __LINE__);
// Initialize the width and height of the screen to zero before sending the variables into the function. try
screenWidth = 0;
screenHeight = 0;
m_initialWindowWidth = 0;
m_initialWindowHeight = 0;
m_isDirect3DInitialized = false;
// Initialize the windows api.
InitializeWindows(screenWidth, screenHeight);
// Create and initialize the input object. This object will be used to handle reading the keyboard input from the user.
m_Input = new InputClass;
result = m_Input->Initialize(m_hinstance, m_hwnd, screenWidth, screenHeight);
if (!result)
{ {
// Initialize the width and height of the screen to zero before sending the variables into the function.
screenWidth = 0;
screenHeight = 0;
m_initialWindowWidth = 0;
m_initialWindowHeight = 0;
m_isDirect3DInitialized = false;
// Initialize the windows api.
InitializeWindows(screenWidth, screenHeight);
// Create and initialize the input object. This object will be used to handle reading the keyboard input from the user.
m_Input = new InputClass;
result = m_Input->Initialize(m_hinstance, m_hwnd, screenWidth, screenHeight);
if (!result)
{
logger.Log("Failed to initialize input class", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the application class object. This object will handle rendering all the graphics for this application.
m_Application = new ApplicationClass;
result = m_Application->Initialize(screenWidth, screenHeight, m_hwnd);
if (!result)
{
return false;
}
m_isDirect3DInitialized = true;
// If we received a WM_SIZE message before Direct3D was initialized, resize the swap chain now
if (m_initialWindowWidth > 0 && m_initialWindowHeight > 0)
{
m_Application->GetDirect3D()->ResizeSwapChain(m_initialWindowWidth, m_initialWindowHeight);
}
// Initialize imgui
m_imguiManager = new imguiManager;
result = m_imguiManager->Initialize(m_hwnd, m_Application->GetDirect3D()->GetDevice(), m_Application->GetDirect3D()->GetDeviceContext());
if (!result)
{
return false;
}
}
catch (const std::exception& e)
{
logger.Log(std::string("Exception caught during initialization: ") + e.what(), __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
// Create and initialize the application class object. This object will handle rendering all the graphics for this application. logger.Log("System class initialized", __FILE__, __LINE__);
m_Application = new ApplicationClass;
result = m_Application->Initialize(screenWidth, screenHeight, m_hwnd);
if (!result)
{
return false;
}
m_isDirect3DInitialized = true;
// If we received a WM_SIZE message before Direct3D was initialized, resize the swap chain now
if (m_initialWindowWidth > 0 && m_initialWindowHeight > 0)
{
m_Application->GetDirect3D()->ResizeSwapChain(m_initialWindowWidth, m_initialWindowHeight);
}
// Initialize imgui
m_imguiManager = new imguiManager;
m_imguiManager->Initialize(m_hwnd, m_Application->GetDirect3D()->GetDevice(), m_Application->GetDirect3D()->GetDeviceContext());
return true; return true;
} }
@ -107,6 +122,8 @@ void SystemClass::Run()
MSG msg; MSG msg;
bool done, result; bool done, result;
logger.Log("Running the system", __FILE__, __LINE__);
// Initialize the message structure. // Initialize the message structure.
ZeroMemory(&msg, sizeof(MSG)); ZeroMemory(&msg, sizeof(MSG));
@ -124,6 +141,7 @@ void SystemClass::Run()
// If windows signals to end the application then exit out. // If windows signals to end the application then exit out.
if (msg.message == WM_QUIT) if (msg.message == WM_QUIT)
{ {
logger.Log("WM_QUIT message received", __FILE__, __LINE__);
done = true; done = true;
} }
else else
@ -132,6 +150,7 @@ void SystemClass::Run()
result = Frame(); result = Frame();
if (!result) if (!result)
{ {
logger.Log("Failed to process frame", __FILE__, __LINE__, Logger::LogLevel::Error);
done = true; done = true;
} }
} }
@ -149,6 +168,7 @@ bool SystemClass::Frame()
result = m_Input->Frame(); result = m_Input->Frame();
if (!result) if (!result)
{ {
logger.Log("Failed to process input frame", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -156,6 +176,7 @@ bool SystemClass::Frame()
result = m_Application->Frame(m_Input); result = m_Application->Frame(m_Input);
if (!result) if (!result)
{ {
logger.Log("Failed to process application frame", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -263,7 +284,7 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
DEVMODE dmScreenSettings; DEVMODE dmScreenSettings;
int posX, posY; int posX, posY;
logger.Log("Initializing windows", __FILE__, __LINE__);
// Get an external pointer to this object. // Get an external pointer to this object.
ApplicationHandle = this; ApplicationHandle = this;
@ -343,6 +364,8 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
void SystemClass::ShutdownWindows() void SystemClass::ShutdownWindows()
{ {
logger.Log("Shutting down the windows", __FILE__, __LINE__);
// Show the mouse cursor. // Show the mouse cursor.
ShowCursor(true); ShowCursor(true);

View File

@ -35,273 +35,291 @@ ApplicationClass::~ApplicationClass()
bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
{ {
char mouseString1[32], mouseString2[32], mouseString3[32];
char modelFilename[128], textureFilename1[128], textureFilename2[128], textureFilename3[128], textureFilename4[128], textureFilename5[128], textureFilename6[128], renderString[32];
char bitmapFilename[128];
char spriteFilename[128];
char fpsString[32];
bool result;
m_screenWidth = screenWidth; logger.Log("Initializing application class", __FILE__, __LINE__);
m_screenHeight = screenHeight;
// Create the Direct3D object. try
m_Direct3D = new D3DClass;
if (!m_Direct3D)
{
return false;
}
result = m_Direct3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR);
if (!result)
{
MessageBox(hwnd, L"Could not initialize Direct3D.", L"Error", MB_OK);
return false;
}
// Create the camera object.
m_Camera = new CameraClass;
if (!m_Camera)
{
return false;
}
// Set the initial position of the camera.
m_Camera->SetPosition(0.0f, 0.0f, -12.0f);
m_Camera->SetRotation(0.0f, 0.0f, 0.0f);
m_Camera->Render();
m_Camera->GetViewMatrix(m_baseViewMatrix);
// Create and initialize the font shader object.
m_FontShader = new FontShaderClass;
result = m_FontShader->Initialize(m_Direct3D->GetDevice(), hwnd);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the font shader object.", L"Error", MB_OK);
return false;
}
// Create and initialize the font object.
m_Font = new FontClass;
result = m_Font->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), 0);
if (!result)
{
return false;
}
// Create and initialize the render to texture object.
m_RenderTexture = new RenderTextureClass;
result = m_RenderTexture->Initialize(m_Direct3D->GetDevice(), 256, 256, SCREEN_DEPTH, SCREEN_NEAR, 1);
if (!result)
{
return false;
}
// Create and initialize the display plane object.
m_DisplayPlane = new DisplayPlaneClass;
result = m_DisplayPlane->Initialize(m_Direct3D->GetDevice(), 1.0f, 1.0f);
if (!result)
{
return false;
}
// Set the sprite info file we will be using.
strcpy_s(spriteFilename, "sprite_data_01.txt");
// Create and initialize the sprite object.
m_Sprite = new SpriteClass;
result = m_Sprite->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, spriteFilename, 50, 50);
if (!result)
{
return false;
}
// Set the initial mouse strings.
strcpy_s(mouseString1, "Mouse X: 0");
strcpy_s(mouseString2, "Mouse Y: 0");
strcpy_s(mouseString3, "Mouse Button: No");
// Create and initialize the text objects for the mouse strings.
m_MouseStrings = new TextClass[3];
result = m_MouseStrings[0].Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, mouseString1, 10, 10, 1.0f, 1.0f, 1.0f);
if (!result)
{
return false;
}
result = m_MouseStrings[1].Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, mouseString1, 10, 35, 1.0f, 1.0f, 1.0f);
if (!result)
{
return false;
}
result = m_MouseStrings[2].Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, mouseString1, 10, 60, 1.0f, 1.0f, 1.0f);
if (!result)
{
return false;
}
// Set the file name of the bitmap file.
strcpy_s(bitmapFilename, "stone01.tga");
// Create and initialize the bitmap object.
m_Bitmap = new BitmapClass;
result = m_Bitmap->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, bitmapFilename, 50, 50);
if (!result)
{
return false;
}
// Set the file name of the model.
strcpy_s(modelFilename, "cube.txt");
// Set the file name of the textures.
strcpy_s(textureFilename1, "stone01.tga");
strcpy_s(textureFilename2, "normal01.tga");
strcpy_s(textureFilename3, "spec02.tga");
strcpy_s(textureFilename4, "alpha01.tga");
strcpy_s(textureFilename5, "light01.tga");
strcpy_s(textureFilename6, "moss01.tga");
// Create and initialize the model object.
m_Model = new ModelClass;
result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename1, textureFilename2, textureFilename3, textureFilename4,
textureFilename5, textureFilename6);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the model object.", L"Error", MB_OK);
return false;
}
// Create and initialize the light object.
m_Light = new LightClass;
m_Light->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
m_Light->SetDirection(0.0f, 0.0f, -1.0f);
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.resize(m_numLights);
m_Lights[0] = new LightClass;
m_Lights[0]->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // White
m_Lights[0]->SetDirection(0.0f, 0.0f, -1.0f);
m_Lights[0]->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
m_Lights[0]->SetSpecularPower(16.0f);
m_Lights[0]->SetPosition(10.0f, 7.0f, -5.0f);
// Manually set the color and position of each light.
m_Lights[1] = new LightClass;
m_Lights[1]->SetDiffuseColor(1.0f, 0.0f, 0.0f, 1.0f); // Red
m_Lights[1]->SetDirection(0.0f, 0.0f, 1.0f);
m_Lights[1]->SetSpecularColor(1.0f, 0.0f, 0.0f, 1.0f);
m_Lights[1]->SetSpecularPower(16.0f);
m_Lights[1]->SetPosition(10.0f, 7.0f, -5.0f);
m_Lights[2] = new LightClass;
m_Lights[2]->SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f); // Green
m_Lights[2]->SetDirection(0.0f, 0.0f, 1.0f);
m_Lights[2]->SetSpecularColor(0.0f, 1.0f, 0.0f, 1.0f);
m_Lights[2]->SetSpecularPower(16.0f);
m_Lights[2]->SetPosition(10.0f, 7.0f, -5.0f);
m_Lights[3] = new LightClass;
m_Lights[3]->SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue
m_Lights[3]->SetDirection(0.0f, 0.0f, 1.0f);
m_Lights[3]->SetSpecularColor(0.0f, 0.0f, 1.0f, 1.0f);
m_Lights[3]->SetSpecularPower(16.0f);
m_Lights[3]->SetPosition(10.0f, 7.0f, -5.0f);
// Create and initialize the normal map shader object.
m_ShaderManager = new ShaderManagerClass;
result = m_ShaderManager->Initialize(m_Direct3D->GetDevice(), hwnd);
if (!result)
{
return false;
}
// Create and initialize the font shader object.
m_FontShader = new FontShaderClass;
result = m_FontShader->Initialize(m_Direct3D->GetDevice(), hwnd);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the font shader object.", L"Error", MB_OK);
return false;
}
// Create and initialize the font object.
m_Font = new FontClass;
result = m_Font->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), 0);
if (!result)
{
return false;
}
// Set the initial render count string.
strcpy_s(renderString, "Render Count: 0");
// Create and initialize the text object for the render count string.
m_RenderCountString = new TextClass;
result = m_RenderCountString->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, renderString, 10, 10, 1.0f, 1.0f, 1.0f);
if (!result)
{
return false;
}
// Create and initialize the model list object.
m_ModelList = new ModelListClass;
m_ModelList->Initialize(25);
// Create and initialize the timer object.
m_Timer = new TimerClass;
result = m_Timer->Initialize();
if (!result)
{
return false;
}
// Create the position class object.
m_Position = new PositionClass;
// Create the frustum class object.
m_Frustum = new FrustumClass;
// Create and initialize the fps object.
m_Fps = new FpsClass();
m_Fps->Initialize();
// Set the initial fps and fps string.
m_previousFps = -1;
strcpy_s(fpsString, "Fps: 0");
// Create and initialize the text object for the fps string.
m_FpsString = new TextClass;
result = m_FpsString->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, fpsString, 10, 10, 0.0f, 1.0f, 0.0f);
if (!result)
{ {
char mouseString1[32], mouseString2[32], mouseString3[32];
char modelFilename[128], textureFilename1[128], textureFilename2[128], textureFilename3[128], textureFilename4[128], textureFilename5[128], textureFilename6[128], renderString[32];
char bitmapFilename[128];
char spriteFilename[128];
char fpsString[32];
bool result;
m_screenWidth = screenWidth;
m_screenHeight = screenHeight;
// Create the Direct3D object.
m_Direct3D = new D3DClass;
if (!m_Direct3D)
{
logger.Log("Could not create the Direct3D object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
result = m_Direct3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR);
if (!result)
{
logger.Log("Could not initialize Direct3D", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create the camera object.
m_Camera = new CameraClass;
if (!m_Camera)
{
logger.Log("Could not create the camera object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the initial position of the camera.
m_Camera->SetPosition(0.0f, 0.0f, -12.0f);
m_Camera->SetRotation(0.0f, 0.0f, 0.0f);
m_Camera->Render();
m_Camera->GetViewMatrix(m_baseViewMatrix);
// Create and initialize the font shader object.
m_FontShader = new FontShaderClass;
result = m_FontShader->Initialize(m_Direct3D->GetDevice(), hwnd);
if (!result)
{
logger.Log("Could not initialize the font shader object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the font object.
m_Font = new FontClass;
result = m_Font->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), 0);
if (!result)
{
logger.Log("Could not initialize the font object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the texture shader object.
m_TextureShader = new TextureShaderClass;
result = m_TextureShader->Initialize(m_Direct3D->GetDevice(), hwnd);
if (!result)
{
logger.Log("Could not initialize the texture shader object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the render to texture object.
m_RenderTexture = new RenderTextureClass;
result = m_RenderTexture->Initialize(m_Direct3D->GetDevice(), 256, 256, SCREEN_DEPTH, SCREEN_NEAR, 1);
if (!result)
{
logger.Log("Could not initialize the render texture object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the display plane object.
m_DisplayPlane = new DisplayPlaneClass;
result = m_DisplayPlane->Initialize(m_Direct3D->GetDevice(), 1.0f, 1.0f);
if (!result)
{
logger.Log("Could not initialize the display plane object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the sprite info file we will be using.
strcpy_s(spriteFilename, "sprite_data_01.txt");
// Create and initialize the sprite object.
m_Sprite = new SpriteClass;
result = m_Sprite->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, spriteFilename, 50, 50);
if (!result)
{
logger.Log("Could not initialize the sprite object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the initial mouse strings.
strcpy_s(mouseString1, "Mouse X: 0");
strcpy_s(mouseString2, "Mouse Y: 0");
strcpy_s(mouseString3, "Mouse Button: No");
// Create and initialize the text objects for the mouse strings.
m_MouseStrings = new TextClass[3];
for (int i = 0; i < 3; i++)
{
int y = 10 + (i * 25);
result = m_MouseStrings[i].Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, mouseString1, 10, y, 1.0f, 1.0f, 1.0f);
if (!result)
{
logger.Log("Could not initialize the mouse strings", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
}
// Set the file name of the bitmap file.
strcpy_s(bitmapFilename, "stone01.tga");
// Create and initialize the bitmap object.
m_Bitmap = new BitmapClass;
result = m_Bitmap->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, bitmapFilename, 50, 50);
if (!result)
{
logger.Log("Could not initialize the bitmap object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the file name of the model.
strcpy_s(modelFilename, "cube.txt");
// Set the file name of the textures.
strcpy_s(textureFilename1, "stone01.tga");
strcpy_s(textureFilename2, "normal01.tga");
strcpy_s(textureFilename3, "spec02.tga");
strcpy_s(textureFilename4, "alpha01.tga");
strcpy_s(textureFilename5, "light01.tga");
strcpy_s(textureFilename6, "moss01.tga");
// Create and initialize the model object.
m_Model = new ModelClass;
result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename1, textureFilename2, textureFilename3, textureFilename4,
textureFilename5, textureFilename6);
if (!result)
{
logger.Log("Could not initialize the model object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the light shader object.
m_LightShader = new LightShaderClass;
result = m_LightShader->Initialize(m_Direct3D->GetDevice(), hwnd);
if (!result)
{
logger.Log("Could not initialize the light shader object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the light object.
m_Light = new LightClass;
m_Light->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
m_Light->SetDirection(0.0f, 0.0f, -1.0f);
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.resize(m_numLights);
m_Lights[0] = new LightClass;
m_Lights[0]->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // White
m_Lights[0]->SetDirection(0.0f, 0.0f, -1.0f);
m_Lights[0]->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
m_Lights[0]->SetSpecularPower(16.0f);
m_Lights[0]->SetPosition(10.0f, 7.0f, -5.0f);
// Manually set the color and position of each light.
m_Lights[1] = new LightClass;
m_Lights[1]->SetDiffuseColor(1.0f, 0.0f, 0.0f, 1.0f); // Red
m_Lights[1]->SetDirection(0.0f, 0.0f, 1.0f);
m_Lights[1]->SetSpecularColor(1.0f, 0.0f, 0.0f, 1.0f);
m_Lights[1]->SetSpecularPower(16.0f);
m_Lights[1]->SetPosition(10.0f, 7.0f, -5.0f);
m_Lights[2] = new LightClass;
m_Lights[2]->SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f); // Green
m_Lights[2]->SetDirection(0.0f, 0.0f, 1.0f);
m_Lights[2]->SetSpecularColor(0.0f, 1.0f, 0.0f, 1.0f);
m_Lights[2]->SetSpecularPower(16.0f);
m_Lights[2]->SetPosition(10.0f, 7.0f, -5.0f);
m_Lights[3] = new LightClass;
m_Lights[3]->SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue
m_Lights[3]->SetDirection(0.0f, 0.0f, 1.0f);
m_Lights[3]->SetSpecularColor(0.0f, 0.0f, 1.0f, 1.0f);
m_Lights[3]->SetSpecularPower(16.0f);
m_Lights[3]->SetPosition(10.0f, 7.0f, -5.0f);
// Create and initialize the normal map shader object.
m_ShaderManager = new ShaderManagerClass;
result = m_ShaderManager->Initialize(m_Direct3D->GetDevice(), hwnd);
if (!result)
{
logger.Log("Could not initialize the shader manager object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the initial render count string.
strcpy_s(renderString, "Render Count: 0");
// Create and initialize the text object for the render count string.
m_RenderCountString = new TextClass;
result = m_RenderCountString->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, renderString, 10, 10, 1.0f, 1.0f, 1.0f);
if (!result)
{
logger.Log("Could not initialize the render count string", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the model list object.
m_ModelList = new ModelListClass;
m_ModelList->Initialize(25);
// Create and initialize the timer object.
m_Timer = new TimerClass;
result = m_Timer->Initialize();
if (!result)
{
logger.Log("Could not initialize the timer object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create the position class object.
m_Position = new PositionClass;
// Create the frustum class object.
m_Frustum = new FrustumClass;
// Create and initialize the fps object.
m_Fps = new FpsClass();
m_Fps->Initialize();
// Set the initial fps and fps string.
m_previousFps = -1;
strcpy_s(fpsString, "Fps: 0");
// Create and initialize the text object for the fps string.
m_FpsString = new TextClass;
result = m_FpsString->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, fpsString, 10, 10, 0.0f, 1.0f, 0.0f);
if (!result)
{
logger.Log("Could not initialize the fps string", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
}
catch (const std::exception& e)
{
logger.Log(std::string("Exception caught during initialization: ") + e.what(), __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
logger.Log("Application class initialized", __FILE__, __LINE__);
return true; return true;
} }
@ -517,6 +535,7 @@ bool ApplicationClass::Frame(InputClass* Input)
result = Render(rotation, x, y, z, textureTranslation); result = Render(rotation, x, y, z, textureTranslation);
if (!result) if (!result)
{ {
logger.Log("Could not render the graphics scene", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -524,6 +543,7 @@ bool ApplicationClass::Frame(InputClass* Input)
result = UpdateFps(); result = UpdateFps();
if (!result) if (!result)
{ {
logger.Log("Could not update the frames per second", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -546,6 +566,7 @@ bool ApplicationClass::Frame(InputClass* Input)
result = RenderSceneToTexture(rotation); result = RenderSceneToTexture(rotation);
if (!result) if (!result)
{ {
logger.Log("Could not render the scene to the render texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -553,6 +574,7 @@ bool ApplicationClass::Frame(InputClass* Input)
result = UpdateMouseStrings(mouseX, mouseY, leftMouseDown); result = UpdateMouseStrings(mouseX, mouseY, leftMouseDown);
if (!result) if (!result)
{ {
logger.Log("Could not update the mouse strings", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -690,6 +712,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
diffuseColor, lightPosition); diffuseColor, lightPosition);
if (!result) if (!result)
{ {
logger.Log("Could not render the cube model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
} }
@ -714,6 +737,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
if (!result) if (!result)
{ {
logger.Log("Could not render the object model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
} }
@ -731,10 +755,12 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
chunk->Render(m_Direct3D->GetDeviceContext()); chunk->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0), result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), chunk->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, chunk->GetTexture(5),
diffuseColor, lightPosition); diffuseColor, lightPosition);
if (!result) if (!result)
{ {
logger.Log("Could not render the terrain model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
} }
@ -749,6 +775,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_RenderTexture->GetShaderResourceView()); m_RenderTexture->GetShaderResourceView());
if (!result) if (!result)
{ {
logger.Log("Could not render the display plane using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -762,6 +789,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_RenderTexture->GetShaderResourceView()); m_RenderTexture->GetShaderResourceView());
if (!result) if (!result)
{ {
logger.Log("Could not render the display plane using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -775,6 +803,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_RenderTexture->GetShaderResourceView()); m_RenderTexture->GetShaderResourceView());
if (!result) if (!result)
{ {
logger.Log("Could not render the display plane using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -812,6 +841,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
diffuseColor, lightPosition); diffuseColor, lightPosition);
if (!result) if (!result)
{ {
logger.Log("Could not render the model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -824,6 +854,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
result = UpdateRenderCountString(renderCount); result = UpdateRenderCountString(renderCount);
if (!result) if (!result)
{ {
logger.Log("Could not update the render count string", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -841,6 +872,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Font->GetTexture(), m_RenderCountString->GetPixelColor()); m_Font->GetTexture(), m_RenderCountString->GetPixelColor());
if (!result) if (!result)
{ {
logger.Log("Could not render the render count text string using the font shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -851,6 +883,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Font->GetTexture(), m_FpsString->GetPixelColor()); m_Font->GetTexture(), m_FpsString->GetPixelColor());
if (!result) if (!result)
{ {
logger.Log("Could not render the fps text string using the font shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -863,6 +896,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Font->GetTexture(), m_MouseStrings[i].GetPixelColor()); m_Font->GetTexture(), m_MouseStrings[i].GetPixelColor());
if (!result) if (!result)
{ {
logger.Log("Could not render the mouse text strings using the font shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
} }
@ -879,6 +913,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Sprite->GetTexture()); m_Sprite->GetTexture());
if (!result) if (!result)
{ {
logger.Log("Could not render the sprite using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -932,6 +967,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Model->GetTexture(0), m_Model->GetTexture(5), m_Model->GetTexture(3)); m_Model->GetTexture(0), m_Model->GetTexture(5), m_Model->GetTexture(3));
if (!result) if (!result)
{ {
logger.Log("Could not render the model using the alpha map shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -947,6 +983,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Model->GetTexture(0)); m_Model->GetTexture(0));
if (!result) if (!result)
{ {
logger.Log("Could not render the model using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -962,6 +999,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Model->GetTexture(0), m_Model->GetTexture(1), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor()); m_Model->GetTexture(0), m_Model->GetTexture(1), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor());
if (!result) if (!result)
{ {
logger.Log("Could not render the model using the normal map shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -978,6 +1016,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Model->GetTexture(0), m_Model->GetTexture(5)); m_Model->GetTexture(0), m_Model->GetTexture(5));
if (!result) if (!result)
{ {
logger.Log("Could not render the model using the multitexture shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -994,6 +1033,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Model->GetTexture(0), textureTranslation); m_Model->GetTexture(0), textureTranslation);
if (!result) if (!result)
{ {
logger.Log("Could not render the model using the translate shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -1010,6 +1050,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Camera->GetPosition(), m_Lights[0]->GetSpecularColor(), m_Lights[0]->GetSpecularPower()); m_Camera->GetPosition(), m_Lights[0]->GetSpecularColor(), m_Lights[0]->GetSpecularPower());
if (!result) if (!result)
{ {
logger.Log("Could not render the model using the specular map shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -1024,6 +1065,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
result = m_ShaderManager->RenderTransparentShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0), blendAmount); result = m_ShaderManager->RenderTransparentShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0), blendAmount);
if (!result) if (!result)
{ {
logger.Log("Could not render the model using the transparent shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -1089,6 +1131,9 @@ int ApplicationClass::GetScreenHeight() const
void ApplicationClass::GenerateTerrain() void ApplicationClass::GenerateTerrain()
{ {
logger.Log("Generating terrain", __FILE__, __LINE__);
char modelFilename[128]; char modelFilename[128];
char textureFilename1[128]; char textureFilename1[128];
char textureFilename2[128]; char textureFilename2[128];
@ -1136,6 +1181,9 @@ void ApplicationClass::GenerateTerrain()
void ApplicationClass::AddKobject(WCHAR* filepath) void ApplicationClass::AddKobject(WCHAR* filepath)
{ {
logger.Log("Adding object", __FILE__, __LINE__);
char modelFilename[128]; char modelFilename[128];
char textureFilename1[128]; char textureFilename1[128];
char textureFilename2[128]; char textureFilename2[128];
@ -1170,6 +1218,9 @@ void ApplicationClass::AddKobject(WCHAR* filepath)
void ApplicationClass::AddCube() void ApplicationClass::AddCube()
{ {
logger.Log("Adding cube", __FILE__, __LINE__);
char modelFilename[128]; char modelFilename[128];
char textureFilename1[128]; char textureFilename1[128];
char textureFilename2[128]; char textureFilename2[128];
@ -1200,6 +1251,8 @@ void ApplicationClass::AddCube()
void ApplicationClass::DeleteKobject(int index) void ApplicationClass::DeleteKobject(int index)
{ {
logger.Log("Deleting object", __FILE__, __LINE__);
if (index < m_object.size()) if (index < m_object.size())
{ {
m_object[index]->Shutdown(); m_object[index]->Shutdown();
@ -1210,6 +1263,8 @@ void ApplicationClass::DeleteKobject(int index)
void ApplicationClass::DeleteTerrain() void ApplicationClass::DeleteTerrain()
{ {
logger.Log("Deleting terrain", __FILE__, __LINE__);
for (auto cube : m_terrainChunk) for (auto cube : m_terrainChunk)
{ {
cube->Shutdown(); cube->Shutdown();
@ -1235,6 +1290,7 @@ bool ApplicationClass::UpdateMouseStrings(int mouseX, int mouseY, bool mouseDown
result = m_MouseStrings[0].UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 50, 1.0f, 1.0f, 1.0f); result = m_MouseStrings[0].UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 50, 1.0f, 1.0f, 1.0f);
if (!result) if (!result)
{ {
logger.Log("Could not update the mouse X string", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -1249,6 +1305,7 @@ bool ApplicationClass::UpdateMouseStrings(int mouseX, int mouseY, bool mouseDown
result = m_MouseStrings[1].UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 75, 1.0f, 1.0f, 1.0f); result = m_MouseStrings[1].UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 75, 1.0f, 1.0f, 1.0f);
if (!result) if (!result)
{ {
logger.Log("Could not update the mouse Y string", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -1267,6 +1324,7 @@ bool ApplicationClass::UpdateMouseStrings(int mouseX, int mouseY, bool mouseDown
if (!result) if (!result)
{ {
logger.Log("Could not update the mouse button string", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -1337,6 +1395,7 @@ bool ApplicationClass::UpdateFps()
result = m_FpsString->UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 10, red, green, blue); result = m_FpsString->UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 10, red, green, blue);
if (!result) if (!result)
{ {
logger.Log("Could not update the fps string", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -1360,6 +1419,7 @@ bool ApplicationClass::UpdateRenderCountString(int renderCount)
result = m_RenderCountString->UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 30, 1.0f, 1.0f, 1.0f); result = m_RenderCountString->UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 30, 1.0f, 1.0f, 1.0f);
if (!result) if (!result)
{ {
logger.Log("Could not update the render count string", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -1404,6 +1464,8 @@ void ApplicationClass::SetLightPosition(int index, XMVECTOR position)
void ApplicationClass::DeleteLight(int index) void ApplicationClass::DeleteLight(int index)
{ {
logger.Log("Deleting light", __FILE__, __LINE__);
if (index < 0 || index >= m_Lights.size()) if (index < 0 || index >= m_Lights.size())
{ {
// Index out of bounds // Index out of bounds

View File

@ -5,6 +5,8 @@
/////////////////////// ///////////////////////
// MY CLASS INCLUDES // // MY CLASS INCLUDES //
/////////////////////// ///////////////////////
#include "Logger.h"
#include "d3dclass.h" #include "d3dclass.h"
#include "cameraclass.h" #include "cameraclass.h"
#include "object.h" #include "object.h"
@ -157,6 +159,12 @@ private :
FpsClass* m_Fps; FpsClass* m_Fps;
TextClass* m_FpsString; TextClass* m_FpsString;
int m_previousFps; int m_previousFps;
// ------------------------------------------------- //
// ------------------- LOGGER ---------------------- //
// ------------------------------------------------- //
Logger logger;
}; };
#endif #endif

View File

@ -87,6 +87,7 @@
<ClInclude Include="lightclass.h" /> <ClInclude Include="lightclass.h" />
<ClInclude Include="lightmapshaderclass.h" /> <ClInclude Include="lightmapshaderclass.h" />
<ClInclude Include="lightshaderclass.h" /> <ClInclude Include="lightshaderclass.h" />
<ClInclude Include="Logger.h" />
<ClInclude Include="modelclass.h" /> <ClInclude Include="modelclass.h" />
<ClInclude Include="object.h" /> <ClInclude Include="object.h" />
<ClInclude Include="modellistclass.h" /> <ClInclude Include="modellistclass.h" />
@ -108,79 +109,120 @@
<ClInclude Include="transparentshaderclass.h" /> <ClInclude Include="transparentshaderclass.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="alphamap.ps" /> <CopyFileToFolders Include="alphamap.ps">
<None Include="alphamap.vs" /> <FileType>Document</FileType>
<None Include="font.ps" /> </CopyFileToFolders>
<None Include="font.vs" /> <CopyFileToFolders Include="alphamap.vs">
<None Include="light.ps" /> <FileType>Document</FileType>
<None Include="light.vs" /> </CopyFileToFolders>
<None Include="lightmap.ps" /> <CopyFileToFolders Include="font.ps">
<None Include="lightmap.vs" /> <FileType>Document</FileType>
<None Include="Multitexture.ps" /> </CopyFileToFolders>
<None Include="Multitexture.vs" /> <CopyFileToFolders Include="font.vs">
<None Include="normalmap.ps" /> <FileType>Document</FileType>
<None Include="normalmap.vs" /> </CopyFileToFolders>
<CopyFileToFolders Include="light.ps">
<FileType>Document</FileType>
</CopyFileToFolders>
<CopyFileToFolders Include="light.vs">
<FileType>Document</FileType>
</CopyFileToFolders>
<CopyFileToFolders Include="lightmap.ps">
<FileType>Document</FileType>
</CopyFileToFolders>
<CopyFileToFolders Include="lightmap.vs">
<FileType>Document</FileType>
</CopyFileToFolders>
<CopyFileToFolders Include="Multitexture.ps">
<FileType>Document</FileType>
</CopyFileToFolders>
<CopyFileToFolders Include="Multitexture.vs">
<FileType>Document</FileType>
</CopyFileToFolders>
<CopyFileToFolders Include="normalmap.ps">
<FileType>Document</FileType>
</CopyFileToFolders>
<CopyFileToFolders Include="normalmap.vs">
<FileType>Document</FileType>
</CopyFileToFolders>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="reflection.ps" /> <CopyFileToFolders Include="reflection.ps">
<None Include="reflection.vs" />
<None Include="specmap.ps">
<FileType>Document</FileType> <FileType>Document</FileType>
</None> </CopyFileToFolders>
<None Include="specmap.vs"> <CopyFileToFolders Include="reflection.vs">
<FileType>Document</FileType> <FileType>Document</FileType>
</None> </CopyFileToFolders>
<None Include="texture.ps" /> <CopyFileToFolders Include="specmap.ps">
<None Include="texture.vs" /> <FileType>Document</FileType>
<None Include="transparent.ps" /> </CopyFileToFolders>
<None Include="transparent.vs" /> <CopyFileToFolders Include="specmap.vs">
<FileType>Document</FileType>
</CopyFileToFolders>
<CopyFileToFolders Include="texture.ps">
<FileType>Document</FileType>
</CopyFileToFolders>
<CopyFileToFolders Include="texture.vs">
<FileType>Document</FileType>
</CopyFileToFolders>
<CopyFileToFolders Include="transparent.ps">
<FileType>Document</FileType>
</CopyFileToFolders>
<CopyFileToFolders Include="transparent.vs">
<FileType>Document</FileType>
</CopyFileToFolders>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Color.ps"> <CopyFileToFolders Include="Color.ps">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<FileType>Document</FileType> <FileType>Document</FileType>
</None> </CopyFileToFolders>
<None Include="Color.vs"> <CopyFileToFolders Include="Color.vs">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
<FileType>Document</FileType> <FileType>Document</FileType>
</None> </CopyFileToFolders>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="..\..\..\..\Downloads\grass.tga" /> <CopyFileToFolders Include="..\..\..\..\Downloads\grass.tga" />
<Image Include="alpha01.tga" /> <CopyFileToFolders Include="alpha01.tga" />
<Image Include="dirt01.tga" /> <Image Include="dirt01.tga" />
<Image Include="font01.tga" /> <CopyFileToFolders Include="font01.tga" />
<Image Include="KhaoticIcon.ico" /> <Image Include="KhaoticIcon.ico" />
<Image Include="light01.tga" /> <CopyFileToFolders Include="light01.tga" />
<Image Include="moss01.tga" /> <CopyFileToFolders Include="moss01.tga" />
<Image Include="normal01.tga" /> <CopyFileToFolders Include="normal01.tga" />
<Image Include="papier.tga" /> <Image Include="papier.tga" />
<Image Include="spec02.tga" /> <CopyFileToFolders Include="spec02.tga" />
<Image Include="stone01.tga" /> <CopyFileToFolders Include="sprite01.tga" />
<CopyFileToFolders Include="sprite02.tga" />
<CopyFileToFolders Include="sprite03.tga" />
<CopyFileToFolders Include="sprite04.tga" />
<CopyFileToFolders Include="stone01.tga" />
<Image Include="wall.tga" /> <Image Include="wall.tga" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Text Include="..\..\..\..\Downloads\chunk.txt" /> <CopyFileToFolders Include="..\..\..\..\Downloads\chunk.txt" />
<Text Include="cube.txt" /> <CopyFileToFolders Include="cube.txt" />
<Text Include="font01.txt" /> <CopyFileToFolders Include="font01.txt" />
<Text Include="plane.txt" /> <CopyFileToFolders Include="plane.txt" />
<Text Include="sphere.txt" /> <Text Include="sphere.txt" />
<CopyFileToFolders Include="sprite_data_01.txt" />
<Text Include="square.txt" /> <Text Include="square.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="translate.ps"> <CopyFileToFolders Include="translate.ps">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<FileType>Document</FileType> <FileType>Document</FileType>
</None> </CopyFileToFolders>
<None Include="translate.vs"> <CopyFileToFolders Include="translate.vs">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<FileType>Document</FileType> <FileType>Document</FileType>
</None> </CopyFileToFolders>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="resources.rc" /> <ResourceCompile Include="resources.rc" />

View File

@ -290,11 +290,17 @@
<ClInclude Include="resources.h"> <ClInclude Include="resources.h">
<Filter>Fichiers d%27en-tête</Filter> <Filter>Fichiers d%27en-tête</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="shadermanagerclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="transparentshaderclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="Logger.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="font01.tga">
<Filter>fonts</Filter>
</Image>
<Image Include="wall.tga"> <Image Include="wall.tga">
<Filter>assets</Filter> <Filter>assets</Filter>
</Image> </Image>
@ -304,9 +310,6 @@
<Image Include="moss01.tga"> <Image Include="moss01.tga">
<Filter>assets</Filter> <Filter>assets</Filter>
</Image> </Image>
<Image Include="stone01.tga">
<Filter>assets</Filter>
</Image>
<Image Include="light01.tga"> <Image Include="light01.tga">
<Filter>assets</Filter> <Filter>assets</Filter>
</Image> </Image>
@ -325,24 +328,15 @@
<Image Include="KhaoticIcon.ico"> <Image Include="KhaoticIcon.ico">
<Filter>Assets</Filter> <Filter>Assets</Filter>
</Image> </Image>
<Image Include="sprite02.tga" />
<Image Include="sprite03.tga" />
<Image Include="sprite04.tga" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="Color.ps"> <None Include="Color.ps">
<Filter>shader</Filter> <Filter>shader</Filter>
</None> </None>
<None Include="Color.vs">
<Filter>shader</Filter>
</None>
<None Include="font.ps">
<Filter>Fonts</Filter>
</None>
<None Include="font.vs">
<Filter>Fonts</Filter>
</None>
<None Include="light.ps">
<Filter>shader</Filter>
</None>
<None Include="light.vs"> <None Include="light.vs">
<Filter>shader</Filter> <Filter>shader</Filter>
</None> </None>
@ -386,23 +380,13 @@
<None Include="reflection.ps" /> <None Include="reflection.ps" />
<None Include="specmap.ps" /> <None Include="specmap.ps" />
<None Include="specmap.vs" /> <None Include="specmap.vs" />
<None Include="transparent.ps" />
<None Include="transparent.vs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Text Include="font01.txt">
<Filter>Fonts</Filter>
</Text>
<Text Include="..\..\..\..\Downloads\chunk.txt">
<Filter>Assets</Filter>
</Text>
<Text Include="cube.txt">
<Filter>Assets</Filter>
</Text>
<Text Include="sphere.txt"> <Text Include="sphere.txt">
<Filter>Assets</Filter> <Filter>Assets</Filter>
</Text> </Text>
<Text Include="plane.txt">
<Filter>Assets</Filter>
</Text>
<Text Include="square.txt"> <Text Include="square.txt">
<Filter>assets</Filter> <Filter>assets</Filter>
</Text> </Text>
@ -412,4 +396,39 @@
<Filter>Fichiers de ressources</Filter> <Filter>Fichiers de ressources</Filter>
</ResourceCompile> </ResourceCompile>
</ItemGroup> </ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="font.vs">
<Filter>Fonts</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="font.ps">
<Filter>Fonts</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="Color.vs">
<Filter>shader</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="light.ps">
<Filter>shader</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="font01.txt">
<Filter>Fonts</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="font01.tga">
<Filter>fonts</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="sprite_data_01.txt" />
<CopyFileToFolders Include="sprite01.tga" />
<CopyFileToFolders Include="stone01.tga">
<Filter>assets</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="cube.txt">
<Filter>Assets</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="spec02.tga" />
<CopyFileToFolders Include="..\..\..\..\Downloads\chunk.txt">
<Filter>Assets</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="plane.txt">
<Filter>Assets</Filter>
</CopyFileToFolders>
</ItemGroup>
</Project> </Project>

View File

@ -3,19 +3,18 @@ Pos=60,60
Size=400,400 Size=400,400
[Window][Khaotic Engine] [Window][Khaotic Engine]
Pos=24,182 Pos=429,57
Size=694,210 Size=392,218
[Window][Objects] [Window][Objects]
Pos=35,13 Pos=39,222
Size=492,353 Size=379,299
Collapsed=1
[Window][Terrain] [Window][Terrain]
Pos=816,75 Pos=60,60
Size=418,94 Size=342,82
[Window][Light] [Window][Light]
Pos=58,418 Pos=95,296
Size=418,240 Size=345,230

View File

@ -13,6 +13,8 @@ imguiManager::~imguiManager()
bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* deviceContext) bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* deviceContext)
{ {
logger.Log("Initializing imgui", __FILE__, __LINE__);
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
io = &ImGui::GetIO(); io = &ImGui::GetIO();
@ -21,6 +23,8 @@ bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceConte
ImGui_ImplDX11_Init(device, deviceContext); ImGui_ImplDX11_Init(device, deviceContext);
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
logger.Log("imgui initialized", __FILE__, __LINE__);
return true; return true;
} }

View File

@ -2,6 +2,8 @@
#ifndef _IMGUI_MANAGER_H_ #ifndef _IMGUI_MANAGER_H_
#define _IMGUI_MANAGER_H_ #define _IMGUI_MANAGER_H_
#include "Logger.h"
#include <imgui.h> #include <imgui.h>
#include <imgui_impl_dx11.h> #include <imgui_impl_dx11.h>
#include <imgui_impl_win32.h> #include <imgui_impl_win32.h>
@ -39,6 +41,8 @@ private :
private: private:
ImGuiIO* io; ImGuiIO* io;
Logger logger;
}; };
#endif #endif

View File

@ -22,12 +22,15 @@ ModelClass::~ModelClass()
bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename, char* textureFilename1, char* textureFilename2, char* textureFilename3, bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename, char* textureFilename1, char* textureFilename2, char* textureFilename3,
char* textureFilename4, char* textureFilename5, char* textureFilename6) char* textureFilename4, char* textureFilename5, char* textureFilename6)
{ {
logger.Log("Initializing model class", __FILE__, __LINE__);
bool result; bool result;
// Load in the model data. // Load in the model data.
result = LoadModel(modelFilename); result = LoadModel(modelFilename);
if (!result) if (!result)
{ {
logger.Log("Failed to load model data", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -38,15 +41,19 @@ bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCon
result = InitializeBuffers(device); result = InitializeBuffers(device);
if (!result) if (!result)
{ {
logger.Log("Failed to initialize buffers", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
// Load the textures for this model. // Load the textures for this model.
result = LoadTextures(device, deviceContext, textureFilename1, textureFilename2, textureFilename3, textureFilename4, textureFilename5, textureFilename6); result = LoadTextures(device, deviceContext, textureFilename1, textureFilename2, textureFilename3, textureFilename4, textureFilename5, textureFilename6);
if (!result) if (!result)
{ {
logger.Log("Failed to load textures", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
logger.Log("Model class initialized", __FILE__, __LINE__);
return true; return true;
} }
@ -88,6 +95,8 @@ ID3D11ShaderResourceView* ModelClass::GetTexture(int index)
bool ModelClass::InitializeBuffers(ID3D11Device* device) bool ModelClass::InitializeBuffers(ID3D11Device* device)
{ {
logger.Log("Initializing buffers", __FILE__, __LINE__);
VertexType* vertices; VertexType* vertices;
unsigned long* indices; unsigned long* indices;
D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc; D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc;
@ -130,6 +139,7 @@ bool ModelClass::InitializeBuffers(ID3D11Device* device)
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer); result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
logger.Log("Failed to create vertex buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -150,6 +160,7 @@ bool ModelClass::InitializeBuffers(ID3D11Device* device)
result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer); result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
logger.Log("Failed to create index buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -160,6 +171,8 @@ bool ModelClass::InitializeBuffers(ID3D11Device* device)
delete[] indices; delete[] indices;
indices = 0; indices = 0;
logger.Log("Buffers initialized", __FILE__, __LINE__);
return true; return true;
} }
@ -210,6 +223,8 @@ void ModelClass::RenderBuffers(ID3D11DeviceContext* deviceContext)
bool ModelClass::LoadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* filename1, char* filename2, char* filename3, char* filename4, char* filename5, bool ModelClass::LoadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* filename1, char* filename2, char* filename3, char* filename4, char* filename5,
char* filename6) char* filename6)
{ {
logger.Log("Loading textures", __FILE__, __LINE__);
bool result; bool result;
@ -219,45 +234,54 @@ bool ModelClass::LoadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceC
result = m_Textures[0].Initialize(device, deviceContext, filename1); result = m_Textures[0].Initialize(device, deviceContext, filename1);
if (!result) if (!result)
{ {
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
result = m_Textures[1].Initialize(device, deviceContext, filename2); result = m_Textures[1].Initialize(device, deviceContext, filename2);
if (!result) if (!result)
{ {
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
result = m_Textures[2].Initialize(device, deviceContext, filename3); result = m_Textures[2].Initialize(device, deviceContext, filename3);
if (!result) if (!result)
{ {
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
result = m_Textures[3].Initialize(device, deviceContext, filename4); result = m_Textures[3].Initialize(device, deviceContext, filename4);
if (!result) if (!result)
{ {
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
result = m_Textures[4].Initialize(device, deviceContext, filename5); result = m_Textures[4].Initialize(device, deviceContext, filename5);
if (!result) if (!result)
{ {
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
result = m_Textures[5].Initialize(device, deviceContext, filename6); result = m_Textures[5].Initialize(device, deviceContext, filename6);
if (!result) if (!result)
{ {
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
logger.Log("Textures loaded", __FILE__, __LINE__);
return true; return true;
} }
void ModelClass::ReleaseTextures() void ModelClass::ReleaseTextures()
{ {
logger.Log("Releasing textures", __FILE__, __LINE__);
// Release the texture object array. // Release the texture object array.
if (m_Textures) if (m_Textures)
{ {
@ -272,11 +296,15 @@ void ModelClass::ReleaseTextures()
m_Textures = 0; m_Textures = 0;
} }
logger.Log("Textures released", __FILE__, __LINE__);
return; return;
} }
bool ModelClass::LoadModel(char* filename) bool ModelClass::LoadModel(char* filename)
{ {
logger.Log("Loading model", __FILE__, __LINE__);
ifstream fin; ifstream fin;
char input; char input;
int i; int i;
@ -288,6 +316,7 @@ bool ModelClass::LoadModel(char* filename)
// If it could not open the file then exit. // If it could not open the file then exit.
if (fin.fail()) if (fin.fail())
{ {
logger.Log("Failed to open model file", __FILE__, __LINE__, Logger::LogLevel::Error);
return false; return false;
} }
@ -327,11 +356,15 @@ bool ModelClass::LoadModel(char* filename)
// Close the model file. // Close the model file.
fin.close(); fin.close();
logger.Log("Model loaded", __FILE__, __LINE__);
return true; return true;
} }
void ModelClass::CalculateModelVectors() void ModelClass::CalculateModelVectors()
{ {
logger.Log("Calculating model vectors", __FILE__, __LINE__);
int faceCount, i, index; int faceCount, i, index;
TempVertexType vertex1, vertex2, vertex3; TempVertexType vertex1, vertex2, vertex3;
VectorType tangent, binormal; VectorType tangent, binormal;
@ -394,11 +427,15 @@ void ModelClass::CalculateModelVectors()
m_model[index - 3].bz = binormal.z; m_model[index - 3].bz = binormal.z;
} }
logger.Log("Model vectors calculated", __FILE__, __LINE__);
return; return;
} }
void ModelClass::CalculateTangentBinormal(TempVertexType vertex1, TempVertexType vertex2, TempVertexType vertex3, VectorType& tangent, VectorType& binormal) void ModelClass::CalculateTangentBinormal(TempVertexType vertex1, TempVertexType vertex2, TempVertexType vertex3, VectorType& tangent, VectorType& binormal)
{ {
logger.Log("Calculating tangent and binormal", __FILE__, __LINE__);
float vector1[3], vector2[3]; float vector1[3], vector2[3];
float tuVector[2], tvVector[2]; float tuVector[2], tvVector[2];
float den; float den;
@ -449,16 +486,22 @@ void ModelClass::CalculateTangentBinormal(TempVertexType vertex1, TempVertexType
binormal.y = binormal.y / length; binormal.y = binormal.y / length;
binormal.z = binormal.z / length; binormal.z = binormal.z / length;
logger.Log("Tangent and binormal calculated", __FILE__, __LINE__);
return; return;
} }
void ModelClass::ReleaseModel() void ModelClass::ReleaseModel()
{ {
logger.Log("Releasing model", __FILE__, __LINE__);
if (m_model) if (m_model)
{ {
delete[] m_model; delete[] m_model;
m_model = 0; m_model = 0;
} }
logger.Log("Model released", __FILE__, __LINE__);
return; return;
} }

View File

@ -5,6 +5,8 @@
////////////// //////////////
// INCLUDES // // INCLUDES //
////////////// //////////////
#include "Logger.h"
#include <d3d11.h> #include <d3d11.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
@ -105,6 +107,8 @@ private:
int m_vertexCount, m_indexCount; int m_vertexCount, m_indexCount;
TextureClass* m_Textures; TextureClass* m_Textures;
ModelType* m_model; ModelType* m_model;
Logger logger;
}; };
#endif #endif

View File

@ -49,4 +49,5 @@ private:
XMMATRIX m_worldMatrix; XMMATRIX m_worldMatrix;
std::string m_name; std::string m_name;
}; };

View File

@ -3,6 +3,8 @@
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include "Logger.h"
#include "inputclass.h" #include "inputclass.h"
#include "applicationclass.h" #include "applicationclass.h"
#include "imguiManager.h" #include "imguiManager.h"
@ -30,6 +32,7 @@ private:
LPCWSTR m_applicationName; LPCWSTR m_applicationName;
HINSTANCE m_hinstance; HINSTANCE m_hinstance;
HWND m_hwnd; HWND m_hwnd;
Logger logger;
InputClass* m_Input; InputClass* m_Input;
ApplicationClass* m_Application; ApplicationClass* m_Application;