OpenGL / C++ / Qt - 需要建议
我正在用 OpenGL 编写一个程序,我需要某种接口工具栏。我最初的反应是使用 GUI,然后进一步研究 C++,我意识到 GUI 依赖于您正在使用的操作系统(我在 Windows 上)。因此,我决定使用QT来帮助我。
我的问题是我是否正在采取最佳/适当的方法来解决这个问题。我什至能够编写我的 OpenGL 程序并拥有我想要使用 C++ 代码创建界面来执行我想要执行的操作的 GUI。
例如,如果我创建一个简单的“控制面板”,每个方向都有箭头。在屏幕上,我有一个由 glut 创建的盒子对象,我可以连接要单击的箭头并与 openGL 程序交互以移动盒子吗?
I am writing a program in OpenGL and I need some sort of interfacing toolbar. My initial reactions were to use a GUI, then further investigation into C++ I realized that GUI's are dependent on the OS you are using (I am on Windows). Therefore, I decided to use QT to help me.
My Question is if I am taking the best/appropriate approach to this solution. Am I even able to write my OpenGL program and have the GUI I want to create interface with the C++ code to do what I want it to do.
For example, If I create a simple "control panel" with arrows in each direction. And on screen I have a box object created by glut can I interface the arrows to be clicked on and interact with the openGL program to move the box?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 Qt 可以解决您的问题:它通过 QtOpenGL 模块提供了与 OpenGL 的良好集成。
QGLWidget
(Qt 4.8 之前)或QOpenGLWidget
(自 Qt 5.4 开始)派生显示类,并实现虚拟方法paintGL()
等Using Qt is coherent for your problem: it provides good integration of OpenGl through the QtOpenGL module.
QGLWidget
(until Qt 4.8) or fromQOpenGLWidget
(since Qt 5.4) and implement virtual methodspaintGL()
etc.您可以在 QGLWidget 之上使用常规的非 OpenGL Qt 小部件,因此您所描述的内容是可行的。
我在这样做时遇到的一件事是常规小部件必须是不透明的。当它们以任何方式透明的那一刻,它们下面就有各种各样的垃圾。那是不久前的事了,所以也许最新版本解决了这个问题。可能也是特定于平台的,所以 YMMV。
You can use regular non-OpenGL Qt widgets on top of a
QGLWidget
so what you describe is do-able.One thing I came across when doing this was that the regular widgets had to be opaque. The moment they were transparent in any way there was all sorts of garbage underneath them. That was a while ago so maybe the latest version addresses this issue. May have been platform-specific too so YMMV.
保持过剩状态。无需为控制面板添加 Qt。您可以打开一个子窗口(或第二个窗口,无论哪个更适合您的程序设计),并将控件绘制到该窗口中,并使用 GLUT 来处理鼠标交互。
此外,Qt 和 GLUT 都有自己的事件循环。要仅使用 Qt 的事件循环,您必须放弃大部分 GLUT 结构,因为 GLUT 事件循环不会调用您的回调函数。 Qt 确实具有让其他人的事件循环调用 Qt 的事件处理代码的功能,但我认为没有一种简单的方法可以让 GLUT 交出事件信息。
Stay in GLUT. There's no need to add Qt for a control panel. You could open a sub window (or second window, whichever works better for your program design), and draw the controls into that window, and use GLUT to handle the mouse interaction.
Furthermore, Qt and GLUT each have their own event loops. To use just Qt's event loop, you'd have to abandon much of the GLUT structure, since the GLUT event loop would not be there to call your callback functions. Qt does have the functionality to have let somebody else event loop call Qt's event processing code, but I don't think there's an easy way to make GLUT hand off the event information.