Texture mapping and height map

Hello.

Im using auto generation of coords to texture mapping, and Im using a height map loader I want to know how to make 1 texture applied for all the map, not for every QUAD.

sorry about english.

my code:

int LoadGLTextures(char *filename, int id)
{
int status = false;
AUX_RGBImageRec TextureImage = NULL;
ZeroMemory(&TextureImage, sizeof(void
)*1);
if (TextureImage = LoadBMP(filename))
{
GLfloat terrain = {1.0, 0.0, 0.0, 0.0};
status = true;
glGenTextures(1, &texture[id]);
glBindTexture(GL_TEXTURE_2D, texture[id]);

 gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage->sizeX, TextureImage->sizeY,
  GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data);     

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv(GL_S, GL_OBJECT_PLANE, terrain);

}
if (TextureImage)
{
if (TextureImage->data)
free(TextureImage->data);
free(TextureImage);
}
return status;
}

void RenderHeightMap(BYTE pHeightMap)
{
GLfloat x,y,z,X=0,Y=0;
if(!pHeightMap) return;
glBegin(GL_QUADS);
for ( X = 0; X < MAP_SIZE; X += STEP_SIZE )
for ( Y = 0; Y < MAP_SIZE; Y += STEP_SIZE )
{
x = X;
y = Height(pHeightMap, X, Y );
z = Y;
glTexCoord2f(0.0, 0.0);
glVertex3f(x, y*ELEVATION, z);

  	x = X;
  	y = Height(pHeightMap, X, Y + STEP_SIZE );
  	z = Y + STEP_SIZE ;
  glTexCoord2f(0.0, 1.0);
  glVertex3f(x,y*ELEVATION, z);

  	x = X + STEP_SIZE;
  	y = Height(pHeightMap, X + STEP_SIZE, Y + STEP_SIZE );
  	z = Y + STEP_SIZE ;
    glTexCoord2f(1.0, 1.0);
  glVertex3f(x, y*ELEVATION, z);

  	x = X + STEP_SIZE;
  	y = Height(pHeightMap, X + STEP_SIZE, Y );
  	z = Y;
    glTexCoord2f(1.0, 0.0);
  glVertex3f(x, y*ELEVATION, z);
  }

glEnd();
}

A lot of thanks!

Instead of using 1 for your tex coord, use (1/MAP_SIZE)*X
and (1/MAP_SIZE)*Y, for each coordinate

Like this? (didnt work)

void RenderHeightMap(BYTE pHeightMap)
{
GLfloat x,y,z,X=0,Y=0;
if(!pHeightMap) return;
for ( X = 0; X < MAP_SIZE; X += STEP_SIZE )
for ( Y = 0; Y < MAP_SIZE; Y += STEP_SIZE )
{
x = X;
y = Height(pHeightMap, X, Y );
z = Y;
glTexCoord2f(0.0, 0.0);
glVertex3f(x, y*ELEVATION, z);

  	x = X;
  	y = Height(pHeightMap, X, Y + STEP_SIZE );
  	z = Y + STEP_SIZE ;
  glTexCoord2f(0, (1/MAP_SIZE)*Y);
  glVertex3f(x,y*ELEVATION, z);

  	x = X + STEP_SIZE;
  	y = Height(pHeightMap, X + STEP_SIZE, Y + STEP_SIZE );
  	z = Y + STEP_SIZE ;
    glTexCoord2f((1/MAP_SIZE)*X, (1/MAP_SIZE)*Y);
  glVertex3f(x, y*ELEVATION, z);

  	x = X + STEP_SIZE;
  	y = Height(pHeightMap, X + STEP_SIZE, Y );
  	z = Y;
    glTexCoord2f((1/MAP_SIZE)*X, 0);
  glVertex3f(x, y*ELEVATION, z);
  }

}

It should work if you change your code to the following:

glTexCoord2f((1/MAP_SIZE)*x, (1/MAP_SIZE)*z);

I think if you use the same line of code for all four of your texCoord calls it should work because x and z are being updated for each vertex.

[This message has been edited by Brent Fogarty (edited 01-14-2002).]