xeed
xeed

Reputation: 947

QOpenGLWidget resize results in incorrect viewport size

I have some issues with my QOpenGLWidget resizing functionality. Obviously, I am aiming for a new viewport with the correct amount of pixels and a scene centered in the actual center of my window. But these two things are off somehow.

Here are some images:

Initial one:

Correct

Scaled in Y:

Scaled in Y

Scaled in X:

Scaled in X

The result is pixelated and translated. For me it looks like the GL viewport has the correct amount of pixels, but is scaled to the top and to the right (if the (0,0) is defined as the bottom left corner).

Here is my code:

void GLWidget::initializeGL() {
    QOpenGLFunctions::initializeOpenGLFunctions();
    glClearColor(0.7f, 0.75f, 0.8f, 1.0f);
    glEnable(GL_MULTISAMPLE);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}

void GLWidget::resizeGL(int w, int h) {
    qreal aspect = qreal(w) / qreal(h ? h : 1);
    const qreal zNear = 3, zFar = 7, fov = 3.14/6;
    //I will leave this at it is. This cannot cause the viewport translation
    mGraphics->setProjectionPers(fov, aspect, zNear, zFar);
}

void GLWidget::paintGL() {

    glClear(GL_COLOR_BUFFER_BIT);
    glClear(GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    //actual Drawing
    //...
}

The resizeGL is called with the correct values. What am I doing wrong for having a pixelated and translated image when I run this piece of code?

Upvotes: 2

Views: 2428

Answers (1)

xeed
xeed

Reputation: 947

For whatever reason this was in the header file of my QOpenGLWidget decendant:

void resizeEvent(QResizeEvent* ev) {
    resizeGL(width(), height());
}

This pretty much skips all the resize logic of the QOpenGLWidget class.

Upvotes: 1

Related Questions