OpenGL: GL_DEPTH_TEST doesn't sesm to work



  • Hi everyone,

    I am trying to intigrate an OpenGL rendered scene in QML. I have looked at the "openglundqml" example and have developed my program accordingly. Till now everything works fine except that I somehow don't seem to get the GL_DEPTH_TEST to work.

    When I use the function "glIsEnabled(GL_DEPTH_TEST)" it returns true, yet the object are rendered ontop of each other.

    Here is my code of the "paint()" routine.

    @
    if(!mpOglProgram)
    {
    mpOglProgram = new QOpenGLShaderProgram();
    mpOglProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/cbasic.vsh");
    mpOglProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/cbasic.fsh");
    mpOglProgram->link();
    }

    mpOglProgram->bind();
    
    // Clear color and depth buffer
    glClearColor(0,0,0,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    QMatrix4x4 modelMat;
    QMatrix4x4 viewMat;
    
    QMatrix4x4 cameraTransformation;
    cameraTransformation.rotate(mRotAlpha, 0, 1, 0);
    cameraTransformation.rotate(mRotBeta, 1, 0, 0);
    
    QVector3D cameraPosition = cameraTransformation * QVector3D(mTranslX, mTranslY, mTranslZ);
    QVector3D cameraUpDirection = cameraTransformation * QVector3D(0, 1, 0);
    
    viewMat.lookAt(cameraPosition, cameraTransformation * QVector3D(mTranslX, mTranslY, 0), cameraUpDirection);
    
    modelMat.setToIdentity();
    
    QMatrix4x4 modelViewMat;
    modelViewMat = viewMat * modelMat;
    
    QMatrix3x3 normalMat;
    normalMat = modelViewMat.normalMatrix();
    
    // Set modelview-projection matrix
    mpOglProgram->setUniformValue("mvpMatrix", mProjectionMat * modelViewMat);
    
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    
    GLfloat light_position[] = {1.0, 1.0, -1, 1,0};
    GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
    GLfloat light_diffuse[] = {0.5, 0.5, 0.5, 1.0};
    GLfloat light_ambient[] = {0.128f, 0.128f, 0.128f, 1.0f};
    GLfloat spot_exponent[] = {5};
    
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_SPOT_EXPONENT, spot_exponent);
    
    mCube.draw(mpOglProgram);
    mCamera.draw(mpOglProgram);
    
    mpOglProgram->release();
    

    @

    Help is very much apreciated. Thank you :)


Log in to reply
 

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