PDA

View Full Version : Tex coord gen on a grid. please help..



Ace_Man
03-14-2001, 03:27 PM
I'm using vertex arrays to handle a grid of WIDTH * HEIGHT faces made of triangles..
(a really big tic-tac-toe board)

Can any of you offer tips on generating texture coords for this map? All the vertex data is stored in a one dimensional array of size WIDTH * HEIGHT.

I'm looking for a simple generic loop that can store all the coords needed to map a single texture across the entire grid...I'm not even sure how many texture coords there will be.

I can do this if I store my vertex values in
a 2 dimensional array and draw the grid with Quads in one big loop. I'm trying to use a more efficient way of doing this but I can't seem to visualize it in this manner...

I suspect this is simple. Any Ideas?

kieranatwork
03-16-2001, 06:24 AM
Yes, it's easy.
To get a scaling value, just divide 1.0f by the width of the grid (number of grid elements, not world width).
Then as you traverse the grid, creating your vertex array, just multiply the current grid x by the scaling value, and insert the result as your 's' coordinate.
Do the same for the height and 't' coordinate.
Just in case you don't know, to access an element in a one dimensional array as if it was a two dimensional array, use the following formula :-
contents = array[(y*width)+x];
And if each of your elements in the array has more than one component (say, x,y,z,s,t), then your formula should be this:-
contents = array[(y*width*stride)+x*stride];