14

OpenGL Mac开发-如何使用imgui(1.89.4)插件进行调试 - 星门

 2 years ago
source link: https://www.cnblogs.com/cangxw/p/17279430.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

OpenGL Mac开发-如何使用imgui(1.89.4)插件进行调试

2023-04-01 21:23  星门  阅读(32)  评论(0)  编辑  收藏  举报

为了调试我们的OpenGL Demo,可以尝试使用一个成熟的开源GUI插件imgui。

1,首先进入imgui在github上的地址

在Release中下载最近的版本,可以得到一个Zip压缩包。

现在是2023年的4月1日,我下载到的版本是1.89.4,与Cherno的OpenGL教程中的代码略微有些区别。如果你看的是Cherno的教程,也可以尝试下载1.60版本,并按照Cherno的代码来。

2,Zip包解压后,首先将根目录的代码文件全部复制加入项目中(imconfig.h, imgiu_demo.cpp, imgui.draw_cpp, imgui_internal.h...)。

3,进入example目录,由于我这边用的GLFW库,因此进入example_glfw_opengl3目录。这里我们看到和Cherno教程不同的地方,这里只有一个main.cpp的代码文件。其实所有的实现文件已经转移到backends文件夹里了。注意这里需要拷贝五个文件到工程目录下,分别是imgui_impl_glfw.h,imgui_impl_glfw.cpp,imgui_impl_opengl3_loader.h,imgui_impl_opengl3.h和imgui_impl_opengl3.cpp。example目录下的main文件可以作为参考代码方便一会的测试。

4,进入自己工程的main方法,引用头文件

imgui.h
imgui_impl_glfw.h
imgui_impl_opengl3.h

然后在mainLoop前初始化imgui

1314038-20230401205142635-1584968359.png

5,在渲染循环,调用GLClear后,我们需要开启imgui的frame

1314038-20230401205337336-1855916129.png

6,接下来就可以开始渲染绘制imgui的内容,我们可以看到example的main.cpp文件中,提供了三个窗口的demo,直接抄就行

1314038-20230401205509726-1219331020.png

7,在swap buff前,我们需要提交imgui的渲染数据

1314038-20230401205606660-1423332302.png

8,最后在销毁窗口前我们需要销毁imgui

1314038-20230401205655506-1198755283.png

9,运行程序可以看到

1314038-20230401205839361-385872045.png

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK