How to Integrate OpenGL and Qt? [closed]
Asked Answered
P

4

11

I'm working on a small project and I need to use OpenGL and Qt.

I'm a newbie with both libraries, so I need a good tutorial that illustrates how to use both of them together.

Is it better to work with OpenGL in Qt Creator or to use the Qt Visual Studio Plug-in?

Pedagogics answered 27/4, 2011 at 17:9 Comment(0)
T
12

You'll be using QGLWidget a lot! Here you go:

http://doc.qt.io/qt-5/examples-widgets-opengl.html

Of all those, maybe this is the best one to start: Hello GL Example. If you prefer using Qt Quick instead of Qt Widgets, check these posts:

If you want a higher-level 3D API than OpenGL, as o Qt 5.7 Qt 3D became stable.

As for the IDE I suggest using Qt Creator. It works out of the box on Windows and the syntax highlighting and autocomplete are comparable to Visual Studio.

Tala answered 27/4, 2011 at 17:24 Comment(2)
This answer is outdated now, especially with Qt 5.5+Pent
Appreciate if you provide a reference to your comment.Renovate
P
2

You have several different options for using OpenGL in Qt. It has changed a lot over the years. For an introduction that should cover all the basic info you need to start look at this post. The old style Qt OpenGL classes and functions were called QGLxx but are now called QOpenGLxx and have been moved to the QtGUI module to start with.

Many of the simple OpenGL examples with Qt (including the QOpenGLWindow example shipped with Qt) use the old style of OpenGL that shouldn't be used any longer. Here is a tutorial that has updated the QOpenGLWindow example to modern OpenGL (3+). It is the simplest, most up to date example I have come across.

I second Qt Creator, especially for learning. It has much better integration with the Qt help files than Visual Studio does. If you are considering switching between IDEs I would also recommend building with CMake. CMake is very similar to the built in qmake of Qt Creator but it can work just as good with Visual Studio or other IDEs. I have been running some examples for learning purposes in both Visual Studio and Qt Creator with CMake. Here is a simple CMake example with Qt. For my purposes I still use the Visual Studio compiler when working in Qt Creator though.

Pent answered 27/11, 2015 at 15:46 Comment(0)
P
-1

There're some examples of how to use Open GL with QT in the SDK. You can open these examples in QT Creator if you want. To answer the second question, I find QT Creator much faster and more pleasant to use than Visual Studio but YMMV.

Peppard answered 27/4, 2011 at 17:25 Comment(0)
L
-2

Here is the complete source code of a map rendering application that uses OpenGL with Qt:

https://github.com/CartoType/CartoType-Public/tree/master/src/apps/Maps

The class that uses Qt directly is MapForm:

https://github.com/CartoType/CartoType-Public/blob/master/src/apps/Maps/mapform.h https://github.com/CartoType/CartoType-Public/blob/master/src/apps/Maps/mapform.cpp

The actual OpenGL function calls are inside the CartoType library and therefore are not available in this source code, but the app may be useful to show the general framework for using OpenGL with Qt.

Drawing is done using an implementation of the paintGL function, MapForm::paintGL(), which is called 30 times a second by means of a timer which calls update(), which then triggers the call to paintGL().

Lingenfelter answered 31/1 at 13:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.