Reputation: 35
I am trying to create two viewports in my window: a main, full screen view and a smaller view in the upper left corner. I've looked the issue up and looked at the solutions: I am using glScissor() and glViewport(), clearing my depth buffer bit, enabling my depth buffer bit, and rendering only once (after a for loop). But clearly, I am missing something. Here is my code. Thank you in advance.
Edit: link to screenshots: http://imgur[dot]com/a/sdoUy Basically, the upper left mini viewport flickers, disappearing and reappearing very quickly.
void viewports() {
float width = wWidth;
float height = wHeight;
for (int i = 0; i < 2; i++) {
glClearColor(.392,.584,.929,0.0f);
if (i == 0) {
//main view
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0,0,(GLsizei)width,(GLsizei)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60,(GLfloat)width/(GLfloat)height,1.0,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
keyOp();
camera();
} else if (i == 1) {
glScissor(0,height - height/3,(GLsizei)height/3,(GLsizei)height/3);
glEnable(GL_SCISSOR_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
glViewport(0,height - height/3,(GLsizei)height/3,(GLsizei)height/3);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60,1,1.0,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,40,-15,0,-1,-15,1,0,0);
glDisable(GL_SCISSOR_TEST);
}
renderScene();
}
}
Upvotes: 2
Views: 2066
Reputation: 35933
Don't call glutSwapBuffers in renderscene. You call renderscene twice per frame (for i==0 and i==1), so you're drawing main screen, swap, draw minimap, swap, repeat.
You need to draw both main and minimap, and then swap.
Also don't bother calling glClearColor so many times, you only need to call it once at init.
Upvotes: 3
Reputation: 1233
Not sure if it will help with your flickering problem but I notice you have written:
glClearColor(.392,.584,929,0.0f);
With the third parameter being 929 instead of what I assume you wanted, .929
Upvotes: 0