简体   繁体   English

OpenGL / C ++ / Qt - 需要建议

[英]OpenGL / C++ / Qt - Advice needed

I am writing a program in OpenGL and I need some sort of interfacing toolbar. 我正在用OpenGL编写程序,我需要某种接口工具栏。 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). 我最初的反应是使用GUI,然后进一步调查C ++我意识到GUI依赖于你正在使用的操作系统(我在Windows上)。 Therefore, I decided to use QT to help me. 因此,我决定使用QT来帮助我。

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. 我甚至能够编写我的OpenGL程序并拥有GUI我想用C ++代码创建接口来做我想做的事情。

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? 在屏幕上我有一个由glut创建的box对象,我可以将箭头接口点击并与openGL程序交互以移动框吗?

Using Qt is coherent for your problem: it provides good integration of OpenGl through the QtOpenGL module. 使用Qt对于您的问题是一致的:它通过QtOpenGL模块提供OpenGl的良好集成。

  1. Derive your display classes from QGLWidget (until Qt 4.8) or from QOpenGLWidget (since Qt 5.4) and implement virtual methods paintGL() etc. QGLWidget (直到Qt 4.8)或QOpenGLWidget (从Qt 5.4开始)派生显示类,并实现虚拟方法paintGL()等。
  2. You will have access to the Qt's signal and slot system so that you will be able to catch Gui events and update the OpenGl display. 您将可以访问Qt的信号和插槽系统,以便您能够捕获Gui事件并更新OpenGl显示。

You can use regular non-OpenGL Qt widgets on top of a QGLWidget so what you describe is do-able. 您可以在QGLWidget上使用常规的非OpenGL Qt小部件,因此您所描述的是可行的。

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. YMMV可能也是特定于平台的。

Stay in GLUT. 留在GLUT。 There's no need to add Qt for a control panel. 没有必要为控制面板添加Qt。 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. 您可以打开一个子窗口(或第二个窗口,无论哪个更适合您的程序设计),并将控件绘制到该窗口,并使用GLUT处理鼠标交互。

Furthermore, Qt and GLUT each have their own event loops. 此外,Qt和GLUT每个都有自己的事件循环。 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的事件循环,您必须放弃大部分GLUT结构,因为GLUT事件循环不会调用您的回调函数。 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. Qt确实有让其他人事件循环调用Qt的事件处理代码的功能,但我认为没有一种简单的方法可以让GLUT处理事件信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM