Patch update - Scene window

This commit is contained in:
CatChow0 2025-01-16 21:02:17 +01:00
parent 06efdf6f6c
commit 15217a5df8
5 changed files with 95 additions and 19 deletions

View File

@ -23,6 +23,7 @@ ApplicationClass::ApplicationClass() : m_ShouldQuit(false)
m_Light = 0; m_Light = 0;
m_RefractionTexture = 0; m_RefractionTexture = 0;
m_ReflectionTexture = 0; m_ReflectionTexture = 0;
m_SceneTexture = nullptr;
m_Physics = 0; m_Physics = 0;
m_cubes.clear(); m_cubes.clear();
m_terrainChunk.clear(); m_terrainChunk.clear();
@ -123,6 +124,17 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
return false; return false;
} }
//ImVec2 availableSize = ImGui::GetContentRegionAvail();
// Create and initialize the scene render to texture object.
m_SceneTexture = new RenderTextureClass();
result = m_SceneTexture->Initialize(m_Direct3D->GetDevice(), 256, 256, SCREEN_DEPTH, SCREEN_NEAR, 1);
if (!result)
{
Logger::Get().Log("Could not initialize the render texture object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the display plane object. // Create and initialize the display plane object.
m_DisplayPlane = new DisplayPlaneClass; m_DisplayPlane = new DisplayPlaneClass;
@ -635,6 +647,13 @@ void ApplicationClass::Shutdown()
Logger::Get().Log("Model object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); Logger::Get().Log("Model object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
} }
if (m_SceneTexture)
{
m_SceneTexture->Shutdown();
delete m_SceneTexture;
m_SceneTexture = nullptr;
}
Logger::Get().Log("Application class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); Logger::Get().Log("Application class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
} }
@ -935,6 +954,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Camera->Render(); m_Camera->Render();
// Get the world, view, and projection matrices from the camera and d3d objects. // Get the world, view, and projection matrices from the camera and d3d objects.
worldMatrix = m_Direct3D->GetWorldMatrix(); worldMatrix = m_Direct3D->GetWorldMatrix();
m_Camera->GetViewMatrix(viewMatrix); m_Camera->GetViewMatrix(viewMatrix);
@ -954,6 +974,17 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
ambientColor[i] = m_Lights[i]->GetPosition(); ambientColor[i] = m_Lights[i]->GetPosition();
} }
// Redimensionner la texture de rendu si nécessaire
if (m_SceneTexture->GetTextureWidth() != windowSize.x || m_SceneTexture->GetTextureHeight() != windowSize.y)
{
m_SceneTexture->Shutdown();
m_SceneTexture->Initialize(m_Direct3D->GetDevice(), windowSize.x, windowSize.y, SCREEN_DEPTH, SCREEN_NEAR, 1);
}
m_SceneTexture->SetRenderTarget(m_Direct3D->GetDeviceContext());
m_SceneTexture->ClearRenderTarget(m_Direct3D->GetDeviceContext(), 0.0f, 0.0f, 0.0f, 1.0f);
//Add the 3 first value of the first light position to the TrueLightPosition XMFLOAT3 //Add the 3 first value of the first light position to the TrueLightPosition XMFLOAT3
positionX = lightPosition[0].x; positionX = lightPosition[0].x;
positionY = lightPosition[0].y; positionY = lightPosition[0].y;
@ -1295,6 +1326,8 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
} }
// Enable the Z buffer and disable alpha blending now that 2D rendering is complete. // Enable the Z buffer and disable alpha blending now that 2D rendering is complete.
// Réinitialiser la cible de rendu au back buffer.
m_Direct3D->SetBackBufferRenderTarget();
m_Direct3D->TurnZBufferOn(); m_Direct3D->TurnZBufferOn();
m_Direct3D->DisableAlphaBlending(); m_Direct3D->DisableAlphaBlending();

View File

@ -60,6 +60,7 @@ public:
ApplicationClass(); ApplicationClass();
~ApplicationClass(); ~ApplicationClass();
D3DClass* GetDirect3D(); D3DClass* GetDirect3D();
RenderTextureClass* GetRenderTexture() const { return m_SceneTexture; };
bool Initialize(int, int, HWND); bool Initialize(int, int, HWND);
void Shutdown(); void Shutdown();
@ -111,6 +112,9 @@ public:
bool IsWindowed() const; bool IsWindowed() const;
void SetWindowed(bool windowed); void SetWindowed(bool windowed);
void SetWindowSize(ImVec2 size) { windowSize = size; };
ImVec2 GetWindowSize() const { return windowSize; };
Physics* GetPhysics() const { return m_Physics; }; Physics* GetPhysics() const { return m_Physics; };
// ----------------------------------- // // ----------------------------------- //
@ -159,7 +163,7 @@ private :
// ------------------------------------- // // ------------------------------------- //
XMMATRIX m_baseViewMatrix; XMMATRIX m_baseViewMatrix;
RenderTextureClass* m_RenderTexture, * m_RefractionTexture, * m_ReflectionTexture; RenderTextureClass* m_RenderTexture, * m_RefractionTexture, * m_ReflectionTexture, * m_SceneTexture;
DisplayPlaneClass* m_DisplayPlane; DisplayPlaneClass* m_DisplayPlane;
int m_screenWidth, m_screenHeight; int m_screenWidth, m_screenHeight;
CameraClass* m_Camera; CameraClass* m_Camera;
@ -227,6 +231,7 @@ private :
Physics* m_Physics; Physics* m_Physics;
float m_gravity; float m_gravity;
XMVECTOR m_previousPosition; XMVECTOR m_previousPosition;
ImVec2 windowSize;
// ------------------------------------------------- // // ------------------------------------------------- //
// ------------------- Culling --------------------- // // ------------------- Culling --------------------- //

