PDA

View Full Version : Looking for Pure OpenGL access from Qt Example



r2com
4th August 2016, 17:39
I am looking online, there are multiple Qt+OpenGL examples, but all of them are using some sort of intermediate classes/subclasses and other layers to get to OpenGL.

Is anyone aware of some basic start off example (like drawing of one line, or empty screen) which utilizes just pure OpenGL calls from Qt application?

d_stranz
5th August 2016, 02:25
If you are going to use Qt as the GUI "host" for your OpenGL app, you need at least a Qt-based window to hold the OpenGL context and provide a means to interact with it. This is usually QOpenGLWidget. In its paintGL() method, you can issue any OpenGL call you wish. So just pick your favorite OpenGL example program and copy its painting calls to the paintGL() method in your widget derived from QOpenGLWidget.

r2com
5th August 2016, 15:59
Does that impose some delay to processing?

d_stranz
5th August 2016, 17:22
Does that impose some delay to processing?

Yes, if you use pure, old-style GL calls where everything is done on the PC instead of being transferred to the GPU and run via shaders. But if you ran the same GL code under different host GUIs (Qt, VTK, etc.) I doubt you could measure the difference. The gain is in pushing as much as possible into the GPU.

If you want to see the difference between PC-side and GPU-side computation, the best example I know of is the "smoke particles" demo NVidia has written to demonstrate the power of GPU programming using their CUDA toolkit. YouTube video here (https://www.youtube.com/watch?v=dX8KeqYLY10), documentation here (http://docs.nvidia.com/cuda/cuda-samples/#smoke-particles), white paper here (http://docs.nvidia.com/cuda/samples/5_Simulations/smokeParticles/doc/smokeParticles.pdf).

The nice thing about these samples is that they can be run both PC-side and GPU-side so you can see for yourself the performance difference on your own hardware.

r2com
9th August 2016, 21:35
Well, I do not want to look at more advanced examples now, because before diving there I want to exercise a simple and neat example where I effectively use OpenGL.

I have some questions:

1) Is it a good idea to use the QOpenGLWidget class to achieve what I described? (i.e. use OpenGL with possibly minimum code overhead)

2) I looked at suggestions on here (http://stackoverflow.com/questions/31522637/how-do-i-render-a-triangle-in-qopenglwidget), and when I compile I get the following errors:


oglwidget.obj:-1: error: LNK2019: unresolved external symbol gluPerspective referenced in function "protected: virtual void __cdecl OGLWidget::resizeGL(int,int)" (?resizeGL@OGLWidget@@MEAAXHH@Z)

oglwidget.obj:-1: error: LNK2019: unresolved external symbol gluLookAt referenced in function "protected: virtual void __cdecl OGLWidget::resizeGL(int,int)" (?resizeGL@OGLWidget@@MEAAXHH@Z)

Which another lib do I need to link with? (adding LIBS += opengl32.lib to the .pro file did not help)

d_stranz
10th August 2016, 06:32
You need to also link to a glut library. On Windows, you can use freeglut. Link here (http://freeglut.sourceforge.net/), and follow further links for there for binary distributions.

Look at the .pro files for some of the examples that came with your Qt distro. They should contain the appropriate LIBS definition.

QOpenGLWidget is the recommended way to go. The older QGLWidget has been deprecated and should not be used for new code.

r2com
10th August 2016, 16:02
I've skimmed through the examples in my Qt creator, they do not include anything, especially any GLUT.

And I am now confused a bit, the FreeGLUT page says that GLUT has been abandoned and cannot be distributed freely that's why they continue FreeGLUT.
But I thought that OpenGL source code is free and constantly kept up to date? What am I missing?

Again, all I want is to use native OpenGL through my QOpenGLWidget class, which way I can achieve that without using any unnecessary 3rd party stuff?

The two functions complained by linker: gluPerspective and gluLookAt are described on the opengl.org website under the SDK section, so maybe I need to download original OpenGL SDK, but not any GLUT?

I'm just trying to understand and sort it all out now...

anda_skoa
10th August 2016, 17:58
I've skimmed through the examples in my Qt creator, they do not include anything, especially any GLUT.

They likely don't need any functionality from GLUT.



And I am now confused a bit, the FreeGLUT page says that GLUT has been abandoned and cannot be distributed freely that's why they continue FreeGLUT.
But I thought that OpenGL source code is free and constantly kept up to date? What am I missing?

OpenGL is an open specification, not a single implementation.
There are various implementations from different vendors, some Free/Open Source (e.g. Mesa), some proprietary (e.g. Nvidia, Microsoft).



Again, all I want is to use native OpenGL through my QOpenGLWidget class, which way I can achieve that without using any unnecessary 3rd party stuff?

If you don't want to depend on any additional library, just don't use any functions from such libraries.

Like with any other library, once you use a function defined in it, you also need to link to it.

Cheers,
_

d_stranz
10th August 2016, 18:52
The two functions complained by linker: gluPerspective and gluLookAt are described on the opengl.org website under the SDK section

Sorry, I misread. You need to be including a link to the "GLU" library, which on my Windows system is found in Program Files (x86)/Microsoft SDKs/Windows/v7.1A/libs (as GlU32.lib). If your linker is finding the OpenGL library OK, then just add "LIBS += -l GlU32"to your .pro

The "GLUT" library provides useful interfaces to your native Windows windowing system, but if you develop within Qt's OpenGL wrapper, you probably won't need them. Sorry for the confusion on my part.

r2com
10th August 2016, 19:18
ok now it works after I modified my .pro file to have:

LIBS += opengl32.lib GLU32.lib

Cruz
15th August 2016, 10:15
Hi r2com,

I would like to draw your attention to the http://libqglviewer.com/ library, which I believe is well suitable for your needs, and comes with simple examples to start you off.