Skip to main content
gamedev.net
🔒 Locked

Reflection Texture Abnormalities

Started by toucel Feb 19, 2003 at 5:55 PM 2 replies 600+ views
Original Post
toucel
toucel
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:
  

	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();
  
Thanks in advance!
toucel
toucel
Come on someone has to have a clue... YannL?

[edited by - toucel on February 23, 2003 4:34:11 PM]
Ysaneya
Ysaneya
I''d suggest displaying the reflection texture as a single ortho quad (ie. not projected) to first know if the problem lies in generating it, or projecting it on the water quad.

Why is your clip plane (0, 10, 0, 0) ? I''d suggest trying (0, 1, 0, 10).

Y.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.