Advertisement

problem with glCopyTexImage2D

Started by July 22, 2004 10:15 AM
2 comments, last by JazzD 20 years, 7 months ago
Hey, I'm trying to create a mirror surface using glCopyTexImage2D, the problem is when use the function directly I get a rendered texture like I want it but, as you know this is not a mirror, it's more or less a camera screen which will show what I'm currently looking at. Back to my problem: Now I had the idea to set up another Viewport and mirror the normal camera position and view vectors to create a mirror effect. No matter what I do somehow the glCopyTexImage2D is always affected but the first lookAt function from my camera. Look at the code and you will get that I set it to a static position, the mirrored image should be copied from a static point, but it's not, the image still moves with the camera... Hmmm Does anyone know what buffer I have to clear or how I have the add a new Viewport to get this working?
void RenderScene()
{
	showCursor=false;
	glColor3f(1.0f,1.0f,1.0f);
	
	
	if(playpath.play) {
		gluLookAt(playpath.xp, playpath.yp, playpath.zp,
             playpath.xv, playpath.yv, playpath.zv,
             0, 1, 0);
	} else {
		Camera.Look();
	}


	glEnable(GL_TEXTURE_2D);
	glEnable(GL_COLOR_MATERIAL);

	if(wireframe) {
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		glLineWidth(2.0f);
		glColor3f(0.0f,0.68359375f,0.8828125f);
	} else {
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	}



	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHTING);
	
	glCullFace(GL_FRONT);

	// Render the game
	Frustum.CalculateFrustum();
	Game.Render();

	glDisable(GL_LIGHT0);
	glDisable(GL_LIGHTING);
	glDisable(GL_FOG);

	glViewport(0, 0, Width(), Height());
    glMatrixMode(GL_PROJECTION); 
	glLoadIdentity ();
	gluPerspective( 120.0f, (GLfloat)Width()/(GLfloat)Height(), 1.0f, 80000.0f); 
 
    glLoadIdentity();

	gluLookAt(100, 121, 232,
			232, 11, 23,
			0, 1, 0);

	glEnable(GL_TEXTURE_2D);	

	glBindTexture(GL_TEXTURE_2D,g_Texture[789]);

	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 512,512, 0);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
	glTexGenf(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
	glTexGenf(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);


	glViewport(0, 0, Width(), Height());
    glMatrixMode(GL_PROJECTION); 
	glLoadIdentity ();
	gluPerspective( 55.0f, (GLfloat)Width()/(GLfloat)Height(), 1.0f, 80000.0f);
 
	glMatrixMode(GL_MODELVIEW);     
    glLoadIdentity();

	glCullFace(GL_BACK);
	
	glPushMatrix();
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
   		glLoadIdentity();								
		glTranslatef(0.0f,0.0f,-1.0f);
		if(!recording) {
			if(debugprint) {
				hud.Draw();
				//hud.DrawFPS();
			} else {
				hud.DrawFPS();
			}
		}
	glPopMatrix();

	if(EndFrame) {
		render = false;
		Mission.Restart();
	}
}
thanks in advance ;)
www.prsoftware.de
I've not read all your code, but the simple fact I don't see glScale with at least one component scaled by a negative value looks weird.

That kind of reflection involves some sort of glScalef(1.f, -1.f, 1.f);
Advertisement
You appear to be missing a call to glMatrixMode(GL_MODELVIEW) when you render the scene to the texture. Also you don't appear to be actually rendering the scene from the new point of view. Just changing the camera position won't have any effect. You need to render the scene again from the new point of view.

Enigma
hehe thanks for posting, I've already fixed it :), http://www.jazzd.de/forums/viewtopic.php?p=56#56 check this out for the end result I came up with!
www.prsoftware.de

This topic is closed to new replies.

Advertisement