Jump to content
  • Advertisement
Sign in to follow this  
Xpyder

Texturing Terrain based on Height

This topic is 4600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys I am working on a 3D terrain engine, and so far it loads a wireframe, colored island onto the screen based on a heightmap. The color settings use the height by a few simple ifs:
if (CV[x + (y * WIDTH)].Z == 0) { CV[x + (y * WIDTH)].Color = Colorif0.ToArgb();}
if (CV[x + (y * WIDTH)].Z == 1) { CV[x + (y * WIDTH)].Color = Colorif1.ToArgb();}
if (CV[x + (y * WIDTH)].Z == 2) { CV[x + (y * WIDTH)].Color = Colorif2.ToArgb();}
if (CV[x + (y * WIDTH)].Z >= 3) { CV[x + (y * WIDTH)].Color = Colorif3.ToArgb();}
but now i need to texture it instead of just colour it, so i sorted out the texture coordinates etc so it would basically render the whole thing in one texture, but when i tried to do the same sort of thing by doing the following:
for (int xy = 0; xy < WIDTH * HEIGHT; xy++)
{
  if (vertices[xy].Z == 0) 
  {
   device.SetTexture(0, tWater);
   device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,4,0,                      indices.Length/3);
  }
  if (vertices[xy].Z == 1)
  {
    device.SetTexture(0, tSand);
    device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, indices.Length / 3);
  }
  if (vertices[xy].Z == 2) 
  {
    device.SetTexture(0, tGrass);
    device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, indices.Length / 3);
  }
  if (vertices[xy].Z >= 3) 
  {
  device.SetTexture(0, tRock);
  device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, indices.Length / 3);
  }

It will only render the top-most texture. 
I have tried changing the numVertices parameter in DrawIndexedPrimitives (currently "4") from 1, to the maximum vertices but it has the same result. 

Can anyone offer any pointers (oh god i miss pointers) on this?

             }

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Umm... Are your "vertices[xy].Z" all int/long's? Otherwise you're only doing something if it's EXACTLY on that. I would suspect your coordinates were done in floats therefore you need to take into consideration 3.0001 to 3.9999 not just 3.0000.

You gave us nearly no information. Try posting some sample data, or telling us what vertices[xy].Z is, etc. Not using these puppies, "", might be your issue...

Share this post


Link to post
Share on other sites
thanks

Other information like datatypes would not help, "4" was my mistake but not in the code.

Is there anybody i could add to MSN and we can sort it out that way?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!