Maximize screen
pas finie, par fois ça crash au démarrage
This commit is contained in:
parent
05e5959cb1
commit
47717f1755
@ -27,24 +27,35 @@ bool SystemClass::Initialize()
|
|||||||
// Initialize the width and height of the screen to zero before sending the variables into the function.
|
// Initialize the width and height of the screen to zero before sending the variables into the function.
|
||||||
screenWidth = 0;
|
screenWidth = 0;
|
||||||
screenHeight = 0;
|
screenHeight = 0;
|
||||||
|
|
||||||
// Create and initialize the application class object. This object will handle rendering all the graphics for this application.
|
m_initialWindowWidth = 0;
|
||||||
m_Application = new ApplicationClass;
|
m_initialWindowHeight = 0;
|
||||||
|
m_isDirect3DInitialized = false;
|
||||||
|
|
||||||
// Initialize the windows api.
|
// Initialize the windows api.
|
||||||
InitializeWindows(screenWidth, screenHeight);
|
InitializeWindows(screenWidth, screenHeight);
|
||||||
|
|
||||||
// Create and initialize the input object. This object will be used to handle reading the keyboard input from the user.
|
// Create and initialize the input object. This object will be used to handle reading the keyboard input from the user.
|
||||||
m_Input = new InputClass;
|
m_Input = new InputClass;
|
||||||
|
|
||||||
m_Input->Initialize();
|
m_Input->Initialize();
|
||||||
|
|
||||||
|
// 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);
|
result = m_Application->Initialize(screenWidth, screenHeight, m_hwnd);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
return false;
|
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
|
// Initialize imgui
|
||||||
m_imguiManager = new imguiManager;
|
m_imguiManager = new imguiManager;
|
||||||
m_imguiManager->Initialize(m_hwnd, m_Application->GetDirect3D()->GetDevice(), m_Application->GetDirect3D()->GetDeviceContext());
|
m_imguiManager->Initialize(m_hwnd, m_Application->GetDirect3D()->GetDevice(), m_Application->GetDirect3D()->GetDeviceContext());
|
||||||
@ -188,6 +199,22 @@ LRESULT CALLBACK SystemClass::MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam
|
|||||||
m_Input->KeyUp((unsigned int)wparam);
|
m_Input->KeyUp((unsigned int)wparam);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
case WM_SIZE:
|
||||||
|
{
|
||||||
|
int newWidth = LOWORD(lparam);
|
||||||
|
int newHeight = HIWORD(lparam);
|
||||||
|
|
||||||
|
// If Direct3D is initialized, update the swap chain. Otherwise, store the window dimensions
|
||||||
|
if (m_isDirect3DInitialized && m_Application && m_Application->GetDirect3D())
|
||||||
|
{
|
||||||
|
m_Application->GetDirect3D()->ResizeSwapChain(newWidth, newHeight);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_initialWindowWidth = newWidth;
|
||||||
|
m_initialWindowHeight = newHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Any other messages send to the default message handler as our application won't make use of them.
|
// Any other messages send to the default message handler as our application won't make use of them.
|
||||||
default:
|
default:
|
||||||
@ -264,7 +291,7 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
|
|||||||
|
|
||||||
// Create the window with the screen settings and get the handle to it.
|
// Create the window with the screen settings and get the handle to it.
|
||||||
m_hwnd = CreateWindowEx(WS_EX_APPWINDOW, m_applicationName, m_applicationName,
|
m_hwnd = CreateWindowEx(WS_EX_APPWINDOW, m_applicationName, m_applicationName,
|
||||||
WS_CLIPSIBLINGS | WS_CLIPCHILDREN ,
|
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
|
||||||
posX, posY, screenWidth, screenHeight, NULL, NULL, m_hinstance, NULL);
|
posX, posY, screenWidth, screenHeight, NULL, NULL, m_hinstance, NULL);
|
||||||
|
|
||||||
// Bring the window up on the screen and set it as main focus.
|
// Bring the window up on the screen and set it as main focus.
|
||||||
|
@ -26,7 +26,6 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
|||||||
char textureFilename[128];
|
char textureFilename[128];
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
|
|
||||||
// Create the Direct3D object.
|
// Create the Direct3D object.
|
||||||
m_Direct3D = new D3DClass;
|
m_Direct3D = new D3DClass;
|
||||||
if (!m_Direct3D)
|
if (!m_Direct3D)
|
||||||
|
@ -593,4 +593,60 @@ bool D3DClass::RecreateResources()
|
|||||||
IDXGISwapChain* D3DClass::GetSwapChain()
|
IDXGISwapChain* D3DClass::GetSwapChain()
|
||||||
{
|
{
|
||||||
return m_swapChain;
|
return m_swapChain;
|
||||||
|
}
|
||||||
|
|
||||||
|
void D3DClass::ResizeSwapChain(int newWidth, int newHeight)
|
||||||
|
{
|
||||||
|
HRESULT result;
|
||||||
|
|
||||||
|
// Release existing DirectX resources
|
||||||
|
m_renderTargetView->Release();
|
||||||
|
m_depthStencilBuffer->Release();
|
||||||
|
|
||||||
|
// Resize the swap chain
|
||||||
|
m_swapChain->ResizeBuffers(0, newWidth, newHeight, DXGI_FORMAT_UNKNOWN, 0);
|
||||||
|
if (FAILED(m_swapChain))
|
||||||
|
{
|
||||||
|
MessageBox(NULL, L"Failed to resize swap chain buffers", L"Error", MB_OK);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recreate the render target view
|
||||||
|
ID3D11Texture2D* backBuffer;
|
||||||
|
m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBuffer);
|
||||||
|
m_device->CreateRenderTargetView(backBuffer, NULL, &m_renderTargetView);
|
||||||
|
backBuffer->Release();
|
||||||
|
|
||||||
|
// Recreate the depth/stencil buffer and view
|
||||||
|
D3D11_TEXTURE2D_DESC depthBufferDesc;
|
||||||
|
ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc));
|
||||||
|
depthBufferDesc.Width = newWidth;
|
||||||
|
depthBufferDesc.Height = newHeight;
|
||||||
|
depthBufferDesc.MipLevels = 1;
|
||||||
|
depthBufferDesc.ArraySize = 1;
|
||||||
|
depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
||||||
|
depthBufferDesc.SampleDesc.Count = 1;
|
||||||
|
depthBufferDesc.SampleDesc.Quality = 0;
|
||||||
|
depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||||
|
depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
||||||
|
depthBufferDesc.CPUAccessFlags = 0;
|
||||||
|
depthBufferDesc.MiscFlags = 0;
|
||||||
|
|
||||||
|
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
|
||||||
|
ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));
|
||||||
|
depthStencilViewDesc.Format = depthBufferDesc.Format;
|
||||||
|
depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
|
||||||
|
depthStencilViewDesc.Texture2D.MipSlice = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// Other depthStencilDesc settings...
|
||||||
|
m_device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer);
|
||||||
|
m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
|
||||||
|
|
||||||
|
// Set the new render target and depth/stencil views for rendering
|
||||||
|
m_deviceContext->OMSetRenderTargets(1, &m_renderTargetView, m_depthStencilView);
|
||||||
|
// Update the viewport
|
||||||
|
m_viewport.Width = static_cast<float>(newWidth);
|
||||||
|
m_viewport.Height = static_cast<float>(newHeight);
|
||||||
|
m_deviceContext->RSSetViewports(1, &m_viewport);
|
||||||
}
|
}
|
@ -42,6 +42,7 @@ public:
|
|||||||
ID3D11DeviceContext* GetDeviceContext();
|
ID3D11DeviceContext* GetDeviceContext();
|
||||||
IDXGISwapChain* m_swapChain;
|
IDXGISwapChain* m_swapChain;
|
||||||
IDXGISwapChain* GetSwapChain();
|
IDXGISwapChain* GetSwapChain();
|
||||||
|
void ResizeSwapChain(int, int);
|
||||||
|
|
||||||
void GetProjectionMatrix(XMMATRIX&);
|
void GetProjectionMatrix(XMMATRIX&);
|
||||||
void GetWorldMatrix(XMMATRIX&);
|
void GetWorldMatrix(XMMATRIX&);
|
||||||
|
@ -3,6 +3,6 @@ Pos=60,60
|
|||||||
Size=400,400
|
Size=400,400
|
||||||
|
|
||||||
[Window][Khaotic Engine]
|
[Window][Khaotic Engine]
|
||||||
Pos=31,27
|
Pos=21,21
|
||||||
Size=694,367
|
Size=694,367
|
||||||
|
|
||||||
|
@ -60,4 +60,9 @@ void imguiManager::WidgetButton()
|
|||||||
void imguiManager::WidgetFPS()
|
void imguiManager::WidgetFPS()
|
||||||
{
|
{
|
||||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io->Framerate, io->Framerate);
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io->Framerate, io->Framerate);
|
||||||
|
}
|
||||||
|
|
||||||
|
void imguiManager::WidgetFullscreen(bool* fullscreen)
|
||||||
|
{
|
||||||
|
ImGui::Checkbox("Fullscreen", fullscreen);
|
||||||
}
|
}
|
@ -22,6 +22,7 @@ public:
|
|||||||
void WidgetSpeedSlider(float* speed);
|
void WidgetSpeedSlider(float* speed);
|
||||||
void WidgetButton();
|
void WidgetButton();
|
||||||
void WidgetFPS();
|
void WidgetFPS();
|
||||||
|
void WidgetFullscreen(bool* fullscreen);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ImGuiIO* io;
|
ImGuiIO* io;
|
||||||
|
@ -32,6 +32,10 @@ private:
|
|||||||
InputClass* m_Input;
|
InputClass* m_Input;
|
||||||
ApplicationClass* m_Application;
|
ApplicationClass* m_Application;
|
||||||
imguiManager* m_imguiManager;
|
imguiManager* m_imguiManager;
|
||||||
|
|
||||||
|
int m_initialWindowWidth;
|
||||||
|
int m_initialWindowHeight;
|
||||||
|
bool m_isDirect3DInitialized;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user