Ok, I have found no really good explanation of how to properly calculate texture coordinates for this problem ... mebbe someone can help me out.
I have a variable size terrain whose dimensions as passed to glVertex3f are :
X Axis : -xMinT to xMaxT
Y Axis : -yMinT to yMaxT
(Note Z is up in this system)
So I want to staple the texture onto the terrain map with a 1:1 correspondence and rely on scaling the texture matrix to distort it at run time.
My last effort went like this ...
Compute the scaling functions ...
and my function to place a vertex and staple its texture coordinate ...Code :// Compute function to map range [xMinT,xMaxT] onto [0,1] m_TexCoordSlope[0] = 1.0f/float(xMaxT-xMinT); m_TexCoordIntercept[0] = -float(xOffset)*m_TexCoordSlope[0]; // Compute function to map range [yMinT,yMaxT] onto [0,1] m_TexCoordSlope[1] = 1.0f/float(yMaxT-yMinT); m_TexCoordIntercept[1] = -float(yOffset)*m_TexCoordSlope[1];
The code that places the vertex is ...Code :void TerrainRenderer: : placeVertex(float x, float y, float z) { double z2 = z*m_ScaledElevationSlope+m_ScaledElevationIntercept; setHeightColor(z); glVertex3f(x,y,z2); float xt = m_TexCoordSlope[0]*x + m_TexCoordIntercept[0]; float yt = m_TexCoordSlope[1]*y + m_TexCoordIntercept[1]; glTexCoord2f(xt,yt); }
Well, I end up with a really nicely textured terrain but that texture is repeated over the terrain roughly 100 times in each direction when m_TexStretch[i] = 1. I want that case to result in the texture being stapled to the corners with a ONE TO ONE match of the texture to the terrain map.Code :glMatrixMode(GL_TEXTURE); glPushMatrix(); glScalef(m_TexStretch[0],m_TexStretch[1],1); glMatrixMode(GL_MODELVIEW); // ... placeVertex(terrainX, terrainY, terrainZ); // ... glMatrixMode(GL_TEXTURE); glPopmatrix(); glMatrixMode(GL_MODEL_VIEW); // ...
Does anyone see what I am doing wrong? Or, are the better ways to do this?
Thanks in advance ...
Ice out
[This message has been edited by Iceman (edited 09-21-2002).]



