terrain borders

Started by
3 comments, last by Tauqeer 18 years, 7 months ago
hello, i am texturing my terrain(which is without hightmap) as tiles applying a texture to one quad but it is not fitting at the quad. a small line of texture is going to the other end of quad looking it real bad and i dont know what to do. here is the code for filling the vertex data --------------------------------------------------------------------------------- int row = 0; for(int z = startZ; z >= endZ; z -= cellSpacing) { int column = 0; for(int x = startX; x <= endX; x += cellSpacing) { index = row * numVerPerRow + column; vertices[index] = VERTEX_FORMAT((float)x,0.0f,(float)z, (float)column,//tex1 (float)row);//tex2 column++; } row++; } -------------------------------------------------------------------------------
Advertisement
If it is a one-texel line, then I must assume that you're attempting to stretch a texture precisely over the entire quad. At the edges, due to small rounding errors, the texture may then wrap. Obviously, you don't want this to happen, so you should switch the texture addressing mode to "clamp" instead (from the default "wrap").

In Direct3D:
//Assuming texture stage 0lpdev->SetTextureStageState (0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);lpdev->SetTextureStageState (0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);//switch back to normal by using D3DTADDRESS_WRAP for the last parameter


In OpenGL:
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);//switch back to normal by using GL_REPEAT for the last parameter
Kippesoep
i have used CLAMP mode but all of my quads except the first have texture coords out of 0-1 range so CLAMP change all those quads too. i need a range out of 0-1 for drawing textures like tiles.
In that case, you should do one or more of the following:

  • make sure your textures are tileable

  • bring all coordinates in 0..1 range

  • offset texture coordinates for edge vertices by one half of a texel



The first two are self explanatory. The third would eliminate the effects of these rounding errors, but may be a bit more difficult. What you do is make sure that the edge texture coordinates are not 0.00 and 1.00, but 0.00+0.5/texture_resolution and 1.00-0.5/texture_resolution. (So, for 1024x1024 textures, they would be 0.00048828125 and 0.99951171875 instead of 0 and 1). This way, the edge no longer lies in between texels (where the wrapping/clamping occurs), but inside the texels.
Kippesoep
thanks a lot for your help Kippesoep.

This topic is closed to new replies.

Advertisement