MinGW g++ 单独编译 Box2d 示例程序 Testbed
在1楼的基础上继续编译 Testbed 演示程序,box2d 静态库位于 Box2D-master\Box2D\Box2D\libBox2D.a
考虑到2楼因项目自带的 glfw 引起的各种编译失败,所以建议 glew 和 glfw 库单独到官网下载编译,
配置过程参考:
MinGW+OpenGL+freeglut+glew+glfw 环境配置
进入 Box2D-master\Box2D\Testbed\Framework
g++ 编译指令
g++ -std=c++11 -o testbed.exe Main.cpp imgui.cpp imgui_demo.cpp imgui_draw.cpp ^
imgui_impl_glfw_gl3.cpp DebugDraw.cpp test.cpp ../Tests/TestEntries.cpp ^
-I. -I../../ -L../../box2d/ ^
-ID:\Lib\glfw-3.1.1\include ^
-LD:\Lib\glfw-3.1.1\lib ^
-ID:\Lib\glew-2.0.0\include ^
-LD:\Lib\glew-2.0.0\lib ^
-lglew32 -lglfw3 -lopengl32 -lbox2d -lgdi32 -limm32
我也实在懒得写出错和修改的过程,概括一下,-lgdi32 和 -limm32 等大部分链接参数都是根据错误提示逐个追加上去的,
imgui 库比较简单,全部源文件 和 main.cpp 叠在一起编译。缺什么补什么。
编译无误,终端执行 testbed.exe 提示:
testbed.exe - 系统错误
无法启动此程序,因为计算机中丢失 glew32.dll
找到 glew32.dll 复制到运行环境,再次执行,弹窗,终端提示:
OpenGL 4.5.0 NVIDIA 353.62, GLSL 4.50 NVIDIA
Assertion failed!
Program: C:\Users\Vulkan\Desktop\box2d comp1\Box2D\Testbed\Framework\testbed.exe
File: imgui_draw.cpp, Line 1171
Expression: 0
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
找到对应文件位置
ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges)
{
int data_size = 0;
void* data = ImLoadFileToMemory(filename, "rb", &data_size, 0);
if (!data)
{
IM_ASSERT(0); // Could not load file.
return NULL;
}
通过 grep 往上追溯:
$ grep -R "AddFontFromFileTTF" *
Framework/Main.cpp: ImGui::GetIO().Fonts->AddFontFromFileTTF(fontPath, 15.f);
$ grep -R "fontPath" *
Framework/Main.cpp: const char* fontPath = "../Data/DroidSans.ttf";
原因是未找到对应字体文件,将 Box2D-master\Box2D\Build\Data 目录复制到 Box2D-master\Box2D\Testbed
运行程序:
[image 460, 320]
http://imgout.ph.126.net/52904014/testbed.jpg[/image]