Original Post
lets start off with some pictures:
ok i think the problem is fairly apparent.
Basically i am trying to throw the reflection of the landscape into a texture. I have it all worked out fine, except I seem to be getting z-buffer fights, and I am unsure how they are getting there. The first image is a shot of the terrain and the texture, the second image is just the texture. I tried extending the near plane but that didnt help. Im kind of at a loss, although I believe it has something to do with the clip plane. Here''s the relevant code:
Thanks in advance!
ok i think the problem is fairly apparent.
Basically i am trying to throw the reflection of the landscape into a texture. I have it all worked out fine, except I seem to be getting z-buffer fights, and I am unsure how they are getting there. The first image is a shot of the terrain and the texture, the second image is just the texture. I tried extending the near plane but that didnt help. Im kind of at a loss, although I believe it has something to do with the clip plane. Here''s the relevant code:
glPushMatrix();
glDisable(GL_FOG);
glViewport(0, 0, 512, 512);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fov, (float)screenWidth/(float)screenHeight, nearz, farz);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
flipView();
glTranslatef(0,-10,0);
double clipPlane[] = { 0, 10, 0, 0 };
glEnable(GL_CLIP_PLANE0);
glClipPlane(GL_CLIP_PLANE0, clipPlane);
drawmap(↦, true);
glDisable(GL_CLIP_PLANE0);
glBindTexture(GL_TEXTURE_2D,reflectiontex[0]);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 512, 512, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, screenWidth, screenHeight);
glPopMatrix();
... //Extra Stuff :)
// Configure the texture matrix to apply the reflection texture.
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5, 0.5, 0.0);
glScalef(0.5f, 0.5f, 1.0);
gluPerspective(fov, (float)screenWidth/(float)screenHeight, nearz, farz);
flipView();
glMatrixMode(GL_MODELVIEW);
glBindTexture(GL_TEXTURE_2D, reflectiontex[0]);
float aa = 100.0f;
glBegin(GL_QUADS);
// Create a texture mapped QUAD that has the new texture map on it
glTexCoord3f( 0, 0, 0 ); glVertex3f(0, 10, 0);
glTexCoord3f( 0, 0, aa ); glVertex3f(0, 10, aa);
glTexCoord3f( aa, 0, aa ); glVertex3f(aa, 10, aa);
glTexCoord3f( aa, 0, 0 ); glVertex3f(aa, 10, 0);
glEnd();