该内容选自DX12课程第十五周直播。本节讲解如何关联ImGui到自己的自研引擎内.
以下是相关源码:
初始化
//版本检测
IMGUI_CHECKVERSION();
//主要加载ImGUI配置(Ini)相关的操作
ImGui::CreateContext();
//元件的颜色初始化
ImGui::StyleColorsDark();
//win32初始化 加载对应的DLL和初始化时间等
ImGui_ImplWin32_Init(GetMianWindowsHandle());
UINT CBVDescriptorSize = GetDescriptorHandleIncrementSizeByCBV_SRV_UAV();
auto CPUDescriptor =
CD3DX12_CPU_DESCRIPTOR_HANDLE(
InHeap->GetCPUDescriptorHandleForHeapStart(),
InOffset, CBVDescriptorSize);
auto GPUDescriptor =
CD3DX12_GPU_DESCRIPTOR_HANDLE(
InHeap->GetGPUDescriptorHandleForHeapStart(),
InOffset,
CBVDescriptorSize);
//初始化后台数据 注册对应的驱动和帧数
ImGui_ImplDX12_Init(
GetD3dDevice().Get(),1,
DXGI_FORMAT_R8G8B8A8_UNORM,InHeap,
CPUDescriptor,
GPUDescriptor);
渲染
//构建PSO(根签名 shader 输入布局) 构建字体
ImGui_ImplDX12_NewFrame();
//初始化 视口 手柄 鼠标移动 帧时间
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
//绘制
Tick(DeltaTime);
ImGui::Render();
ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), GetGraphicsCommandList().Get());
退出
ImGui_ImplDX12_Shutdown();
ImGui_ImplWin32_Shutdown();
tick(接通上层逻辑)
void FIMGUIPipeline::Tick(float DeltaTime)
{
bool show_demo_window = true;
ImGui::ShowDemoWindow(&show_demo_window);//学习案例
//ImGui::Begin("Log System");
//ImGui::Text("asdioakd asd madm askld asd alsd masd .");
//ImGui::SetWindowPos(ImVec2(0,0),ImGuiCond_Always);
//ImGui::SetWindowSize(ImVec2(ImGui::GetIO().DisplaySize.x / 2.f, ImGui::GetIO().DisplaySize.y / 2.f));
//ImGui::Checkbox("bHeight",&bClicked);
//ImGui::SliderFloat("Hello",&fff,0.f,1.f);
//ImGui::ColorEdit3("Color",(float*)&CCC);
//ImGui::End();
}
以上内容希望对大家有帮助。