Qt + OpenGL 3+ - Frustum not completely rendered

  • Hi everyone!

    I'm currently stuck with an issue when trying to draw a simple geometry in a QGLWidget. Indeed the frustum is not completely rendered.

    Actually I've set a perspective of 45°, my camera is translated to 4 units towards the negative Z axis and all my geometry is drawn on the z=0 plane. Thus, any point on this plane situated within a square from (-2, -2 (0)) to (2, 2, (0)) must be rendered as shown on my schematic:


    But actually my frustum is not totally rendered. Indeed i've created a simple trapezoidal geometry which is totally inside my frustum, but when rendering the geometry is incomplete as shown in the next screenshot:


    So I'm wondering if I've missed a point since I'm not able to render all the content of my frustum.

    I've set my MVP matrix as:

    @void GLWidget::resizeGL(int w, int h)
    // Set OpenGL viewport to cover whole widget
    glViewport(0, 0, w, h);

    // Calculate aspect ratio
    qreal aspect = qreal(w) / qreal(h); //qreal(h ? h : 1);
    // Set near plane to 3.0, far plane to 7.0, field of view 45 degrees
    const qreal zNear = 2.0, zFar = 7.0;
    qreal fov = 45.0;
    // Reset projection
    // Set perspective projection
    m_oProjection.perspective(fov, aspect, zNear, zFar);


    then in my paintGL() function I calculate the projection matrix as:

    // Calculate model view transformation
    QMatrix4x4 matrix;
    matrix.translate(0.0, 0.0, -4.0f);

    // Set modelview-projection matrix
    m_oProgram.setUniformValue("mvp_matrix", m_oProjection * matrix);@

    And finally my geometry is set as:

    // Initializing Vertices attributes: position and color
    VertexData vertices[numVertices] = {
    {QVector3D(-2, 1, 0), QVector2D(0, 1)}, //v0 - top left
    {QVector3D(-1, -1, 0), QVector2D(0, 0)}, //v1 - bottom left
    {QVector3D(1, -1, 0), QVector2D(1, 0)}, //v2 - bottom right
    {QVector3D(2, 1, 0), QVector2D(1, 1)} //v3 - top right

    Does anyone have ever encounter such an issue? Do you think I missed a parameter to set in my pipeline?

    Yhanks in advance for your answers!!

Log in to reply

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