QOpenGLContext on Mac OS X

  • Hi,

    System: OS X 10.9, Qt 5.2.1 (installed view homebrew), Graphics: nvidia GTX 750M, Intel Iris Pro

    I am new to OpenGL and Qt. For the last days I played with various examples, primarily using QGLWidget. I wanted to use the modern QOpenGLContext and tried this example here: http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html

    When I change the following two lines:

    @QSurfaceFormat format;


    @QSurfaceFormat format;
    format.setDepthBufferSize( 24 );
    format.setMajorVersion( 4 );
    format.setMinorVersion( 3 );
    format.setSamples( 4 );
    format.setProfile( QSurfaceFormat::CoreProfile );
    format.setOption( QSurfaceFormat::DebugContext );@

    The screen is black, no matter which version combination I use. The reason is I wanted to use some features of newer GLSL standards.

    What am I doing wrong or missing?

    Thanks a lot in advance!

  • I figured out that for newer OpenGL versions, one must use VertexArrayObjects, otherwise it does not work. That fixed the problem.

  • I'm just getting started myself, and I found the following code extremely useful. Just copy it into your initializeGL function before you do anything else.

    @ // get context opengl-version
    qDebug() << "Widget OpenGl: " << format().majorVersion() << "." << format().minorVersion();
    qDebug() << "Context valid: " << context()->isValid();
    qDebug() << "Really used OpenGl: " << context()->format().majorVersion() << "." << context()->format().minorVersion();
    qDebug() << "OpenGl information: VENDOR: " << (const char*)glGetString(GL_VENDOR);
    qDebug() << " RENDERDER: " << (const char*)glGetString(GL_RENDERER);
    qDebug() << " VERSION: " << (const char*)glGetString(GL_VERSION);
    qDebug() << " GLSL VERSION: " << (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);

    This is what you will see in the application output:
    @Widget OpenGl: 4 . 1
    Context valid: true
    Really used OpenGl: 4 . 1
    OpenGl information: VENDOR: ATI Technologies Inc.
    RENDERDER: AMD Radeon HD - FirePro D300 OpenGL Engine
    VERSION: 4.1 ATI-1.16.39
    GLSL VERSION: 4.10

  • That's nice of you, thanks a lot for sharing this snippet!

  • Right, as you found, a core profile context requires a vertex array object to be bound. The easy way to port from legacy OpenGKL is to simply create and bind a VAO up front and then forget about it.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.