Texture coordinates problem

Started by
2 comments, last by Grigou 15 years, 8 months ago
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()->CreateVertexBuffer(NumVertices*sizeof(TerrainVertex),D3DUSAGE_WRITEONLY,TerrainVertex::FVF,D3DPOOL_DEFAULT,&pNode->vBuffer,NULL);
TerrainVertex * v = NULL;
pNode->vBuffer->Lock(0,0,(void**)&v,0);
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);
		j++; 
	}
	i++;
}
pNode->vBuffer->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]
Advertisement
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?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

1) Please use the source bbcode markup around code blocks

2) You don't show us your vertex structure or the FVF for the vertex.

3) Perhaps Chapter 5. Modeling and Chapter 11. Basic Texturing from my book "The Direct3D Graphics Pipeline" will help.

My free book on Direct3D: "The Direct3D Graphics Pipeline"
My blog on programming, vintage computing, music, politics, etc.: Legalize Adulthood!

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]

This topic is closed to new replies.

Advertisement