Sign in to follow this  
subi

small texture matrix prob

Recommended Posts

Hello I am having a few problems getting reflections to work, i am pretty close and just need a little hand
void UpdateTextReflection()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, M_SIZE, M_SIZE);

glMatrixMode(GL_TEXTURE);
  glLoadIdentity();
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glGetFloatv(GL_MODELVIEW_MATRIX, View);
  glGetFloatv(GL_PROJECTION_MATRIX, Proj);
  glLoadMatrixf(Proj);
  glMultMatrixf(View);  
  glScalef(1, -1, 1);
  glPopMatrix();
 
  glEnable(GL_CLIP_PLANE0);
  glClipPlane(GL_CLIP_PLANE0, CP);
  RenderWall();
  glDisable(GL_CLIP_PLANE0);

  glBindTexture(GL_TEXTURE_2D, mirror);
  glCopyTexSubImage2D(GL_TEXTURE_2D, 0,0,0,0,0,M_SIZE, M_SIZE);

  glViewport(0, 0, Width, Height);

   glMatrixMode(GL_TEXTURE);
    glLoadIdentity();
    glTranslatef(0.5, 0.5, 0.0); //centre the texture
    glScalef(0.5, 0.5, 0);
    gluPerspective(video.GetFOV(),(GLfloat)Width/(GLfloat)Height, video.GetZNear(),video.GetZFar());
	  glLoadMatrixf(View);
	
  glMatrixMode(GL_MODELVIEW);
}

void RenderScene()
{
	UpdateTextReflection();
	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glClearColor(0.2f, 0.5f, 1.0f, 1.0f);
	glLoadIdentity();
	camera.Look();
	
	glMatrixMode(GL_TEXTURE);
  glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
 	RenderWall(); //render brick wall
	glMatrixMode(GL_TEXTURE);
  glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	

	glDisable(GL_LIGHTING);
	glColor4fv(WATERCOLOR);

	glActiveTextureARB(GL_TEXTURE1_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,water.TextureID);
	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);

	glActiveTextureARB(GL_TEXTURE0_ARB);
	glBindTexture(GL_TEXTURE_2D,mirror);

	RenderWater(); //render water plane

	glColor4f(1, 1, 1, 1);
    glEnable(GL_LIGHTING);
  glActiveTextureARB(GL_TEXTURE1_ARB);
    glDisable(GL_TEXTURE_2D);
  glActiveTextureARB(GL_TEXTURE0_ARB);

	SwapBuffers();
}

as u can see i am rendering my brick wall to a texture in order to reflect it onto the water. The water and the brick wall render just perfect, the reflection shows up but moves around with the mouse and looks really wrong, so i know i am stuffing something up around the texture matrix. Thanks for any help

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this