Game Development Reference
In-Depth Information
The DevIL library was written to complement OpenGL so it has a very similar
interface. An image is generated and then bound. Binding an image means all
subsequent operations will affect that image.
ilLoadImage
is called, which
loads the texture data into memory.
iluFlipImage
is called on the image, and
this flips it on the Y axis; most of the common image formats need to be flipped
to work correctly with OpenGL. The image is then queried for width and height
information. Finally, the DevIl utility library is used to bind the texture to an
OpenGL id. The id, width, and height are all wrapped in the texture class, which
is then returned. DevIl still has the texture data in memory; this is freed using
ilDeleteImages
, as the data has now been moved from DevIl to OpenGL.
Testing the
TextureManager
requires a texture. A TIF image file, called face.
tif, can be found on the CD in the Asset directory. Copy it into your project
directory. Then in Visual Studio, right-click the project and choose Add
>
Ex-
isting Item. We're going to add the TIF file to the project. This brings up a dialog
box. To see the image you will probably have to change the filter from
C# Files
to
All Files
. Select
face.tif
. The final step is to select the
face.tif
file in
the solution explorer, right-click, and select Properties, as shown in Figure 6.8.
A number of fields are displayed describing the properties of the image file.
Change the field Copy To Output Directory to Copy If Newer. This will copy the
image file over to the bin directory, and once you run the program, the file will
always be in the correct place. Adding the image file to the project isn't necessary,
but it's a simple way to keep track of the assets and to make sure they are put in
the right places.
The
TextureManager
object can be created in the Form.cs file and then passed
into any state that requires it.
TextureManager _textureManager = new TextureManager();
public Form1()
{
InitializeComponent();
_openGLControl.InitializeContexts();
// Init DevIl
Il.ilInit();
Ilu.iluInit();
Ilut.ilutInit();
Search WWH ::
Custom Search