   Texture mapping on terrain
  HiI need to map a texture on a terrain.The terrain is a triangle mesh, x*y vertexfor(int i=0; i < x-1; i++){for (int j = 0; j < y-1; j++){glBegin(GL_TRIANGLE_STRIP);glNormal3fv(normals[j]);glTexCoord2f(0, 0); glVertex3fv(vertex[j]);glNormal3fv(normals[i+1][j]);glTexCoord2f(0, 0); glVertex3fv(vertex[i+1][j]);glNormal3fv(normals[j+1]);glTexCoord2f(0, 0); glVertex3fv(vertex[j+1]);glNormal3fv(normals[i+1][j+1]);glTexCoord2f(0, 0); glVertex3fv(vertex[i+1][j+1]);glEnd();}}andglBindTexture(GL_TEXTURE_2D, texture[loop]);glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);What I need is that the texture borders match the terrain borders, so the texture's size match the terrain sizeWith the above code the texture is repeated for every triangle couple, looking like a chessboardWhat can I do to map the texture correctly?ThanksBye   
  Actually, with the code you posted, you will get a single texel across everything (as the texture coordinates are all 0).To map a texture across a terrain of N vertices across (index 0..(N-1)), you set the texture coordinate to (float(index)/(N-1)).Thus, something like:glBegin(GL_QUADS)for (int i = 0; i < x-1; ++i) {  for (int j = 0; j < y-1; ++j) {    glNormal3fv(normals[j]);    glTexCoord2f(float(i)/(x-1), float(j)/(y-1)); glVertex3fv(vertex[j]);    glNormal3fv(normals[i+1][j]);    glTexCoord2f(float(i+1)/(x-1), float(j)/(y-1)); glVertex3fv(vertex[i+1][j]);    glNormal3fv(normals[i+1][j+1]);    glTexCoord2f(float(i+1)/(x-1), float(j+1)/(y-1)); glVertex3fv(vertex[i+1][j+1]);    glNormal3fv(normals[j+1]);    glTexCoord2f(float(i)/(x-1), float(j+1)/(y-1)); glVertex3fv(vertex[j+1]);  }}glEnd();Also, note that a single swoop of GL_QUADS drawing is significantly faster than a number of GL_TRIANGLE_STRIP draws. glBegin() often has a noticeable cost on modern hardware (as in "batching cost").;  ouchi feel like a moronI tried that before posting, but I just realized that I forgot to cast to floatX_XWorks fine now, thank youThanks for the advice on QUADSBye   ;Another question....How can I rotate or mirror the texture on my mesh?I need to mirror and rotare by 90 deegrees the texture, what should I do?thanks again   ;  To mirror AND rotate 90, switch the u and v coordinates around.Just to mirror vertically use 1.0f - v   ;  perfect, thanks   ;  You can also scale, rotate, translate, or otherwise arbitrarily transform the texture matrix (glMatrixMode(GL_TEXTURE)) just like you would with the modelview matrix.  That may be more intuitive than manually altering the texture coordinates, depending on what it is you're doing.EDIT: Fixed a typo[Edited by - Kalidor on June 22, 2006 9:31:01 AM]