Results 1 to 11 of 11

Thread: How to use QOpenGLFunctions_2_1 properly

  1. #1
    Join Date
    Dec 2010
    Posts
    76
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    13

    Default How to use QOpenGLFunctions_2_1 properly

    I am trying to use raw OpenGL with Qt and I am trying to strictly use the Qt API to do so. I am using OpenGL 2.1 because that is our hardware limitation. I am able to build without any errors but the first instance of a gl* fails. The first opengl function is glGetIntergv(GL_ENUM, int*) and through the debugger I am able to see that is where I crash first. I am just curious if anyone can see what I am missing because my guess is I have to do something special to initialize these functions (which I thought initializeOpenGLFunctions() accomplished). Any help or direction would be great!!

    I am subclassing with QOpenGLFunctions_2_1 like so:
    Qt Code:
    1. class GLWidget : public QGLWidget, protected QOpenGLFunctions_2_1
    To copy to clipboard, switch view to plain text mode 

    These are the relevant source file functions
    Qt Code:
    1. GLWidget::GLWidget(QWidget *parent) :
    2. QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::Rgba | QGL::DepthBuffer),parent)
    3. {
    4. createActions();
    5. createMenus();
    6. }
    7.  
    8. void GLWidget::initializeGL()
    9. {
    10. initializeOpenGLFunctions();
    11.  
    12. pixels[0] = pixels[1] = pixels[2] = NULL;
    13. frameGood[0] = frameGood[1] = frameGood[2] = GL_FALSE;
    14.  
    15. qDebug() << "Pixel Buffer Object Demo";
    16.  
    17. QGLFunctions funcs(QGLContext::currentContext());
    18. bool isNonPowerTwo = funcs.hasOpenGLFeature(QGLFunctions::NPOTTextures);
    19.  
    20. // // Make sure required functionality is available!
    21. // if (!GLEE_VERSION_2_1 && !GLEE_ARB_pixel_buffer_object)
    22. // {
    23. // qDebug() << "PBO extension is not available!";
    24. //// fprintf(stderr, "PBO extension is not available!\n");
    25. // Sleep(2000);
    26. // exit(0);
    27. // }
    28.  
    29. if (isNonPowerTwo)
    30. {
    31. npotTexturesAvailable = GL_TRUE;
    32. }
    33. else
    34. {
    35. qDebug() << "GL_ARB_texture_non_power_of_two extension is not available!";
    36. qDebug() << "Only portion of window will be used for rendering";
    37. }
    38.  
    39. // Check for minimum resources
    40. GLint intVal = 0;
    41. glGetIntegerv(GL_MAX_TEXTURE_UNITS, &intVal);
    42.  
    43. if (intVal < 3)
    44. {
    45. qDebug() << "Fewer than 3 texture units available!";
    46. Sleep(2000);
    47. exit(0);
    48. }
    49. glGetIntegerv(GL_MAX_TEXTURE_SIZE, &intVal);
    50. if (intVal < 1024)
    51. {
    52. qDebug() << "1024x1024 texture not supported!";
    53. Sleep(2000);
    54. exit(0);
    55. }
    56.  
    57. qDebug() << "Controls:";
    58. qDebug() << "\tRight-click for menu";
    59. qDebug() << "\tb\tToggle motion blur";
    60. qDebug() << "\tp\tToggle PBO usage";
    61. qDebug() << "\tarrows\t+/- rotation speed";
    62. qDebug() << "\tq\t\tExit demo";
    63.  
    64. // Colors
    65. glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
    66. glColor4f(0.0f, 0.0f, 0.0f, 1.0f );
    67.  
    68. // Texture matrix is the only one we'll change
    69. glMatrixMode(GL_TEXTURE);
    70.  
    71. // Set up textures
    72. SetupTextures();
    73. }
    To copy to clipboard, switch view to plain text mode 

    And as stated above the first call to glGetIntergv is what fails . Any ideas?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to use QOpenGLFunctions_2_1 properly

    Has initializeOpenGLFunctions() returned true or failed (false)?

  3. The following user says thank you to ChrisW67 for this useful post:

    jshafferman (28th March 2014)

  4. #3
    Join Date
    Dec 2010
    Posts
    76
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    13

    Default Re: How to use QOpenGLFunctions_2_1 properly

    I haven't had a chance to check it yet, but if it is returning false why would that happen?

  5. #4
    Join Date
    Dec 2010
    Posts
    76
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    13

    Default Re: How to use QOpenGLFunctions_2_1 properly

    So it is turning out that my initializeOpenGLFunctions() is returning false. What would cause this to happen? I have already double checked to make sure that my graphics card is capable of supporting OpenGL 2.1 so I know that it isn't hardware related. Any ideas?

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to use QOpenGLFunctions_2_1 properly

    Well, the QOpenGLFunctions example sets a surface type and creates a GL context in the class constructor and makes that current before calling initializeOpenGLFunctions.

  7. The following user says thank you to ChrisW67 for this useful post:

    jshafferman (28th March 2014)

  8. #6
    Join Date
    Dec 2010
    Posts
    76
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    13

    Default Re: How to use QOpenGLFunctions_2_1 properly

    Isn't the SetSurfaceType specific to a QWindow not a QWidget? I have seen that example but I didn't think it applied to the QGLWidget.

  9. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to use QOpenGLFunctions_2_1 properly

    This is where my broken link should have been pointing http://qt-project.org/doc/qt-5.0/qtg...s.html#details

    Yes it is QWindow but there could be a clue in the setup to use the inherited functions. I do not know from first hand use of it.

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

    jshafferman (28th March 2014)

  11. #8
    Join Date
    Dec 2010
    Posts
    76
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    13

    Default Re: How to use QOpenGLFunctions_2_1 properly

    I investigated trying to use the QWindow version and I don't see how that can be applied to the QGLWidget. The QOpenGLContext takes a QSurfaceType (if I remember right) which I don't know if it makes sense to create a QSurfaceType inside of QGLWidget. Anyhow I don't see how I can piggy back off of that example. Do you have any ideas? According to the documentation for QGLWidget context should be set when calling the paintgl and initializeGL functions.

  12. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to use QOpenGLFunctions_2_1 properly

    OK. This code works for me (Linux 64-bit, Qt 5.2.0, nVidia proprietary drivers):
    Qt Code:
    1. #include <QtWidgets>
    2. #include <QtOpenGL>
    3. #include <QOpenGLFunctions_2_1>
    4.  
    5. class GLWidget : public QGLWidget, protected QOpenGLFunctions_2_1
    6. {
    7. Q_OBJECT
    8. public:
    9. GLWidget(QWidget *parent = 0) :
    10. QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::Rgba | QGL::DepthBuffer),parent)
    11. {
    12. }
    13. protected:
    14. void initializeGL()
    15. {
    16. bool ok = initializeOpenGLFunctions();
    17.  
    18. // Check for minimum resources
    19. GLint intVal = 0;
    20. glGetIntegerv(GL_MAX_TEXTURE_UNITS, &intVal);
    21. qDebug() << ok << intVal; // true, 4 on my machine
    22. }
    23. };
    24.  
    25. int main(int argc, char **argv) {
    26. QApplication app(argc, argv);
    27. GLWidget w;
    28. w.show();
    29. return app.exec();
    30. }
    31. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    Your initializeOpenGLFunctions() returning false would indicate that there is no OpenGL support on your system.

  13. The following user says thank you to ChrisW67 for this useful post:

    jshafferman (28th March 2014)

  14. #10
    Join Date
    Dec 2010
    Posts
    76
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    13

    Default Re: How to use QOpenGLFunctions_2_1 properly

    Well I'll be... It appears that the laptop I am using to work with 'says' it has OpenGL support for 2.1 however if I change the QOpenGLFunction_2_1 to 2_0 or 1_* it appears to start working! So I am glad to learn that if initializeOpenGLFunctions fails it is because that particular version of OpenGL is not supported on your system. I wish the Qt doucmentation just said that , however thank you very much for your help! I am sure I will have more questions about Qt and OpenGL as get more involved with the process. Thanks!

  15. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to use QOpenGLFunctions_2_1 properly

    It is not ideal documentation, but see the second last paragraph in the detailed description of QAbstractOpenGLFunctions.

Similar Threads

  1. How to properly install QCA on Mac OS?
    By unix7777 in forum Newbie
    Replies: 1
    Last Post: 2nd September 2010, 00:20
  2. Replies: 1
    Last Post: 22nd March 2010, 14:38
  3. ScrollZoomer not working properly..
    By Raghaw in forum Qwt
    Replies: 1
    Last Post: 30th October 2009, 06:51
  4. How to install Qxt properly?
    By blurboy in forum Newbie
    Replies: 3
    Last Post: 18th October 2009, 20:12
  5. How do I use QTcpSocket properly ?
    By mnemonic_fx in forum Qt Programming
    Replies: 13
    Last Post: 29th March 2007, 20:33

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
  •  
Qt is a trademark of The Qt Company.