Quote:Original post by Coder
This is a big problem then. I wonder how I can make the indicies get sorted the same as the vertices. See if I sort the vertices by z value, indicies don't have a z value to sort by. I guess I can make a struct that contains the index and a z value, then sort the list of structs and then fill another list (of shorts) with the indicies (now sorted) and then memcpy the sorted indicies over the existing data in the index buffer.
This won't work. Consider the following vertices:
<0, 0, 20>
<0, 0, 2.5>
<0, 0, 15>
And the indices: 0, 1, 2
If you sort vertices by Z, and the indices by the Z of their indexed vertices you'd get:
<0, 0, 2.5>
<0, 0, 15>
<0, 0, 20>
Indices: 1, 2, 0
Which is not what you want. You want them to be "2, 0, 1", to preserve the winding (clockwise or anti-clockwise).
EDIT: Why do you want to z-sort the vertices, anyway? It makes sense to z-sort triangles/faces, but not vertices. Unless you're doing point sprites, but then you don't need index buffers for point sprites.
[Edited by - Coder on May 26, 2005 9:33:21 AM]