Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. OpenGL: GL_DEPTH_TEST doesn't sesm to work
Forum Updated to NodeBB v4.3 + New Features

OpenGL: GL_DEPTH_TEST doesn't sesm to work

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 868 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Boy2melo
    wrote on last edited by
    #1

    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 :)

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved