Game Development Reference
In-Depth Information
#region IDisposable Members
public void Dispose()
{
foreach (Texture t in _textureDatabase.Values)
{
Gl.glDeleteTextures(1, new int[] { t.Id });
}
}
#endregion
}
The class implements IDisposable ; it ensures that if the class is destroyed, it
will release the textures from memory. The only other function is Get ; this takes
a name of a texture and returns the associated texture data. If the data doesn't
exist, it will throw an exception.
The TextureManager class has one obvious omission: there is no function to
load the texture from the hard disk.
public void LoadTexture(string textureId, string path)
{
int devilId = 0;
Il.ilGenImages(1, out devilId);
Il.ilBindImage(devilId); // set as the active texture.
if (!Il.ilLoadImage(path))
{
System.Diagnostics.Debug.Assert(false,
"Could not open file, [" + path + "].");
}
// The files we'll be using need to be flipped before passing to OpenGL
Ilu.iluFlipImage();
int width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH);
int height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT);
int openGLId = Ilut.ilutGLBindTexImage();
System.Diagnostics.Debug.Assert(openGLId != 0);
Il.ilDeleteImages(1, ref devilId);
_textureDatabase.Add(textureId, new Texture(openGLId, width,
height));
}
Search WWH ::




Custom Search