imguiManager et start Fullscreen
This commit is contained in:
parent
e9fda93632
commit
77adeb2872
@ -6,6 +6,7 @@ SystemClass::SystemClass()
|
||||
{
|
||||
m_Input = 0;
|
||||
m_Application = 0;
|
||||
m_imguiManager = 0;
|
||||
}
|
||||
|
||||
SystemClass::SystemClass(const SystemClass& other)
|
||||
@ -27,6 +28,9 @@ bool SystemClass::Initialize()
|
||||
screenWidth = 0;
|
||||
screenHeight = 0;
|
||||
|
||||
// Create and initialize the application class object. This object will handle rendering all the graphics for this application.
|
||||
m_Application = new ApplicationClass;
|
||||
|
||||
// Initialize the windows api.
|
||||
InitializeWindows(screenWidth, screenHeight);
|
||||
|
||||
@ -35,11 +39,6 @@ bool SystemClass::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;
|
||||
|
||||
// Initialize the application object.
|
||||
|
||||
result = m_Application->Initialize(screenWidth, screenHeight, m_hwnd);
|
||||
if (!result)
|
||||
{
|
||||
@ -47,13 +46,8 @@ bool SystemClass::Initialize()
|
||||
}
|
||||
|
||||
// Initialize imgui
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
ImGui_ImplWin32_Init(m_hwnd);
|
||||
ImGui_ImplDX11_Init(m_Application->GetDirect3D()->GetDevice(), m_Application->GetDirect3D()->GetDeviceContext());
|
||||
ImGui::StyleColorsDark();
|
||||
m_imguiManager = new imguiManager;
|
||||
m_imguiManager->Initialize(m_hwnd, m_Application->GetDirect3D()->GetDevice(), m_Application->GetDirect3D()->GetDeviceContext());
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -76,9 +70,12 @@ void SystemClass::Shutdown()
|
||||
}
|
||||
|
||||
// Shutdown imgui
|
||||
ImGui_ImplDX11_Shutdown();
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
if (m_imguiManager)
|
||||
{
|
||||
m_imguiManager->Shutdown();
|
||||
delete m_imguiManager;
|
||||
m_imguiManager = 0;
|
||||
}
|
||||
|
||||
// Shutdown the window.
|
||||
ShutdownWindows();
|
||||
@ -146,20 +143,23 @@ bool SystemClass::Frame()
|
||||
}
|
||||
|
||||
// Start the Dear ImGui frame
|
||||
ImGui_ImplDX11_NewFrame();
|
||||
ImGui_ImplWin32_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
m_imguiManager->NewFrame();
|
||||
|
||||
//ImGui Widget
|
||||
ImGui::Begin("Khaotic Engine", NULL);
|
||||
ImGui::Text("Salam");
|
||||
ImGui::SliderFloat("Slider", &value, 0.0f, 1.0f);
|
||||
|
||||
bool fullscreen = m_Application->GetFullscreen();
|
||||
m_imguiManager->WidgetFullscreenBox(&fullscreen);
|
||||
if (fullscreen != m_Application->GetFullscreen())
|
||||
{
|
||||
m_Application->SetFullscreen(fullscreen);
|
||||
m_Application->GetDirect3D()->SetFullscreen(fullscreen);
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
|
||||
// Assemble Together Draw Data
|
||||
ImGui::Render();
|
||||
// Render Draw Data
|
||||
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
||||
//render imgui
|
||||
m_imguiManager->Render();
|
||||
|
||||
this->m_Application->GetDirect3D()->m_swapChain->Present(0, NULL);
|
||||
|
||||
@ -214,7 +214,7 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
|
||||
m_hinstance = GetModuleHandle(NULL);
|
||||
|
||||
// Give the application a name.
|
||||
m_applicationName = L"Engine";
|
||||
m_applicationName = L"Khaotic Engine";
|
||||
|
||||
// Setup the windows class with default settings.
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
|
||||
@ -238,7 +238,7 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
|
||||
screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||
|
||||
// Setup the screen settings depending on whether it is running in full screen or in windowed mode.
|
||||
if (FULL_SCREEN)
|
||||
if (m_Application->GetFullscreen())
|
||||
{
|
||||
// If full screen set the screen to maximum size of the users desktop and 32bit.
|
||||
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
|
||||
@ -267,7 +267,7 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
|
||||
|
||||
// Create the window with the screen settings and get the handle to it.
|
||||
m_hwnd = CreateWindowEx(WS_EX_APPWINDOW, m_applicationName, m_applicationName,
|
||||
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP,
|
||||
WS_CLIPSIBLINGS | WS_CLIPCHILDREN ,
|
||||
posX, posY, screenWidth, screenHeight, NULL, NULL, m_hinstance, NULL);
|
||||
|
||||
// Bring the window up on the screen and set it as main focus.
|
||||
@ -276,7 +276,7 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
|
||||
SetFocus(m_hwnd);
|
||||
|
||||
// Hide the mouse cursor.
|
||||
ShowCursor(false);
|
||||
ShowCursor(true);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -287,7 +287,7 @@ void SystemClass::ShutdownWindows()
|
||||
ShowCursor(true);
|
||||
|
||||
// Fix the display settings if leaving full screen mode.
|
||||
if (FULL_SCREEN)
|
||||
if (m_Application->GetFullscreen())
|
||||
{
|
||||
ChangeDisplaySettings(NULL, 0);
|
||||
}
|
||||
@ -336,3 +336,24 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SystemClass::SetScreen(bool fullscreen)
|
||||
{
|
||||
if (fullscreen)
|
||||
{
|
||||
DEVMODE dmScreenSettings;
|
||||
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
|
||||
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
|
||||
dmScreenSettings.dmPelsWidth = (unsigned long)GetSystemMetrics(SM_CXSCREEN); // donne la largeur de l'écran en pixel
|
||||
dmScreenSettings.dmPelsHeight = (unsigned long)GetSystemMetrics(SM_CYSCREEN); // donne la hauteur de l'écran en pixel
|
||||
dmScreenSettings.dmBitsPerPel = 32;
|
||||
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
||||
|
||||
|
||||
ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangeDisplaySettings(NULL, 0);
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
||||
// Create and initialize the Direct3D object.
|
||||
m_Direct3D = new D3DClass;
|
||||
|
||||
result = m_Direct3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR);
|
||||
result = m_Direct3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, m_fullscreen, SCREEN_DEPTH, SCREEN_NEAR);
|
||||
if (!result)
|
||||
{
|
||||
MessageBox(hwnd, L"Could not initialize Direct3D", L"Error", MB_OK);
|
||||
@ -157,4 +157,24 @@ bool ApplicationClass::Render()
|
||||
D3DClass* ApplicationClass::GetDirect3D()
|
||||
{
|
||||
return m_Direct3D;
|
||||
}
|
||||
|
||||
void ApplicationClass::SetFullscreen(bool fullscreen)
|
||||
{
|
||||
m_fullscreen = fullscreen;
|
||||
}
|
||||
|
||||
bool ApplicationClass::GetFullscreen() const
|
||||
{
|
||||
return m_fullscreen;
|
||||
}
|
||||
|
||||
int ApplicationClass::GetScreenWidth() const
|
||||
{
|
||||
return GetSystemMetrics(SM_CXSCREEN);
|
||||
}
|
||||
|
||||
int ApplicationClass::GetScreenHeight() const
|
||||
{
|
||||
return GetSystemMetrics(SM_CYSCREEN);
|
||||
}
|
@ -14,7 +14,6 @@
|
||||
/////////////
|
||||
// GLOBALS //
|
||||
/////////////
|
||||
const bool FULL_SCREEN = false;
|
||||
const bool VSYNC_ENABLED = true;
|
||||
const float SCREEN_DEPTH = 1000.0f;
|
||||
const float SCREEN_NEAR = 0.3f;
|
||||
@ -30,6 +29,10 @@ public:
|
||||
bool Initialize(int, int, HWND);
|
||||
void Shutdown();
|
||||
bool Frame();
|
||||
void SetFullscreen(bool fullscreen);
|
||||
bool GetFullscreen() const;
|
||||
int GetScreenWidth() const;
|
||||
int GetScreenHeight() const;
|
||||
|
||||
private:
|
||||
bool Render();
|
||||
@ -40,6 +43,7 @@ private:
|
||||
ModelClass* m_Model;
|
||||
ColorShaderClass* m_ColorShader;
|
||||
IDXGISwapChain* m_swapChain;
|
||||
bool m_fullscreen = false;
|
||||
};
|
||||
|
||||
#endif
|
@ -504,4 +504,139 @@ void D3DClass::ResetViewport()
|
||||
m_deviceContext->RSSetViewports(1, &m_viewport);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void D3DClass::ReleaseResources()
|
||||
{
|
||||
// libere la vue
|
||||
if (m_renderTargetView)
|
||||
{
|
||||
m_renderTargetView->Release();
|
||||
m_renderTargetView = 0;
|
||||
}
|
||||
|
||||
// libere le buffer de profondeur
|
||||
if (m_depthStencilBuffer)
|
||||
{
|
||||
m_depthStencilBuffer->Release();
|
||||
m_depthStencilBuffer = 0;
|
||||
}
|
||||
|
||||
// libere la vue de profondeur
|
||||
if (m_depthStencilView)
|
||||
{
|
||||
m_depthStencilView->Release();
|
||||
m_depthStencilView = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool D3DClass::RecreateResources()
|
||||
{
|
||||
HRESULT result;
|
||||
ID3D11Texture2D* backBufferPtr;
|
||||
D3D11_TEXTURE2D_DESC depthBufferDesc;
|
||||
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
|
||||
|
||||
// Recréez la vue de rendu.
|
||||
result = m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
result = m_device->CreateRenderTargetView(backBufferPtr, NULL, &m_renderTargetView);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
backBufferPtr->Release();
|
||||
backBufferPtr = 0;
|
||||
|
||||
// Recréez le tampon de profondeur et la vue de profondeur.
|
||||
ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc));
|
||||
depthBufferDesc.Width = m_viewport.Width;
|
||||
depthBufferDesc.Height = m_viewport.Height;
|
||||
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;
|
||||
|
||||
result = m_device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));
|
||||
depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
||||
depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
|
||||
depthStencilViewDesc.Texture2D.MipSlice = 0;
|
||||
|
||||
result = m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Liez la vue de rendu et le tampon de profondeur à la pipeline de rendu de sortie.
|
||||
m_deviceContext->OMSetRenderTargets(1, &m_renderTargetView, m_depthStencilView);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool D3DClass::SetFullscreen(bool fullscreen)
|
||||
{
|
||||
HRESULT result;
|
||||
|
||||
ReleaseResources();
|
||||
|
||||
// Definie les options de plein ecran
|
||||
DXGI_MODE_DESC newScreenSize;
|
||||
ZeroMemory(&newScreenSize, sizeof(newScreenSize));
|
||||
newScreenSize.Width = 1920;
|
||||
newScreenSize.Height = 1080;
|
||||
newScreenSize.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
|
||||
// Redimensionne la cible
|
||||
result = m_swapChain->ResizeTarget(&newScreenSize);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Change le mode d'affichage
|
||||
result = m_swapChain->SetFullscreenState(fullscreen, NULL);
|
||||
if (FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Recréez les ressources
|
||||
if (!RecreateResources())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Informez ImGui du changement de taille de la fenêtre
|
||||
ImGui::GetIO().DisplaySize = ImVec2((float)newScreenSize.Width, (float)newScreenSize.Height);
|
||||
|
||||
// Libérez les anciens objets de rendu ImGui
|
||||
ImGui_ImplDX11_InvalidateDeviceObjects();
|
||||
|
||||
// Recréez les objets de rendu ImGui
|
||||
ImGui_ImplDX11_CreateDeviceObjects();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDXGISwapChain* D3DClass::GetSwapChain()
|
||||
{
|
||||
return m_swapChain;
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
//////////////
|
||||
#include <d3d11.h>
|
||||
#include <directxmath.h>
|
||||
#include "imguiManager.h"
|
||||
using namespace DirectX;
|
||||
|
||||
|
||||
@ -40,6 +41,7 @@ public:
|
||||
ID3D11Device* GetDevice();
|
||||
ID3D11DeviceContext* GetDeviceContext();
|
||||
IDXGISwapChain* m_swapChain;
|
||||
IDXGISwapChain* GetSwapChain();
|
||||
|
||||
void GetProjectionMatrix(XMMATRIX&);
|
||||
void GetWorldMatrix(XMMATRIX&);
|
||||
@ -50,6 +52,10 @@ public:
|
||||
void SetBackBufferRenderTarget();
|
||||
void ResetViewport();
|
||||
|
||||
void ReleaseResources();
|
||||
bool SetFullscreen(bool fullscreen);
|
||||
bool RecreateResources();
|
||||
|
||||
private:
|
||||
bool m_vsync_enabled;
|
||||
int m_videoCardMemory;
|
||||
|
@ -24,6 +24,7 @@
|
||||
<ClCompile Include="Cameraclass.cpp" />
|
||||
<ClCompile Include="Colorshaderclass.cpp" />
|
||||
<ClCompile Include="d3dclass.cpp" />
|
||||
<ClCompile Include="imguiManager.cpp" />
|
||||
<ClCompile Include="include\backends\imgui_impl_dx11.cpp" />
|
||||
<ClCompile Include="include\backends\imgui_impl_win32.cpp" />
|
||||
<ClCompile Include="include\imgui.cpp" />
|
||||
@ -41,6 +42,7 @@
|
||||
<ClInclude Include="Cameraclass.h" />
|
||||
<ClInclude Include="Colorshaderclass.h" />
|
||||
<ClInclude Include="d3dclass.h" />
|
||||
<ClInclude Include="imguiManager.h" />
|
||||
<ClInclude Include="include\backends\imgui_impl_dx11.h" />
|
||||
<ClInclude Include="include\backends\imgui_impl_win32.h" />
|
||||
<ClInclude Include="include\imconfig.h" />
|
||||
|
@ -3,6 +3,6 @@ Pos=60,60
|
||||
Size=400,400
|
||||
|
||||
[Window][Khaotic Engine]
|
||||
Pos=137,66
|
||||
Size=144,109
|
||||
Pos=59,59
|
||||
Size=694,353
|
||||
|
||||
|
48
enginecustom/imguiManager.cpp
Normal file
48
enginecustom/imguiManager.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "imguiManager.h"
|
||||
|
||||
imguiManager::imguiManager()
|
||||
{
|
||||
io = nullptr;
|
||||
}
|
||||
|
||||
imguiManager::~imguiManager()
|
||||
{
|
||||
}
|
||||
|
||||
bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* deviceContext)
|
||||
{
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
io = &ImGui::GetIO();
|
||||
|
||||
ImGui_ImplWin32_Init(hwnd);
|
||||
ImGui_ImplDX11_Init(device, deviceContext);
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void imguiManager::Shutdown()
|
||||
{
|
||||
ImGui_ImplDX11_Shutdown();
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
void imguiManager::Render()
|
||||
{
|
||||
ImGui::Render();
|
||||
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
||||
}
|
||||
|
||||
void imguiManager::NewFrame()
|
||||
{
|
||||
ImGui_ImplDX11_NewFrame();
|
||||
ImGui_ImplWin32_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
void imguiManager::WidgetFullscreenBox(bool* fullscreen)
|
||||
{
|
||||
ImGui::Checkbox("Fullscreen", fullscreen);
|
||||
}
|
26
enginecustom/imguiManager.h
Normal file
26
enginecustom/imguiManager.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#ifndef _IMGUI_MANAGER_H_
|
||||
#define _IMGUI_MANAGER_H_
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_dx11.h>
|
||||
#include <imgui_impl_win32.h>
|
||||
#include <windows.h>
|
||||
|
||||
class imguiManager
|
||||
{
|
||||
public:
|
||||
imguiManager();
|
||||
~imguiManager();
|
||||
|
||||
bool Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* deviceContext);
|
||||
void Shutdown();
|
||||
void Render();
|
||||
void NewFrame();
|
||||
void WidgetFullscreenBox(bool* fullscreen);
|
||||
|
||||
private:
|
||||
ImGuiIO* io;
|
||||
};
|
||||
|
||||
#endif
|
@ -2,12 +2,9 @@
|
||||
#define _SYSTEMCLASS_H_
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <windows.h>
|
||||
#include "inputclass.h"
|
||||
#include "applicationclass.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_win32.h"
|
||||
#include "imgui_impl_dx11.h"
|
||||
#include "imguiManager.h"
|
||||
|
||||
class SystemClass
|
||||
{
|
||||
@ -19,6 +16,7 @@ public:
|
||||
bool Initialize();
|
||||
void Shutdown();
|
||||
void Run();
|
||||
void SetScreen(bool fullscreen);
|
||||
|
||||
LRESULT CALLBACK MessageHandler(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
@ -34,6 +32,7 @@ private:
|
||||
|
||||
InputClass* m_Input;
|
||||
ApplicationClass* m_Application;
|
||||
imguiManager* m_imguiManager;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user