docking imgui: https://github.com/TheCherno/imgui/tree/docking
完整代码:https://github.com/DXT00/Hazel_study/tree/4a155df403a50ecb9700aa7b941ae8411da2edc9
存在这样一个问题:
ImGui是静态lib-->Hazel是dll---->Sandbox是.exe
当Sanbox想要使用ImGui时链接会失败!因为ImGui的接口并没有暴露在Hazel.dll中!Sanbox想要使用不在Hazel.dll的函数就会导致链接失败
运行以下Sandbox.cpp
#include <Hazel.h>
#include "imgui/imgui.h"
class ExampleLayer : public Hazel::Layer
{
public:
ExampleLayer()
: Layer("Example")
{
}
void OnUpdate() override
{
if (Hazel::Input::IsKeyPressed(HZ_KEY_TAB))
HZ_TRACE("Tab key is pressed (poll)!");
}
virtual void OnImGuiRender() override
{
ImGui::Begin("Test");
ImGui::Text("Hello World");
ImGui::End();
}
void OnEvent(Hazel::Event& event) override
{
if (event.GetEventype() == Hazel::EventType::KeyPressed)
{
Hazel::KeyPressedEvent& e = (Hazel::KeyPressedEvent&)event;
if (e.GetKeyCode() == HZ_KEY_TAB)
HZ_TRACE("Tab key is pressed (event)!");
HZ_TRACE("{0}", (char)e.GetKeyCode());
}
}
};
class Sandbox : public Hazel::Application
{
public:
Sandbox()
{
PushLayer(new ExampleLayer());
}
~Sandbox()
{
}
};
Hazel::Application* Hazel::CreateApplication()
{
return new Sandbox();
}
出现错误:
解决方法1:
把ImGui 函数导出到Hazel.dll
可以看到ImGui的所有函数前都有IMGUI_API这个宏
所以我们可以这样的定义:
编译一下ImGui生成 .lib
修改Hazel和ImGui 预编译:
修改SandBox预编译:
F5成功运行:
解决方法2:
module file, .def file
Hazel.def -->have all the function that we want to export from imgui