0

I am trying to draw a basic mesh loaded from an .obj file using stereoscopic 3D rendering on a NVIDIA Quadro 5000. From what I can tell I think I got my left eye and right eye frustums and offsets set accordingly, but my main issue is with writing and clearing the BACK_LEFT and BACK_RIGHT buffers. It seems that it misses the first part completely and only draws the BACK_RIGHT buffer (second part of the rendering loop). If I could get some pointers on how to write/read and clear these buffers in the same frame that would be great. It's a Linux application hence the glXSwap(), not using glut or glew and using glm for maths. Here is my drawing loop:

void GLDraw::Draw()
{
    //initialise shader in frame
    shader->UseShaderProgram();

    //select back_left buffer
    glDrawBuffer(GL_BACK_LEFT);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //set projection and view for back_left
    projectionMatrix = glm::frustum(-xCoord - frustumAssymmetry, xCoord - frustumAssymmetry, -yCoord, yCoord, 0.1f, 200.0f);
    projectionMatrix *= glm::translate(glm::mat4(1.0f), glm::vec3(eyeOffset, 0.0f, 0.0f));
    glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, value_ptr(projectionMatrix));
    glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &viewMatrix[0][0]);

    //set model matrix for rendering calls   
    modelMatrix = scale(mat4(1.0f), vec3(0.7, 0.7, 0.5f));
    modelMatrix *= translate(mat4(1.0f), vec3(0.0f, 0.0f, 0.0f));
    modelMatrix *= rotate(mat4(1.0f), i+=0.04, vec3(0.0f, 1.0f, 0.0f));
    glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]);

    //draw VAO
    glBindVertexArray(vikingVAO);
    glDrawElements(GL_TRIANGLES, viking_elements.size() * sizeof(viking_elements[0]), GL_UNSIGNED_SHORT, 0);
    glBindVertexArray(0);

    //select back_right buffer  <-- SEEMS TO ONLY RENDER FROM HERE, MISSING THE FIRST PART
    glDrawBuffer(GL_BACK_RIGHT);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //set projection and view for back_right
    projectionMatrix = glm::frustum(-xCoord + frustumAssymmetry, xCoord + frustumAssymmetry, -yCoord, yCoord, 0.1f, 200.0f);
    projectionMatrix *= glm::translate(glm::mat4(1.0f), glm::vec3(-eyeOffset, 0.0f, 0.0f));
    glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, value_ptr(projectionMatrix));
    glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &viewMatrix[0][0]);

    //set model matrix for rendering calls   
    modelMatrix = scale(mat4(1.0f), vec3(0.7, 0.7, 0.5f));
    modelMatrix *= translate(mat4(1.0f), vec3(0.0f, 0.0f, 0.0f));
    modelMatrix *= rotate(mat4(1.0f), i+=0.04, vec3(0.0f, 1.0f, 0.0f));
    glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]);

    //draw VAO
    glBindVertexArray(vikingVAO);
    glDrawElements(GL_TRIANGLES, viking_elements.size() * sizeof(viking_elements[0]), GL_UNSIGNED_SHORT, 0);
    glBindVertexArray(0);

    //clear shader
    shader->ClearShaderProgram();

    //swap buffers
    glXSwapBuffers(display, win);
}

EDIT: Realised that if I run my application on the right screen it renders the GL_BACK_RIGHT buffer. Running it on the left screen draws the GL_BACK_LEFT.

Any ideas? Monitor settings maybe?

  • Are you sure that `GL_BACK_LEFT` is available and initialized properly? There are ways to check that. – Bartek Banachewicz Nov 20 '12 at 15:31
  • I am checking `GL_STEREO` and it comes back true. If I take out the `GL_BACK_RIGHT` rendering it does indeed render the `GL_BACK_LEFT`. Also realised that if I run the application on my left screen it renders the `GL_BACK_LEFT` and on my right on it draws `GL_BACK_RIGHT`. Could it be my monitors settings? – Dragos Budan Nov 20 '12 at 18:19

0 Answers0