Game Development Reference
In-Depth Information
Rendering a cube
In this section we will render a cube since it is actually 3D, unlike our triangle in the
previous demo. We will modify the project from the previous demo to create the cube
demo. In the downloadable code for this chapter, you will find the code for the cube
demo in a separate project so you can look at the code for both demos. The
Tri-
angle
project is set as the startup project by default. When you want to run the
Cube
demo, remember that you will have to set the
Cube
project as the startup project to
run it.
To get started, we will add an enumeration named
GraphicsMode
. We will use it to
specify how we will render our cube. This enumeration looks like the following:
enum GraphicsMode
{
SolidBlue = 0,
PerVertexColoring,
Textured
}
The first option will make the program render all the pixels of the cube blue. The
second option renders the cube using colors specified with each vertex and blending
them across each
face
(or side) of the cube. And the third option will render our
cube with a texture on it, which happens to be the red brick tile from our 2D demo in
resent a vertex since we need to store more information for each vertex now. We will
name it
Vertex
. It looks as follows:
struct Vertex
{
public Vector4 Position;
public Color4 Color;
public Vector2 TexCoord;
}