I have been messing around with XNA for a long while now, but have never really done much more than just copy/pasting tutorials and editing those. Since a bit I have been trying to really start to learn XNA but encountered a problem (or challenge, I suppose) that I can't seem to find any information on anywhere (or its there but I just don't see it).
So my question is.. Is there any way to draw multiple (different) textures on a Vertex Buffer?
I make one large Vertex Buffer out of an array of cubes to make sure no cube-sides are drawn when they aren't visible as well as not having to call the drawing device a million times if I would want to draw a million cubes.
Example, having two cubes in a row would be:
_ _
|_|_|
But obviously, the middle will never be seen (left cube's right side and right cube's left side) so they are not added to the Vertex Buffer.
So my question is, how do I get a different texture on both of these cubes even though they are part of the same Vertex Buffer?
A cube side is constructed like this, but will obviously have to have something in it that lets the buffer know this part will need this texture (instead of simply a color):
vertices.Add(new VertexPositionColor(new Vector3(x, y + 1, z + 1), Color.Purple));
vertices.Add(new VertexPositionColor(new Vector3(x, y, z + 1), Color.Purple));
vertices.Add(new VertexPositionColor(new Vector3(x, y, z), Color.Purple));
vertices.Add(new VertexPositionColor(new Vector3(x, y, z), Color.Purple));
vertices.Add(new VertexPositionColor(new Vector3(x, y + 1, z), Color.Purple));
vertices.Add(new VertexPositionColor(new Vector3(x, y + 1, z + 1), Color.Purple));
And the Vertex Buffer is filled like this:
if (vertices.Count > 0)
{
chunkVertexBuffer = new VertexBuffer(device, VertexPositionColor.VertexDeclaration, vertices.Count, BufferUsage.WriteOnly);
chunkVertexBuffer.SetData<VertexPositionColor>(vertices.ToArray());
}
Pretty standard stuff I believe, but I can't seem to work it out with textures as VertexPositionTexture will only let you add the texture when you assign the effect.. for the entire Vertex Buffer.