IMGUI라이브러리를 사용하기 위한 소스코드를 가져오기
ImGuiGithub에서 소스코드 다운받기
Imgui-master폴더와 Imgui-master/backends폴더에서 해당 소스코드 가져오기
ImGui 마우스입력 처리
Game::WndProc()에서 ImGui_ImplWin32_WndProcHandler()함수 추가
Game.cpp
LRESULT CALLBACK Game::WndProc(HWND handle, UINT message, WPARAM wParam, LPARAM lParam)
{
if (ImGui_ImplWin32_WndProcHandler(handle, message, wParam, lParam))
return true;
switch (message)
{
case WM_SIZE:
break;
case WM_CLOSE:
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return ::DefWindowProc(handle, message, wParam, lParam);
}
}
ImGui를 자유롭게 사용하도록 Manager 생성
- 매번 ImGui를 사용할때마다
Init과, Update, Render를 사용할 클래스에다가 적용해주기는 힘들어서 Singleton으로 생성해서 만들기
ImGuiManager.h
#pragma once
class ImGuiManager
{
DECLARE_SINGLE(ImGuiManager);
public:
void Init();
void Update();
void Render();
};
ImGuiManager.cpp
#include "pch.h"
#include "ImGuiManager.h"
void ImGuiManager::Init()
{
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
ImGui::StyleColorsDark();
ImGui_ImplWin32_Init(GAME->GetGameDesc().hWnd);
ImGui_ImplDX11_Init(DEVICE.Get(), DC.Get());
}
void ImGuiManager::Update()
{
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
}
void ImGuiManager::Render()
{
ImGui::Render();
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
}
Game.cpp
WPARAM Game::Run(GameDesc& desc)
{
_desc = desc;
assert(_desc.app != nullptr);
MyRegisterClass();
if (!InitInstance(SW_SHOWNORMAL))
return FALSE;
GRAPHICS->Init(_desc.hWnd);
TIME->Init();
INPUT->Init(_desc.hWnd);
GUI->Init();
_desc.app->Init();
MSG msg = { 0 };
while (msg.message != WM_QUIT)
{
if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
else
{
Update();
}
}
return msg.wParam;
}
void Game::Update()
{
TIME->Update();
INPUT->Update();
GRAPHICS->RenderBegin();
GUI->Update();
_desc.app->Update();
_desc.app->Render();
GUI->Render();
GRAPHICS->RenderEnd();
}
ImGuiDemo.cpp
#include "pch.h"
#include "ImGuiDemo.h"
void ImGuiDemo::Init() { }
void ImGuiDemo::Update()
{
Test();
}
void ImGuiDemo::Render() { }
void ImGuiDemo::Test()
{
if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);
{
static float f = 0.0f;
static int counter = 0;
ImGui::Begin("Hello, world!");
ImGui::Text("This is some useful text.");
ImGui::Checkbox("Demo Window", &show_demo_window);
ImGui::Checkbox("Another Window", &show_another_window);
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
ImGui::ColorEdit3("clear color", (float*)&clear_color);
if (ImGui::Button("Button"))
counter++;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);
ImGui::End();
}
{
static float f = 0.0f;
static int counter = 0;
ImGui::Begin("Hello, world!2");
if (ImGui::CollapsingHeader("Hello"))
{
ImGui::Text("Hi");
}
ImGui::End();
}
if (show_another_window)
{
ImGui::Begin("Another Window", &show_another_window);
ImGui::Text("Hello from another window!");
if (ImGui::Button("Close Me"))
show_another_window = false;
ImGui::End();
}
}
결과

참고 강의
https://www.inflearn.com/courses/lecture?courseId=329791&type=LECTURE&unitId=161143&tab=curriculum&subtitleLanguage=ko