目录

Dx系列教程1

Dx系列教程1

  • ImGui的基础使用

  • ImGui主题配置

  • ImGui字体资源使用

  • 实现目标:配置一个ImGui样式,加载自己喜欢的字体,关闭ImGui的布局保存文件

    https://cdn.jsdelivr.net/gh/xinqinew/pic@main/img/bsijdHW83WJT8756t1u70q-A3CelflximTtS4LAR9EZzOMN2Clc7A4JPYrP4aGq-zMmYISrhBoHtmDHrXi1Vw-ZnQWxaMsgJ3hcCz_KMqJvmxa6-ddwACS0HLYLXvBl1Lb8qJposKysLEUWVy9U.png

Step1:下载ImGui源码

https://github.com/ocornut/imgui

https://cdn.jsdelivr.net/gh/xinqinew/pic@main/img/tJUth8KQZ0eXFQABtp7Vn7ZcNGPKvr4A3N9gX0yPg3vDvgQnFRiZfwwESfOJ2FAAETsgAjLhXRfAchlT8UDvs3-ChMqsJrcvE9BVlVrO40zNpq7sHh0U0Al2deSp7DhVjhpI7ANsc0NNInq4dwA-20220218093733494.png

Step2:打开imgui-master\examples\example_win32_directx11 目录

https://cdn.jsdelivr.net/gh/xinqinew/pic@main/img/6xC4rSvyzYZgX0ujBp4Bumf4SYGDSgxBqo_0hCWJzrMfynnzYvJ19AJA4U5T2IJqb4Ucys9GAIrVu6EianR3T8pEgFok-y7ZH47mzl_6_B_ZTw6iiFkwCW0RgpoESsnCebOSXCbBJN463oVEKxI.png

Step3:运行ImGui官方Demo

https://cdn.jsdelivr.net/gh/xinqinew/pic@main/img/LeOl1VLsecsbQG1AUFT0kbMxBAlqpyRV66H1cBEj4CICWoMiUu7FGLjhu8SuLInOoabf8haPnBlejQ2D56HYVOOIx3qNMathrEIRphc54qvJ62cFJe85Ch8fjC_ZXbLfDP0gDYL34qaC38vyO0w-20220218093749195.png

​ 提示 :导入以下两个文件,尽量配置自己的风格

https://cdn.jsdelivr.net/gh/xinqinew/pic@main/img/U-3Rh8PA8rUgLD0dQN7qSaFMmhY5eLT07SdvFDLlFuXXX3jqvmytMSm0nRIICQC52axKIb6jTTG0zA4csZaLwIQ2rMcEh33ZpKrzwPtQZeTBSI58-7DTCcIcMxeTIFYZmkUQleUlO2snDc26MgU.png

https://cdn.jsdelivr.net/gh/xinqinew/pic@main/img/q_MDgM63JxDT9pmZ0OZR0UvmICsQsydLoxvQld2LG97B5jjbpRICJQ6LOPjZ414yFgzFkWyZ9DVymNOV8U5qJjIIWTAZPh5waUJhoXOPFdWkrAhbACe3PAd3EIL-FSJJPs4ewHWQaexrRtlev8U.png

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//默认字体配置方式
ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\msyh.ttc", 18.0f, NULL, io.Fonts->GetGlyphRangesChineseFull());
//内存字体配置方式
ImFont* font = io.Fonts->AddFontFromMemoryTTF((void*)baidu_font_data, baidu_font_size, 18.0f, NULL, io.Fonts->GetGlyphRangesChineseFull());
//我的字体样式
inline static void LoadMyStype() {
  ImGuiStyle* style = &ImGui::GetStyle();
  
  style->WindowPadding = ImVec2(5, 5); 
  style->WindowRounding = 0.0f; 
  style->WindowBorderSize = 0.0f;
  
  style->FramePadding = ImVec2(5, 5);  
  style->FrameRounding = 0.0f;  
  style->ItemSpacing = ImVec2(12, 8); 
  style->ItemInnerSpacing = ImVec2(8, 6);  
  style->IndentSpacing = 25.0f; 
  style->ScrollbarSize = 15.0f;  
  style->ScrollbarRounding = 9.0f;  
  style->GrabMinSize = 5.0f;  
  style->GrabRounding = 3.0f; 
  style->ScrollbarRounding = 0.0f;
  
  style->Colors[ImGuiCol_Text] = ImVec4(0.80f, 0.80f, 0.83f, 1.00f); 
  style->Colors[ImGuiCol_TextDisabled] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f); 
  style->Colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f); 
  style->Colors[ImGuiCol_ChildBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);  
  style->Colors[ImGuiCol_PopupBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);  
  /*style->Colors[ImGuiCol_Border] = ImVec4(0.80f, 0.80f, 0.83f, 0.88f); 
  style->Colors[ImGuiCol_BorderShadow] = ImVec4(0.92f, 0.91f, 0.88f, 0.00f);*/ 
  style->Colors[ImGuiCol_FrameBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f); 
  style->Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f);  
  style->Colors[ImGuiCol_FrameBgActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);  
  style->Colors[ImGuiCol_TitleBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);  
  style->Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 0.98f, 0.95f, 0.75f);
  style->Colors[ImGuiCol_TitleBgActive] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);  
  style->Colors[ImGuiCol_MenuBarBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);  
  style->Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);  
  style->Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f); 
  style->Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 
  style->Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);  
  style->Colors[ImGuiCol_CheckMark] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f); 
  style->Colors[ImGuiCol_SliderGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f);  
  style->Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);  
  style->Colors[ImGuiCol_Button] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f); 
  style->Colors[ImGuiCol_ButtonHovered] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f);
  style->Colors[ImGuiCol_ButtonActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 
  style->Colors[ImGuiCol_Header] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);  
  style->Colors[ImGuiCol_HeaderHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
  style->Colors[ImGuiCol_HeaderActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);  
  //style->Colors[ImGuiCol_Column] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);  
  //style->Colors[ImGuiCol_ColumnHovered] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f);  
  //style->Colors[ImGuiCol_ColumnActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);  
  style->Colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); 
  style->Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
  style->Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);  
  style->Colors[ImGuiCol_PlotLines] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f); 
  style->Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);  
  style->Colors[ImGuiCol_PlotHistogram] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f);  
  style->Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f); 
  style->Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.25f, 1.00f, 0.00f, 0.43f);  
  style->Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(1.00f, 0.98f, 0.95f, 0.73f);
}