Texture Coordinates

Started by
1 comment, last by stringa 15 years, 9 months ago
Well, I'm trying to create water. I want to simulate a wave by moving the texture coordinates of a quad by some amount. Thus the lookup to the noise texture will be displace for which I will use that displacement in my projected texture lookup. I have everything working except the noise texture lookup. The Main Function


  // ....
  // Reflection stuff above

  SHADERS.SetCurrentShader( GRAPHICS::GLSLShaderManager::ST_WATER );
  SHADERS.SetUniformSampler( GRAPHICS::GLSLShaderManager::ST_WATER, "noise", 1);
  SHADERS.SetUniformSampler( GRAPHICS::GLSLShaderManager::ST_WATER, "reflection", 0);

  Enable2DTexture( 1, GetTexture("noise.bmp") );
  Enable2DTexture( 0, BlankTexID );

// Using these 2 calls below slow the framerate down to 1 Frame / 5 secs
//  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
//  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

  SetupWaterTextureMatrix( 1 );

  DrawTexturedFloorQuad2();




All Helper Functions below

void SetupWaterTextureMatrix( unsigned active_texture )
{

  glMatrixMode( GL_TEXTURE );
  glActiveTexture(GL_TEXTURE0 + active_texture );
  glEnable(GL_TEXTURE_2D);

  glLoadIdentity();

  glTranslatef (0.5, 0.5, 0.5);
  glScalef (0.5, 0.5, 0.5);
  glMultMatrixf(current_camera->GetProjection());
  glMultMatrixf(current_camera->GetCameraMatrix());

}



I think the problem may have to either do with the Texture Coordinates, but I am not sure

void DrawTexturedFloorQuad2(void)
{

  glMatrixMode( GL_MODELVIEW );
  glLoadIdentity();
  glLoadMatrixf( current_camera->GetCameraMatrix() );


  static float time = 0.0f;
  time += 0.001f;

  glBegin( GL_QUADS );

  glTexCoord2f(0.0f + time, 0.0f); 
  glVertex3f( -100.0f,0.0f, 100.0f );
  glTexCoord2f(0.0f+ time, 1.0f); 
  glVertex3f( -100.0f, 0.0f, -100.0f );
  glTexCoord2f(1.0f+ time, 1.0f); 
  glVertex3f(  100.0f, 0.0f, -100.0f );
  glTexCoord2f(1.0f+ time, 0.0f); 
  glVertex3f(  100.0f, 0.0f, 100.0f );

  glEnd();
}




void Enable2DTexture( unsigned active_texture, unsigned oGL_id)
{
  glActiveTexture( GL_TEXTURE0 + active_texture );

  glEnable( GL_TEXTURE_2D );
  glBindTexture( GL_TEXTURE_2D, oGL_id );

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // far from camera
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // close to camera
}





Advertisement
Are you using VTF to do this? And if so what hardware are you on? What formats are you using...
I am not using VTF at all due to the fact that my ATI card doesn't support it. All i am doing is rendering the scene upside down and clipping everything above the water plane. Then I use glCopyTexSubImage2D to take a snapshot of the buffer.

All this works.

Then I have the code that you see above. I just projected that copied reflection to a quad that I call water.

I was trying to displace my noise lookup by using glTexCoord2f(0.0f + time, 0.0f); For some reason I'm not getting the result's i was expecting. I'm wondering if i possible missed some texture parameters.

I'm thinking about taking a different approach and sending uniforms to the shader for noise texture displacement.

This topic is closed to new replies.

Advertisement