Results 1 to 11 of 11

Thread: Looking for Pure OpenGL access from Qt Example

  1. #1
    Join Date
    Jul 2016
    Posts
    57
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Question Looking for Pure OpenGL access from Qt Example

    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?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Looking for Pure OpenGL access from Qt Example

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2016
    Posts
    57
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Looking for Pure OpenGL access from Qt Example

    Does that impose some delay to processing?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Looking for Pure OpenGL access from Qt Example

    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, documentation here, white paper here.

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Jul 2016
    Posts
    57
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Looking for Pure OpenGL access from Qt Example

    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, 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)

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Looking for Pure OpenGL access from Qt Example

    You need to also link to a glut library. On Windows, you can use freeglut. Link here, 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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Jul 2016
    Posts
    57
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Looking for Pure OpenGL access from Qt Example

    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...

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Looking for Pure OpenGL access from Qt Example

    Quote Originally Posted by r2com View Post
    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.

    Quote Originally Posted by r2com View Post
    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).

    Quote Originally Posted by r2com View Post
    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,
    _

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Looking for Pure OpenGL access from Qt Example

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  10. The following user says thank you to d_stranz for this useful post:

    r2com (10th August 2016)

  11. #10
    Join Date
    Jul 2016
    Posts
    57
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Looking for Pure OpenGL access from Qt Example

    ok now it works after I modified my .pro file to have:
    LIBS += opengl32.lib GLU32.lib

  12. #11
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Looking for Pure OpenGL access from Qt Example

    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.

Similar Threads

  1. Pure QML and qdoc
    By joshelmich in forum Qt Tools
    Replies: 1
    Last Post: 27th February 2015, 16:26
  2. QT + OpenGL + OpenCV + GStreamer (Access violation)
    By Elijah Muhammad in forum Qt Programming
    Replies: 1
    Last Post: 3rd June 2013, 07:24
  3. Using Qt Creator as a pure C IDE?
    By blooglet in forum Qt Tools
    Replies: 3
    Last Post: 11th November 2011, 01:21
  4. Cost of pure virtual
    By ShaChris23 in forum General Programming
    Replies: 4
    Last Post: 4th November 2007, 18:20
  5. the memory is not pure
    By mickey in forum General Programming
    Replies: 3
    Last Post: 14th July 2007, 17:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.