View File

@ -4,22 +4,22 @@ Size=400,400
Collapsed=0 Collapsed=0
[Window][Khaotic Engine] [Window][Khaotic Engine]
Pos=1665,27 Pos=1201,27
Size=375,1094 Size=375,826
Collapsed=0 Collapsed=0
DockId=0x00000005,0 DockId=0x00000005,0
[Window][Objects] [Window][Objects]
Pos=8,27 Pos=8,27
Size=331,1094 Size=330,826
Collapsed=0 Collapsed=0
DockId=0x00000003,0 DockId=0x00000001,1
[Window][Terrain] [Window][Terrain]
Pos=8,27 Pos=8,27
Size=331,1094 Size=330,826
Collapsed=0 Collapsed=0
DockId=0x00000003,1 DockId=0x00000001,0
[Window][Light] [Window][Light]
Pos=1648,27 Pos=1648,27
@ -29,25 +29,31 @@ DockId=0x00000005,1
[Window][Shader Manager] [Window][Shader Manager]
Pos=8,27 Pos=8,27
Size=331,1094 Size=330,1094
Collapsed=0 Collapsed=0
DockId=0x00000003,2 DockId=0x00000001,2
[Window][Engine Settings] [Window][Engine Settings]
Pos=1648,27 Pos=1201,27
Size=392,1094 Size=375,826
Collapsed=0 Collapsed=0
DockId=0x00000005,2 DockId=0x00000005,1
[Window][DockSpace Demo] [Window][DockSpace Demo]
Pos=0,0 Pos=0,0
Size=2048,1129 Size=1584,861
Collapsed=0 Collapsed=0
[Docking][Data] [Window][Render Window]
DockSpace ID=0xC0DFADC4 Window=0xD0388BC8 Pos=8,27 Size=2032,1094 Split=X Pos=340,27
DockNode ID=0x00000002 Parent=0xC0DFADC4 SizeRef=1655,1094 Split=X Size=859,826
DockNode ID=0x00000003 Parent=0x00000002 SizeRef=331,826 Selected=0x031DC75C Collapsed=0
DockNode ID=0x00000004 Parent=0x00000002 SizeRef=1322,826 CentralNode=1 Selected=0x9F035453 DockId=0x00000002,0
DockNode ID=0x00000005 Parent=0xC0DFADC4 SizeRef=375,1094 Selected=0x9F035453
[Docking][Data]
DockSpace ID=0xC0DFADC4 Window=0xD0388BC8 Pos=8,27 Size=1568,826 Split=X
DockNode ID=0x00000001 Parent=0xC0DFADC4 SizeRef=330,1094 Selected=0x031DC75C
DockNode ID=0x00000003 Parent=0xC0DFADC4 SizeRef=1700,1094 Split=X
DockNode ID=0x00000002 Parent=0x00000003 SizeRef=1655,1094 CentralNode=1 Selected=0x9204953B
DockNode ID=0x00000005 Parent=0x00000003 SizeRef=375,1094 Selected=0x9F035453

View File

@ -416,6 +416,8 @@ bool imguiManager::ImGuiWidgetRenderer(ApplicationClass* app)
WidgetEngineSettingsWindow(app); WidgetEngineSettingsWindow(app);
} }
WidgetRenderWindow(app, ImVec2(800, 600));
//render imgui //render imgui
Render(); Render();
@ -475,5 +477,30 @@ void imguiManager::WidgetEngineSettingsWindow(ApplicationClass* app)
app->SetFrustumTolerance(frustumTolerance); app->SetFrustumTolerance(frustumTolerance);
} }
ImGui::End();
}
void imguiManager::WidgetRenderWindow(ApplicationClass* app, ImVec2 availableSize)
{
ImGui::Begin("Render Window");
windowSize = ImGui::GetContentRegionAvail();
app->SetWindowSize(windowSize);
// Assurez-vous que la texture est valide
RenderTextureClass* renderTexture = app->GetRenderTexture();
if (renderTexture)
{
// Obtenez la vue de la ressource shader de la texture rendue
ID3D11ShaderResourceView* texture = renderTexture->GetShaderResourceView();
// Affichez la texture dans une fenêtre ImGui
ImGui::Image((ImTextureID)texture, windowSize);
}
else
{
ImGui::Text("Render texture is not available.");
}
ImGui::End(); ImGui::End();
} }

View File

@ -34,9 +34,13 @@ public:
void WidgetLightWindow(ApplicationClass* app); void WidgetLightWindow(ApplicationClass* app);
void WidgetShaderWindow(ApplicationClass* app); void WidgetShaderWindow(ApplicationClass* app);
void WidgetEngineSettingsWindow(ApplicationClass* app); void WidgetEngineSettingsWindow(ApplicationClass* app);
void WidgetRenderWindow(ApplicationClass* app, ImVec2 availableSize);
bool ImGuiWidgetRenderer(ApplicationClass* app); bool ImGuiWidgetRenderer(ApplicationClass* app);
void SetWindowSize(ImVec2 size) { windowSize = size; }
ImVec2 GetWindowSize() const { return windowSize; }
// Shader toggles // Shader toggles
bool m_EnableCelShading; bool m_EnableCelShading;
@ -54,6 +58,7 @@ private :
ID3D11Device* m_device; ID3D11Device* m_device;
ID3D11DeviceContext* m_deviceContext; ID3D11DeviceContext* m_deviceContext;
ImVec2 windowSize;
}; };