PiP in OpenGL causing flickering

Tag: opengl , glut , viewport Author: bluebuble Date: 2011-11-13

I am trying to set up a Picture in picture style "map" display for a graphics program that displays a car. (Just shows the view from top again in a smaller view port.) However, the second viewport seems to flicker. I thought I was doing this correctly, but I may be not conceptualizing this correctly.

void display(void) {


    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);


    // Set Perspective

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(fov, aspect, near, far);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glViewport(0, 0, 500, 500);
    // Lighting follows Camera if inserted here.


    //Set Camera
    calculateCamera();
    gluLookAt(eyeX + carPosX, eyeY + carPosY, eyeZ + carPosZ, cX + carPosX, 
              cY + carPosY, cZ + carPosZ, 0, 1, 0);


    displayEnvironment();


    glClear(GL_DEPTH_BUFFER_BIT);

    // Set Perspective

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(fov, aspect, near, far);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glViewport(0,0,150,150);

    gluLookAt(0, 140, 0,0, 0, 0, 1, 0, 0);

    displayEnvironment();

    }
Could it be because I am enabling lights inside displayEnvironment?
What kind of flicker is it? Is the PIP itself flickering (i.e. sometimes it is drawn on top of the rest of your backend, sometimes not)? Or is the image inside of the PIP flickering in some fashion? I think it would be helpful if you posted a couple screenshots of the two different "flicker" states (assuming there are only 2 states).
Double buffer and make sure displayEnvironment doesn't clear stuff itself?
I tried to but it won't. All the screen shots show an intact image. It sort of looks like a wave that starts at the bottom and leaves the top of the viewport and it is on the larger view port. It's as if it is redrawing the scene in a odd way
Where/when are you swapping buffers? Maybe you're not waiting for the render to finish?

Best Answer

Where/when are you swapping buffers? Maybe you're not waiting for the render to finish?

comments:

Thanks. glutSwapBuffers was called inside of displayEnvironment. This was causing the flickering. Moved glutSwapBuffer down after the second displayEnvironment was called.