QOpenGLVertexArrayObject cannot use in openGL version 3.1 ?
-
I try to render a simple triangle using opengl version 3.1 in Qt5.1. I used Vertex Array Object to encapsulate vertex states, but I found that the function create() of QOpenGLVertexArrayObject class didn't work.
If I change the context version to 3.3, the function create() can be compiled, unfortunately my graphics card does not support version 3.3.
I wonder that in Qt class reference (http://doc-snapshot.qt-project.org/qt5-stable/qtgui/qopenglvertexarrayobject.html), they say that "VAOs are supported as a core feature in OpenGL 3.0 or newer", so the version 3.1 should have worked. Does anyone know what I should do?
Thank you in advance.
-
Hi and welcome to devnet,
Please allow at least 24 to 72 hours before bumping your own thread, not everybody on this forum live in the same timezone as you or even might have an answer to this specific question.
In between you can also search the "bug report system":bugreports.qt-project.org/issues/ to see if someone reported something about this.
The interest mailing list might also be a good place to search -
Hmmm, are you sure that you are actually getting an OpenGL 3.1 context created? What does OpenGL report as the version number after you have created the context and made it current (glGetString(GL_VERSION))?
Prior to OpenGL 3.0 VAO's are only available on OS X via the GL_APPLE_vertex_array_object extension which I unfortunately missed support for in the current implementation of QOpenGLVertexArrayObject. I will add this to an upcoming release of Qt.
-
Hi ZapB
I have just checked the opengl version from glGetString(GL_VERSION). This is the result
OpenGL Version = 2.1 APPLE-7.32.12So, why didn't it change to the version I defined?
This is my code.@GLWindow::GLWindow(QScreen* screen )
: QWindow( screen ),
m_scene(new GLShaderScene(this)),
m_leftButtonPressed( false )
{
// Tell Qt we will use OpenGL for this window
setSurfaceType( OpenGLSurface );// Specify the format we wish to use QSurfaceFormat format; format.setMajorVersion(3); format.setMinorVersion(1); format.setSamples(16); format.setProfile(QSurfaceFormat::CoreProfile); //format.setOption( QSurfaceFormat::DebugContext ); resize( 800,600 ); setFormat( format ); create(); // Create an OpenGL context m_context = new QOpenGLContext; m_context->setFormat( format ); m_context->create(); // Setup our scene m_context->makeCurrent( this ); m_scene->setContext( m_context ); initializeGL(); // Make sure we tell OpenGL about new window sizes connect( this, SIGNAL( widthChanged( int ) ), this, SLOT( resizeGL() ) ); connect( this, SIGNAL( heightChanged( int ) ), this, SLOT( resizeGL() ) ); resizeGL(); // This timer drives the scene updates QTimer* timer = new QTimer( this ); connect( timer, SIGNAL( timeout() ), this, SLOT( updateScene() ) ); timer->start( 16 ); qDebug("OpenGL Version = %s", glGetString(GL_VERSION));
}@
-
When I changed the version to 3.2 or newer, as seen in the following code. The OpenGL version is "OpenGL Version = 3.2 INTEL-7.32.12"
But the viewport has no object rendered. When I try adding some codes for initializing OpenGL functions, it returns false (cannot initialize).
@GLWindow::GLWindow(QScreen* screen )
: QWindow( screen ),
m_scene(new GLShaderScene(this)),
m_leftButtonPressed( false )
{
// Tell Qt we will use OpenGL for this window
setSurfaceType( OpenGLSurface );// Specify the format we wish to use QSurfaceFormat format; format.setMajorVersion(3); format.setMinorVersion(2); format.setSamples(16); format.setProfile(QSurfaceFormat::CoreProfile); //format.setOption( QSurfaceFormat::DebugContext ); resize( 800,600 ); setFormat( format ); create(); // Create an OpenGL context m_context = new QOpenGLContext; m_context->setFormat( format ); m_context->create(); // Initialise opengl function QOpenGLFunctions_3_2_Core *func = m_context->versionFunctions<QOpenGLFunctions_3_2_Core>(); if(!func->initializeOpenGLFunctions()) qDebug("Cannot initialise OpenGL function."); // Setup our scene m_context->makeCurrent( this ); m_scene->setContext( m_context ); initializeGL(); // Make sure we tell OpenGL about new window sizes connect( this, SIGNAL( widthChanged( int ) ), this, SLOT( resizeGL() ) ); connect( this, SIGNAL( heightChanged( int ) ), this, SLOT( resizeGL() ) ); resizeGL(); // This timer drives the scene updates QTimer* timer = new QTimer( this ); connect( timer, SIGNAL( timeout() ), this, SLOT( updateScene() ) ); timer->start( 16 ); qDebug("OpenGL Version = %s", glGetString(GL_VERSION));
}@
-
You need to make the context current before initializing the functions object. It should work as expected then.
As for why you didn't get an OpenGL 3.1 context, either:
- A bug in Qt
- OS X doesn't support OpenGL 3.1 contexts
Not sure which it is without digging further.
-
Now I can fix it without initializing.
But I dont know why opengl is set to the version 2.1 when I define the surface format to 3.1 or even the older version, but when I define it to 3.2 or newer, opengl is set to version 3.2.
I think OS X support only these two versions on my mac
Anyway, thanks very much