Sign in to follow this  

Texture coordinates problem

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;	
TerrainVertex * v = NULL;
int i = 0;
for(int z = (int)pNode->vBoundingCoords[0].y; z <= (int)pNode->vBoundingCoords[3].y; z += vertexSpacing)
	int j = 0;
	for(int x = (int)pNode->vBoundingCoords[0].x; x <= (int)pNode->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->vBoundingCoords[0].y/vertexSpacing))) + (j+(pNode->vBoundingCoords[0].x/vertexSpacing));
		v[v_index] = TerrainVertex((float)x,(float)0,(float)z,coordU,coordV);

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 this post

Link to post
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 this post

Link to post
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]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this