背景:有时候kanzi运行后节点不显示,可能是visible/opacity等属性设置不正确,排查困难。做一个实时节点树,方便查看节点信息。
1. 引入imgui
在vs工程里导入glad
,glfw
,imgui
代码
vs属性-链接库,增加glfw3.lib
2. 实现框架
在onProjectLoaded
里创建子线程
CreateThread(NULL, 0, multiTask, 0, 0, NULL);
子线程负责创建glfw
窗口,刷新,销毁窗口
DWORD WINAPI multiTask(LPVOID p) {
FCreateWindow();
while (!glfwWindowShouldClose(m_Window)) {
Update();
}
Destory();
return 0;
};
2.1 创建窗口
void FCreateWindow() {
glfwInit();
const char* glsl_version = "#version 130";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
m_Window = glfwCreateWindow(m_WindowWidth, m_WindowHeight, "Xml", nullptr, nullptr);
glfwMakeContextCurrent(m_Window);
glfwSwapInterval(1); // Enable vsync
int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
printf("status-%d\n", status);
printf("Vendor-%s\n", glGetString(GL_VENDOR));
printf("Renderer-%s\n", glGetString(GL_RENDERER));
printf("Version-%s\n", glGetString(GL_VERSION));
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO();
(void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
// io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
// io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
// io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
float fontSize = 18.0f; // *2.0f;
io.Fonts->AddFontFromFileTTF(("./font/Alimama_DongFangDaKai_Regular.ttf"), fontSize, NULL, io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
io.FontDefault = io.Fonts->AddFontFromFileTTF(("./font/Alimama_DongFangDaKai_Regular.ttf"), fontSize, NULL, io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsClassic();
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
ImGuiStyle &style = ImGui::GetStyle();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
style.WindowRounding =