Tuesday, November 28, 2006

Rendering a textured cube


XNA Game Studio Express provides a number of helpful how-to guides. One such guide demonstrates the use of the framework's default material class "BasicEffect" to render a cube using 3D primitives.

When you run the sample code, you will see a colored cube rendered on screen (seen on the right).

That great. So now how do you render a bitmap textured cube?

Initially, I got a black cube instead of the expected rendered one. After tinkering around, I have managed to load a bitmap and assigned it to the basic effect material.

Here are a couple of learning points:
  1. To use bitmap textures, you need to :
    • Assign a loaded texture to the BasicEffect.Texture property
    • Enable texture rendering, set BasicEffect.TextureEnabled to true
  2. The framework calls Initialize() before LoadGraphicsContent(). Hence you should only assign your texture reference to the basic-effect material after you have loaded the bitmap.
Here is a screenshot of modded cube on the right. You can also download the project files here (UseBasicEffect.zip).

Please let me know if the link works and other comments.

1 comments:

ForgivenBoy said...

Confirmed--The link works. Thanks for the content☺