1

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();

    }
genpfault
  • 51,148
  • 11
  • 85
  • 139
jaiesh
  • 146
  • 2
  • 12
  • Could it be because I am enabling lights inside displayEnvironment? – jaiesh Nov 30 '11 at 03:09
  • 1
    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). – Jim Buck Nov 30 '11 at 03:18
  • Double buffer and make sure displayEnvironment doesn't clear stuff itself? –  Nov 30 '11 at 03:23
  • 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 – jaiesh Nov 30 '11 at 03:24
  • @pst It is double buffer and displayEnvironment does not clear anything. Sorry for the lack of detail on how it looks. – jaiesh Nov 30 '11 at 03:27
  • Now only the PiP screen flickers. Larger viewport stays solid. PiP keeps loading itself over and over from top to bottom. Like a wave. – jaiesh Nov 30 '11 at 03:33
  • 1
    Where/when are you swapping buffers? Maybe you're not waiting for the render to finish? – Jim Buck Nov 30 '11 at 03:43
  • @JimBuck haha I was just about to post an answer. Yeah that was the problem I was swapping buffers in displayEnvironment. – jaiesh Nov 30 '11 at 03:45
  • Hah, funny, well to give this question an official answer, I'll just repost my comment as an answer. – Jim Buck Nov 30 '11 at 03:54

1 Answers1

4

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

Jim Buck
  • 20,482
  • 11
  • 57
  • 74
  • Thanks. glutSwapBuffers was called inside of displayEnvironment. This was causing the flickering. Moved glutSwapBuffer down after the second displayEnvironment was called. – jaiesh Nov 30 '11 at 04:00