views:

341

answers:

1

I am trying to draw a textured cube using just 8 vertices and one DrawIndexedPrimitives call. Is this even possible?

I am having problems with the UV co-ordinates. I am finding it impossible to come up with suitable UV values which will work for all faces of the cube.

Take the following numbering as an example:

Cube with UV Values

UV is set to (0, 0) for vertex A. For all vertices diagonally opposite to A (on all three faces sharing A as a vertex), I am setting UV to (1, 1). Now the three faces which do not have A as a vertex end up having two vertices each which have a UV value of (1, 1). It is my understanding that this should not be the case.

What then is the solution?

+3  A: 

It is not possible if a single vertex has multiple UV coordinates.

To get around this problem duplicate the vertex position and assign each copy a unique UV coordinate. This will increase the number of vertices to 24 for a cube in the worst case (four per side).

This is btw what everyone does regardless if he's using OpenGL or DirectX. For a cube this may look like a lot of wasted memory, but in practice - with real world models - the amount of vertex duplication is not that high.

Afterwards you can draw the cube with a single call to DrawIndexedprimitive.

Nils Pipenbrinck