Reputation: 22346
A week ago I upgraded my OS to the latest version, so GLEW, nVidia drivers, g++, Qt, etc. all got upgraded too. That was the day my QGLWidget
s stopped showing raw OpenGL 3.3 content, only the 2D QPainter
based stuff. Since no other OpenGL applications (including my DE) on my machine were affected, I must have written some dodgy code in my application, that perhaps had been allowed by older versions of these libraries - which have now been amended.
I have a lot of heavily abstracted OpenGL code, so many potential places for a failure; and after a few days of trying to get any sort of output from it (glGetError()
was not returning errors before I started messing with it), I decided the best thing to do was write the simplest OpenGL application possible and then slowly build it up until it broke.
But I can't even get a triangle to appear!
void Viewer::initializeGL()
{
// Initialise GLEW, compile/link fragment and vertex shaders, error check, etc.
...
// Create default VAO.
glGenVertexArrays( 1, &vao_ );
glBindVertexArray( vao_ );
glUseProgram( shader_ );
vVertex_ = glGetAttribLocation( shader_, "vVertex" );
// Create the test triangle VBO.
glGenBuffers( 1, &vbo_ );
glBindBuffer( GL_ARRAY_BUFFER, vbo_ );
glEnableVertexAttribArray( vVertex_ );
glVertexAttribPointer( vVertex_, 3, GL_FLOAT, false, 0,
reinterpret_cast< GLvoid* >( 0 ) );
// Upload the data to the GPU.
static const float verts[9] = { 0.0f, 0.0f, -0.5f,
1.0f, 0.0f, -0.5f,
0.5f, 1.0f, -0.5f };
glBufferData( GL_ARRAY_BUFFER, sizeof( verts ),
static_cast< const void* >( verts ), GL_STATIC_DRAW );
glBindBuffer( GL_ARRAY_BUFFER, GL_NONE );
glDisableVertexAttribArray( vVertex_ );
Sy_GL::checkError();
}
void Viewer::paintGL()
{
// Clear the buffers.
qglClearColor( QColor( Qt::black ) );
glClear( GL_COLOR_BUFFER_BIT );
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glBindBuffer( GL_ARRAY_BUFFER, vbo_ );
glEnableVertexAttribArray( vVertex_ );
glVertexAttribPointer( vVertex_, 3, GL_FLOAT, false, 0,
reinterpret_cast< GLvoid* >( 0 ) );
glDrawArrays( GL_TRIANGLES, 0, 3 );
glBindBuffer( GL_ARRAY_BUFFER, GL_NONE );
glDisableVertexAttribArray( vVertex_ );
Sy_GL::checkError();
}
I'm not using my VAO for what it is for because VAOs cannot be shared across contexts, which is the scenario in my 'real' application, so I'm replicating that situation here. Sy_GL::checkError()
just calls glGetError()
and throws an exception if there's a problem. My two shaders could not be simpler:
// Vertex shader.
#version 330
in vec3 vVertex;
void main( void )
{
gl_Position = vec4( vVertex, 1.0 );
}
// Fragment shader (in different file).
#version 330
out vec4 fragColour;
void main( void )
{
fragColour = vec4( 1.0, 0.0, 0.0, 1.0 );
}
This should display a red line rendered triangle against a black background, but I just get the black background - no console output or exceptions. My system really does support OpenGL 3.3 and higher, here is top of my glxinfo
output:
name of display: :0
display: :0 screen: 0
direct rendering: Yes
server glx vendor string: NVIDIA Corporation
server glx version string: 1.4
And my glewinfo
output:
GLEW version 1.9.0
Reporting capabilities of display :0, visual 0x2b
Running on a GeForce GTX 560 Ti/PCIe/SSE2 from NVIDIA Corporation
OpenGL version 4.3.0 NVIDIA 310.32 is supported
So my question is: Is my code wrong? Or is my system damaged very subtly?
It appears that QGLFormat
is reporting that I only have OpenGL v1.0 - what mechanism is Qt using to get that value?
In my 'real' application I perform a OpenGL version check using QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_3_3
, and this passes; but using myQGLWidget->format().majorVersion()
and myQGLWidget->format().minorVersion()
return 1
and 0
respectively.
Interestingly, if I set a default QGLFormat
of v3.3 in my main.cpp:
QGLFormat format( QGL::DoubleBuffer |
QGL::DepthBuffer |
QGL::AlphaChannel );
format.setVersion( 3, 3 );
QGLFormat::setDefaultFormat( format );
It segfaults on the first of my OpenGL calls, specifically glGenVertexArrays(1, &vao_)
, but myQGLWidget->format().majorVersion()
and myQGLWidget->format().minorVersion()
return 3
and 3
respectively.
Upvotes: 1
Views: 404
Reputation: 5116
We recently had this at work. The cause was the latest NVIDIA drivers, which broke the major and minor version queries.
Edit: I think it may have been related to calling these functions before setting up a valid GL context. End edit
So, you could try with a slightly older driver. However, there is also an issue with some Qt versions and glversion. Check this link out:
http://qt-project.org/forums/viewthread/20424
Upvotes: 1