i have 2 surfaces that am trying to render at the same time. the surfaces cross each other many times giving me horrible Z-fighting/artifacts. i dont do any translating, i use gluLookAt, so x,y and z change when you hit certain keys on the keyboard. all of that can be seen below. how would i get rid of this z-fighting or at least improve it to where i can get it to looking better. Thanks all a lot for your help and info in advance..
//global stuff
float x = 0.0;
float y = 0.0;
float z = -3000.0;
void myReshape(GLsizei width, GLsizei height)
{
if (height==0) // Prevent A Divide By Zero By
{ height=1;} // Making Height Equal One
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
setWidthHeight(width, height);
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,2000000.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
glutPostRedisplay();
}
void draw()
{
.........
.........
gluLookAt(x, y, z, 0.0, 0.0, 500000.0, 0.0, 1.0, 0.0); //cam pos, eye, up
//draw_surfaces
.........
.........
}
void specialKey(int key, int i, int j)
{
switch(key)
{
case GLUT_KEY_HOME:
break;
case GLUT_KEY_UP:
z += speed;
break;
case GLUT_KEY_DOWN:
z -= speed;
break;
case GLUT_KEY_LEFT:
x -= speed;
break;
case GLUT_KEY_RIGHT:
x += speed;
break;
case GLUT_KEY_PAGE_UP:
y += speed;
break;
case GLUT_KEY_PAGE_DOWN:
y -= speed;
break;
} //end switch
GLUI_Master.sync_live_all();
glutPostRedisplay();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(1280, 1024);
glutInitWindowPosition(100, 50);
window = glutCreateWindow("test");
InitGL(1280, 1024, file);
glutDisplayFunc(draw);
.....
.....
.....
GLUI_Master.set_glutSpecialFunc(specialKey)
.....
.....