Source Code Download URL(ENG)
https://github.com/ocornut/imgui
▲ docking branch 사용시 멀티뷰포트 기능 사용가능
Multi Viewports Document URL(ENG)
https://github.com/ocornut/imgui/wiki/Multi-Viewports
FAQ Document URL(ENG)
1.다운로드한 폴더에서 해당 파일들을 Project 폴더로 복사
imconfig.h
imgui.h
imgui.cpp
imgui_internal.cpp
imgui_draw.cpp
imgui_table.cpp
imgui_widgets.cpp
//stb 라이브러리(stb란 헤더만 있어도 작동하는 단일 라이브러리를 의미)
imstb_rectpack.h
imstb_textedit.h
imstb_truetype.h
2./Backends 폴더에서 필요한 파일들(Platform & Graphic)을 Project 폴더로 복사
//운영체제 프로그램 메시지를 Imgui 로직에 전달하는 소스
imgui_impl_win32.h
imgui_impl_win32.cpp
//Imgui의 드로우 리스트를 그려주는 렌더 소스
imgui_impl_dx11.h
imgui_impl_dx11.cpp << 하단 3개의 라이브러리를 #ifdef _MSC_VER 전처리 블럭에 작성할 것(프로젝트에 추가되어 있다면 상관없음)
#pragma comment(lib,"d3d11.lib")
#pragma comment(lib,"dxgi.lib")
#pragma comment(lib, "d3dcompiler.lib")
3.해당 파일들을 생성
main.cpp
{module}.cpp
main.cpp
//헤더포함
//전방선언, 전역변수
//프로시져 선언(백엔드 헤더에 존재)
extern IMGUI_IMPL_API LRESULT ImGui_Impl_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
int main(int, char**)함수 진입후
일반적인 Window, Graphic 생성하기
ImGui초기화 시작
ImGuiIO& io = ImGui::GetIO(); //싱글턴생성(멀티 뷰포트 사용시 플래그 변경)
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
ImGUi Font 로드
ImGui Style 설정
ImGui Backend impl(Platform, Graphic)초기화 전달
ex)WindowOS + DX11의 경우
ImGui_ImplWin32_Init(g_HWnd);
ImGui_ImplDX11_Init(g_Device, g_DeviceContext);
ImGui 컨트롤 플래그 변수 생성 및 초기화.
ImGuiLoop 시작
Window Msg 처리후
ImGui_ProcHandler(메시지)전달후에 어플리케이션 메시지 PROC전달해야함.
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
(IMGUI 구현하기) + {Module}Tool
사용자의 ImGui 라이브러리를 이용한 Render 로직;
ImGui::Render();
const float clear_color_with_alpha[4] = { 1.f, 1.f, 1.f, 1.f };
d3dDeviceContext->OMSetRenderTargets(1, &mainRenderTargetView, NULL);
d3dDeviceContext->ClearRenderTargetView(mainRenderTargetView, clear_color_with_alpha);
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
//멀티 뷰포트 사용시 추가
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}
mainSwapChain->Present(1, 0);
MainLoop 종료
ImGui_ImplDX11_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
일반적인 Window, Graphic 해제하기
Module.h
class IImGuiModuleListener
{
public:
virtual void AddListener();//ImGuiModuleManager에 등록구현
virtual void RemoveListener();//ImGuiModuleManager에서 제거구현
virtual void Render();//ImGui 렌더로직 구현
}
class ImGuiModuleManager
{
public:
static std::list<IImGuiModuleListener> m_InterfaceModuleListeners;
}
Module.cpp
Module Render 기본 규칙
void Render(bool* active = 0)
{
//정적 변수로 컨트롤&플래그 생성 및 초기화
if(ImGui::Begin("ID",active,flags))//성공시
{
//GUI Contents
ImGui::End();
}
}
GUIContents Render 이해
렌더 함수 (표현)
컨트롤 함수 (변수 변경, 직접 브랜치)
main.cpp
// Create a Dear ImGui context, setup some options
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();//Singleton Create Instance.
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable some options
// Initialize Platform + Renderer backends (here: using imgui_impl_win32.cpp + imgui_impl_dx11.cpp)
ImGui_ImplWin32_Init(my_hwnd);
ImGui_ImplDX11_Init(my_d3d_device, my_d3d_device_context);
// Application main loop
static bool done = false;
while (!done)
{
while(windowMessage)
{
ImGui_ProcHandler()처리
}
// Beginning of frame: update Renderer + Platform backend, start Dear ImGui frame
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
// Any application code here
ImGui::Text("Hello, world!");//Default Debug Window Create
// End of frame: render Dear ImGui
ImGui::Render();
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
// Swap
g_pSwapChain->Present(1, 0);
}
// Shutdown
ImGui_ImplDX11_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
```