Qt 5.3 OpenGL - vertex buffer object drawing using the core profile

Posted by user3700881 on Stack Overflow See other posts from Stack Overflow or by user3700881
Published on 2014-06-02T21:21:31Z Indexed on 2014/06/02 21:24 UTC
Read the original article Hit count: 394

Filed under:
|
|
|

Im using Qt 5.3 to create a QWindow to do some basic rendering stuff. The QWindow is declared like this:

 class OpenGLWindow : public QWindow, protected QOpenGLFunctions_3_3_Core
 {
     Q_OBJECT
     ...
 }

It is initialized in the constructor:

OpenGLWindow::OpenGLWindow(QWindow *parent) : QWindow(parent)
{
    QSurfaceFormat format;
    format.setVersion(3,3);
    format.setProfile(QSurfaceFormat::CoreProfile);

    this->setSurfaceType(OpenGLSurface);
    this->setFormat(format);
    this->create();

    _context = new QOpenGLContext;
    _context->setFormat(format);
    _context->create();

    _context->makeCurrent(this);
    this->initializeOpenGLFunctions();
    ...
}

And that's the rendering code:

void OpenGLWindow::render()
{
    if(!isExposed())
        return;

    _context->makeCurrent(this);

    glClear(GL_COLOR_BUFFER_BIT);

    glUseProgram(_shaderProgram);

    glBindBuffer(GL_ARRAY_BUFFER, _positionBufferObject);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    glDisableVertexAttribArray(0);
    glUseProgram(0);

    _context->swapBuffers(this);
}

I am trying to draw a simple triangle using a vertex and fragment shader. The problem is that the triangle is not showing up when the core profile is set. Only when I set the OpenGL version to 2.0 or when I use the compatibility profile, it shows up. From my point of view that doesn't make any sense because I am not using fixed functionality at all. What am I missing?

© Stack Overflow or respective owner

Related posts about c++

Related posts about qt