diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index 647a19b..3ac4459 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -1105,7 +1105,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t if (!m_enableCelShading) { - result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), cube->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, cube->GetTexture(), + result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), cube->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, cube->GetTexture(0), diffuseColor, lightPosition, ambientColor); if (!result) { @@ -1116,7 +1116,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t // Render cel shading globally to the scene using the cel shader if the checkbox is checked. if (m_enableCelShading) { - result = m_ShaderManager->RenderCelShadingShader(m_Direct3D->GetDeviceContext(), cube->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, cube->GetTexture(), + result = m_ShaderManager->RenderCelShadingShader(m_Direct3D->GetDeviceContext(), cube->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, cube->GetTexture(0), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor(), TrueLightPosition); if (!result) { @@ -1143,7 +1143,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t object->Render(m_Direct3D->GetDeviceContext()); if (!m_enableCelShading) { - result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, object->GetTexture(), + result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, object->GetTexture(0), diffuseColor, lightPosition, ambientColor); if (!result) @@ -1155,7 +1155,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t // Render cel shading globally to the scene using the cel shader if the checkbox is checked. if (m_enableCelShading) { - result = m_ShaderManager->RenderCelShadingShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, object->GetTexture(), + result = m_ShaderManager->RenderCelShadingShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, object->GetTexture(0), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor(), TrueLightPosition); if (!result) { @@ -1178,7 +1178,13 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t chunk->Render(m_Direct3D->GetDeviceContext()); if (!m_enableCelShading) { - result = m_ShaderManager->RenderTextureShader(m_Direct3D->GetDeviceContext(), chunk->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, chunk->GetTexture()); + if (chunk->GetTexture(0) == nullptr) + { + Logger::Get().Log("Could not render the terrain model using the light shader, texture is null", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + result = m_ShaderManager->RenderTextureShader(m_Direct3D->GetDeviceContext(), chunk->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, chunk->GetTexture(0)); if (!result) { @@ -1190,7 +1196,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t // Render cel shading globally to the scene using the cel shader if the checkbox is checked. if (m_enableCelShading) { - result = m_ShaderManager->RenderCelShadingShader(m_Direct3D->GetDeviceContext(), chunk->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, chunk->GetTexture(), + result = m_ShaderManager->RenderCelShadingShader(m_Direct3D->GetDeviceContext(), chunk->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, chunk->GetTexture(0), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor(), TrueLightPosition); if (!result) { @@ -1578,7 +1584,6 @@ void ApplicationClass::GenerateTerrain() Logger::Get().Log("Generating terrain", __FILE__, __LINE__); char modelFilename[128]; - std::vector Filename; bool result; XMMATRIX scaleMatrix; @@ -1622,13 +1627,16 @@ void ApplicationClass::GenerateTerrain() return ; // Assurez-vous de retourner false ou de gérer l'erreur de manière appropriée } textures.push_back(texture); + + // log success message + Logger::Get().Log("Texture loaded: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Initialize); + } std::filesystem::path p(modelFilename); std::string filenameWithoutExtension = p.stem().string(); - // for loop to generate terrain chunks for a 10x10 grid for (int i = 0; i < 10; i++) { diff --git a/enginecustom/enginecustom.vcxproj b/enginecustom/enginecustom.vcxproj index 7c944ff..864fa1e 100644 --- a/enginecustom/enginecustom.vcxproj +++ b/enginecustom/enginecustom.vcxproj @@ -225,7 +225,7 @@ - + diff --git a/enginecustom/enginecustom.vcxproj.filters b/enginecustom/enginecustom.vcxproj.filters index 8dd5054..5c70cca 100644 --- a/enginecustom/enginecustom.vcxproj.filters +++ b/enginecustom/enginecustom.vcxproj.filters @@ -370,9 +370,6 @@ Assets - - Assets - @@ -559,5 +556,8 @@ shader + + Assets + \ No newline at end of file diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index d85c6d3..34eb174 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -19,6 +19,6 @@ Pos=1564,17 Size=345,519 [Window][Shader Manager] -Pos=32,253 +Pos=34,253 Size=172,284 diff --git a/enginecustom/imguiManager.cpp b/enginecustom/imguiManager.cpp index e9581b5..002e579 100644 --- a/enginecustom/imguiManager.cpp +++ b/enginecustom/imguiManager.cpp @@ -167,7 +167,7 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app) for (int count = 0; count < 6; count++) { std::string textureLabel = "Texture##" + std::to_string(index); - ID3D11ShaderResourceView* texture = object->GetTexture(); + ID3D11ShaderResourceView* texture = object->GetTexture(count); if (texture != nullptr) { // Set the cursor position @@ -188,7 +188,7 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app) for (int count = 0; count < 6; count++) { std::string textureLabel = "Texture##" + std::to_string(index); - ID3D11ShaderResourceView* texture = object->GetTexture(); + ID3D11ShaderResourceView* texture = object->GetTexture(count); if (texture != nullptr) { // Set the cursor position diff --git a/enginecustom/modelclass.cpp b/enginecustom/modelclass.cpp index 1d00fb0..78107d2 100644 --- a/enginecustom/modelclass.cpp +++ b/enginecustom/modelclass.cpp @@ -77,9 +77,11 @@ int ModelClass::GetIndexCount() return m_indexCount; } -ID3D11ShaderResourceView* ModelClass::GetTexture(int index) -{ - return m_Textures[index]; +ID3D11ShaderResourceView* ModelClass::GetTexture(int index) const { + if (index >= 0 && index < m_Textures.size()) { + return m_Textures[index]; + } + return nullptr; // Retourne nullptr si l'index est hors limites } diff --git a/enginecustom/modelclass.h b/enginecustom/modelclass.h index 24376ed..69acb5b 100644 --- a/enginecustom/modelclass.h +++ b/enginecustom/modelclass.h @@ -89,7 +89,7 @@ public: void Render(ID3D11DeviceContext*); int GetIndexCount(); - ID3D11ShaderResourceView* GetTexture(int); + ID3D11ShaderResourceView* GetTexture(int index) const; bool ChangeTexture(ID3D11Device*, ID3D11DeviceContext*, std::wstring filename, int index); private: diff --git a/enginecustom/object.cpp b/enginecustom/object.cpp index c07198e..4b80347 100644 --- a/enginecustom/object.cpp +++ b/enginecustom/object.cpp @@ -17,23 +17,7 @@ Object::Object() : ModelClass() Object::~Object() { - if (m_Texture) { - m_Texture->Release(); - m_Texture = nullptr; - } -} -bool Object::LoadTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, const std::wstring& filename) { - HRESULT result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &m_Texture); - if (FAILED(result)) { - return false; - } - return true; -} - -ID3D11ShaderResourceView* Object::GetTexture() const -{ - return m_Texture; } void Object::SetScaleMatrix(XMMATRIX scaleMatrix) diff --git a/enginecustom/object.h b/enginecustom/object.h index fd22899..adf9127 100644 --- a/enginecustom/object.h +++ b/enginecustom/object.h @@ -54,8 +54,6 @@ public: bool LoadTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, const std::wstring& filename); - ID3D11ShaderResourceView* GetTexture() const; - public : bool m_demoSpinning = false; XMVECTOR m_previousPosition; @@ -74,5 +72,4 @@ private: bool m_isGrounded; std::string m_name; - ID3D11ShaderResourceView* m_Texture; };