Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qt and OpenGL3.3 Tutorial
I'm running ubuntu 12.04 and I use Qt creator with the Qt 4.8 library.
glxinfo informs me that I have OpenGL 3.3.0 and GLSL 3.3.0
I'm trying to follow this tutorial : "http://qt-project.org/wiki/How_to_use_OpenGL_Core_Profile_with_Qt":http://qt-project.org/wiki/How_to_use_OpenGL_Core_Profile_with_Qt
So I downloaded the provided source files and opened the project in Qt Creator. The compilation works fine but when I run the program, the window opens but the red triangle is not displayed, and I can't figure why because there is no error during the compilation.
Thanks for your help
Hi and welcome to devnet,
You should also check if you really got the format you asked for
Hi Sgaist, thank you for your answer.
Unfortunately, I don't understand what you are asking me to check .. which format are you talking about ?
The QGLFormat created in the main.cpp
Ok, so here's what I did, I just added some debug lines to the existing code :
int main( int argc, char* argv )
QApplication a( argc, argv );
// Specify an OpenGL 3.3 format using the Core profile. // That is, no old-school fixed pipeline functionality QGLFormat glFormat; glFormat.setVersion( 3, 3 ); glFormat.setProfile( QGLFormat::CoreProfile ); // Requires >=Qt-4.8.0 glFormat.setSampleBuffers( true ); qDebug() << "OpenGL context QFlags " << glFormat.openGLVersionFlags(); qDebug() << "OpenGL context " << glFormat; // Create a GLWidget requesting our format GLWidget w( glFormat ); qDebug() << "OpenGL context" << w.format(); qDebug() << "Driver Version String:" << glGetString(GL_VERSION); w.show(); return a.exec();
line 16 returns :
OpenGL context QFlags QFlags(0x1|0x2|0x4|0x8|0x10|0x20|0x40|0x1000|0x2000|0x4000|0x8000)
So, the flag 0x8000 which stands for opengl 3.3, show that openGL 3.3 is supported.
But line 18 returns :
OpenGL context QGLFormat(options QFlags(0x1|0x2|0x4|0x20|0x80|0x200|0x400) , plane 0 , depthBufferSize -1 , accumBufferSize -1 , stencilBufferSize -1 , redBufferSize -1 , greenBufferSize -1 , blueBufferSize -1 , alphaBufferSize -1 , samples -1 , swapInterval -1 , majorVersion 3 , minorVersion 3 , profile 1 )
Here, the flag 0x8000 has disappeared. Yet, the openGL major and minor version is still 3.3 ...
And finally, once the QGLWidget has been instanciated, line 24 returns :
OpenGL context QGLFormat(options QFlags(0x1|0x2|0x4|0x10|0x20|0x80|0x200|0x400) , plane 0 , depthBufferSize 24 , accumBufferSize 16 , stencilBufferSize 8 , redBufferSize 8 , greenBufferSize 8 , blueBufferSize 8 , alphaBufferSize -1 , samples 4 , swapInterval 0 , majorVersion 3 , minorVersion 3 , profile 1 )
I tried on line 26 to display one more information but it returns "0x0", I don't know why.
Could someone help me to identify what's wrong ?
tilsitt last edited by
You should call the show() method before calling glGetString(). Before show(), despite you called the constructor, initializeGL() should'nt have been called and your OpenGL context will not be initialized. I think that is why glGetString() is returning NULL (and it is returning a GLubyte*: you should cast it into a char* to display it with qDebug())..
Oh yes thanks !
So, I called glGetString after the call of show() and it returns this :
"3.3.0 NVIDIA 304.88"
So it should be okay, it proves that opengl3.3 is supported right, so why is it not working ?
Just to be sure, you are not having any warning shown on the console when running the application ?
Nope, no warnings at all ...
Just thought about something, did you try to run another OpenGL example/demo from Qt's sources, just to be sure they are doing fine
TheMindWithin last edited by
Very same problem here, working on OS X 10.9 with Qt 5.1.1. Has a solution been found so far?