I've written this down on paper and tried to understand how the triangles of each cube are created, but I can't get my texture drawn on my cube properly. I don't know if it's the texuture coordinates of each face of my cube, or the order in which I create the cube from my vertices, but I only see two sides correctly and the rest are gray.
private void SetUpFrontFace(Vector3 cubeInChunkPosition, List<VertexPositionTexture> vertices)
{
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(0, 0, 0), new Vector2(0, 1)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(0, 1, 0), new Vector2(0, 0)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(1, 1, 0), new Vector2(1, 0)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(1, 0, 0), new Vector2(1, 1)));
}
private void SetUpBackFace(Vector3 cubeInChunkPosition, List<VertexPositionTexture> vertices)
{
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(0, 0, -1), new Vector2(0, 1)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(0, 1, -1), new Vector2(0, 0)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(1, 1, -1), new Vector2(1, 0)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(1, 0, -1), new Vector2(1, 1)));
}
private void SetUpLeftFace(Vector3 cubeInChunkPosition, List<VertexPositionTexture> vertices)
{
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(0, 0, -1), new Vector2(0, 1)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(0, 1, -1), new Vector2(0, 0)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(0, 1, 0), new Vector2(1, 0)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(0, 0, 0), new Vector2(1, 1)));
}
private void SetUpRightFace(Vector3 cubeInChunkPosition, List<VertexPositionTexture> vertices)
{
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(1, 0, 0), new Vector2(0, 1)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(1, 1, 0), new Vector2(0, 0)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(1, 1, -1), new Vector2(1, 0)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(1, 0, -1), new Vector2(1, 1)));
}
private void SetUpTopFace(Vector3 cubeInChunkPosition, List<VertexPositionTexture> vertices)
{
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(0, 1, 0), new Vector2(0, 1)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(0, 1, -1), new Vector2(0, 0)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(1, 1, -1), new Vector2(1, 0)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(1, 1, 0), new Vector2(1, 1)));
}
private void SetUpBottomFace(Vector3 cubeInChunkPosition, List<VertexPositionTexture> vertices)
{
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(0, 0, 0), new Vector2(0, 0)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(0, 0, -1), new Vector2(0, 1)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(1, 0, -1), new Vector2(1, 1)));
vertices.Add(new VertexPositionTexture(cubeInChunkPosition + new Vector3(1, 0, 0), new Vector2(1, 0)));
}
private void SetUpIndicesAndVertices(float x, float y, float z, List<VertexPositionTexture> vertices, List<short> indices)
{
short verticesStart = (short)vertices.Count;
Vector3 cubeInChunkPosition = new Vector3(x, y, z);
SetUpFrontFace(cubeInChunkPosition, vertices);
SetUpBackFace(cubeInChunkPosition, vertices);
SetUpRightFace(cubeInChunkPosition, vertices);
SetUpLeftFace(cubeInChunkPosition, vertices);
SetUpTopFace(cubeInChunkPosition, vertices);
SetUpBottomFace(cubeInChunkPosition, vertices);
All my vertices being built. I think the texture coordinates are correct. They start from the top left corner rotating clockwise around the whole face.
indices.Add((short)(verticesStart + 0));
indices.Add((short)(verticesStart + 2));
indices.Add((short)(verticesStart + 3));
indices.Add((short)(verticesStart + 0));
indices.Add((short)(verticesStart + 1));
indices.Add((short)(verticesStart + 2));
indices.Add((short)(verticesStart + 1));
indices.Add((short)(verticesStart + 5));
indices.Add((short)(verticesStart + 6));
indices.Add((short)(verticesStart + 1));
indices.Add((short)(verticesStart + 6));
indices.Add((short)(verticesStart + 2));
indices.Add((short)(verticesStart + 2));
indices.Add((short)(verticesStart + 6));
indices.Add((short)(verticesStart + 7));
indices.Add((short)(verticesStart + 2));
indices.Add((short)(verticesStart + 7));
indices.Add((short)(verticesStart + 3));
indices.Add((short)(verticesStart + 4));
indices.Add((short)(verticesStart + 7));
indices.Add((short)(verticesStart + 6));
indices.Add((short)(verticesStart + 4));
indices.Add((short)(verticesStart + 6));
indices.Add((short)(verticesStart + 5));
indices.Add((short)(verticesStart + 1));
indices.Add((short)(verticesStart + 4));
indices.Add((short)(verticesStart + 5));
indices.Add((short)(verticesStart + 1));
indices.Add((short)(verticesStart + 0));
indices.Add((short)(verticesStart + 4));
indices.Add((short)(verticesStart + 0));
indices.Add((short)(verticesStart + 7));
indices.Add((short)(verticesStart + 4));
indices.Add((short)(verticesStart + 0));
indices.Add((short)(verticesStart + 3));
indices.Add((short)(verticesStart + 7));
The indices. I don't know why this is happening. I've messed around with the Texture values and have gotten textures to show on all sides, but they always come out skewed.