# Texture coordinates problem

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

## Recommended Posts

Hi, I'm having trouble generating textures coordinates for the cells of my terrain Here is the code :
int v_index = 0;
int HeightIndex = 0;
CDXObjects::Instance().getDevice()-&gt;CreateVertexBuffer(NumVertices*sizeof(TerrainVertex),D3DUSAGE_WRITEONLY,TerrainVertex::FVF,D3DPOOL_DEFAULT,&pNode-&gt;vBuffer,NULL);
TerrainVertex * v = NULL;
pNode-&gt;vBuffer-&gt;Lock(0,0,(void**)&v,0);
int i = 0;
for(int z = (int)pNode-&gt;vBoundingCoords[0].y; z &lt;= (int)pNode-&gt;vBoundingCoords[3].y; z += vertexSpacing)
{
int j = 0;
for(int x = (int)pNode-&gt;vBoundingCoords[0].x; x &lt;= (int)pNode-&gt;vBoundingCoords[3].x; x += vertexSpacing)
{
v_index = i * numVerticePerSide + j;
coordU = ((float)j)/16.0f;
coordV = ((float)i)/16.0f;
HeightIndex = ((i * FileWidth)+(FileWidth*(pNode-&gt;vBoundingCoords[0].y/vertexSpacing))) + (j+(pNode-&gt;vBoundingCoords[0].x/vertexSpacing));
v[v_index] = TerrainVertex((float)x,(float)0,(float)z,coordU,coordV);
j++;
}
i++;
}
pNode-&gt;vBuffer-&gt;Unlock();
return;


I divide coordU and coordV by 16.0 but it is just a random number to test In fact the problem is that coordU has no influence, I can set it to what ever I want it doesn't change anything..... But coordV does work fine, the coordinates are not good at all! If you have any ideas....... Thanx. [Edited by - Grigou on August 13, 2008 4:28:00 PM]

##### Share on other sites
Try stepping through your code in debug mode, line by line, examining the values of x, z, i and j and see if they're what they should be.

For instance, is j incrementing correctly? Do you get reasonable values for coordU and coordV? Is j always less than numVerticePerSide?

EDIT: What is TerrainVertex::FVF? It appears that it should be D3DFVF_XYZ | D3DFVF_TEX1. Is that what you have it set to?

##### Share on other sites
Well, sorry for the code part, i'm new and I dont know how it works....

So this is my vertex declaration :
TerrainVertex::FVF = D3DFVF_XYZ|D3DFVF_TEX1;
It should be fine .....

Before is was creating my terrain cells one by one and the texture coordinates where working fine.
Now I am using a QuadTree to manage the terrain.
I am checking all the variables...

Thanx for the replies

EDIT : Okay I solved the problem after a few hours of research....
Seems like the terrain vertices were not getting the proper vertex declaration
Anyway thank you for spending some time on this thread

[Edited by - Grigou on August 14, 2008 5:10:08 AM]

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 23
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631768
• Total Posts
3002242
×