QGLWidget to QOpenGLWidget > Only background, no objects etc.



  • Hi,

    I installed yesterday Qt 5.4 x64 opengl_msvc13. I tested out if everything is ok, app runs well so I checked out and there was new QOpenGLWidget class.

    So I did changes from QGLWidget to QOpenGLWidget like this:
    @#include <QOpenGLWidget> // from #include <QGLWidget>

    class MapView : public QOpenGLWidget // from class MapView : public QGLWidget

    MapView::MapView(..., QWidget* parent)
    : QOpenGLWidget(parent)
    , GLcontext(this->context()), ...
    {
    QSurfaceFormat format;
    format.setDepthBufferSize(24);
    format.setMajorVersion(4);
    format.setMinorVersion(3);
    format.setSamples(4);
    format.setProfile(QSurfaceFormat::CoreProfile);

    GLcontext->setFormat(format);
    GLcontext->create();
    

    }
    // from
    MapView::MapView(..., QWidget* parent)
    : QGLWidget(parent)
    , GLcontext(this->context()->contextHandle()), ...
    {
    QSurfaceFormat format;
    format.setDepthBufferSize(24);
    format.setMajorVersion(4);
    format.setMinorVersion(3);
    format.setSamples(4);
    format.setProfile(QSurfaceFormat::CoreProfile);

    QSurfaceFormat::setDefaultFormat(format);
    

    }

    void MapView::initializeGL()
    {
    this->makeCurrent();

    QSurfaceFormat format;
    format.setDepthBufferSize(24);
    format.setMajorVersion(4);
    format.setMinorVersion(3);
    format.setSamples(4);
    format.setProfile&#40;QSurfaceFormat::CoreProfile&#41;;
    
    this->context()->setFormat(format);
    
    // Initialize World
    world->initialize(/*GLcontext*/this->context(), size());
    
    // Initialize camera shader
    camera->initialize();
    
    // Enable depth testing
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    
    glDepthFunc(GL_LEQUAL); // just testing new depth func
    
    glClearColor(0.65f, 0.77f, 1.0f, 1.0f);
    
    m_Utime.start();
    
    emit initialized();
    

    }
    // from
    void MapView::initializeGL()
    {
    this->makeCurrent();

    // Initialize World
    world->initialize(GLcontext, size());
    
    // Initialize camera shader
    camera->initialize();
    
    // Enable depth testing
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    
    glDepthFunc(GL_LEQUAL); // just testing new depth func
    
    glClearColor(0.65f, 0.77f, 1.0f, 1.0f);
    
    m_Utime.start();
    
    emit initialized();
    

    }

    void World::initialize(QOpenGLContext* context, QSize fboSize)
    {
    GLfuncs = context->versionFunctions<QOpenGLFunctions_4_2_Core>();
    //GLfuncs = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_4_2_Core>(); // tried also.. not worked

    GLfuncs->initializeOpenGLFunctions();
    ...
    

    }
    // from
    void World::initialize(QOpenGLContext* context, QSize fboSize)
    {
    GLfuncs = context->versionFunctions<QOpenGLFunctions_4_2_Core>();

    GLfuncs->initializeOpenGLFunctions();
    ..
    

    }
    @

    I don't know what I am missing to draw correct what I did before QGLWidget to QOpenGLWidget... I think there must be something different with QOpenGLContext...

    I'm also using/used QOpenGLContext::currentContext() in another classes like Material, Sampler, ...
    following code (non changed, worked with QGLWidget):
    @Material::Material()
    {
    QOpenGLContext* context = QOpenGLContext::currentContext();

    Q_ASSERT(context);
    
    m_funcs = context->versionFunctions<QOpenGLFunctions_4_2_Core>();
    
    if(!m_funcs)
    {
        qWarning() << QObject::tr("Requires multi-texturing support");
    
        return;
    }
    
    m_funcs->initializeOpenGLFunctions();
    

    }@

    So there must be something different with currentContext or I don't know :(

    paint function:
    @void MapView::paintGL()
    {
    this->makeCurrent();

    glDrawBuffer(GL_FRONT);
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    if(showCameraCurve)
            camera->drawCurve(modelMatrix);
    
    if(eMode == Terrain || eMode == Texturing || eMode == VertexShading)
            world->draw(this, terrain_pos, modelMatrix, screenSpaceErrorLevel, QVector2D(mouse_position.x(), mouse_position.y()), true);
    else if(eMode == Object && eModel == Insertion)
            world->draw(this, terrain_pos, modelMatrix, screenSpaceErrorLevel, QVector2D(mouse_position.x(), mouse_position.y()), false, true);
    else
            world->draw(this, terrain_pos, modelMatrix, screenSpaceErrorLevel, QVector2D(mouse_position.x(), mouse_position.y()));
    

    }@

    and timer event:
    @void MapView::timerEvent(QTimerEvent*)
    {
    this->makeCurrent();

    const qreal time = m_Utime.elapsed() / 1000.0f;
    
    update(time);
    //updateGL(); // no longer in QOpenGLWidget
    

    }@

    Thanks for reply and help!


Log in to reply
 

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