Game Development Reference
In-Depth Information
6.
This also happens with RGBA bitmaps that contain an alpha channel:
if ( BMPRec.FBitmapFormat == L_BITMAP_BGRA8 )
{
#if defined( ANDROID )
*InternalFormat = GL_RGBA;
*Format = GL_RGBA;
#else
*InternalFormat = GL_RGBA8;
*Format = GL_BGRA;
#endif
}
return false;
}
This function can be easily extended to work with grayscale, loat, and compressed formats.
How it works…
Using our texture wrapper is straightforward:
clPtr<clBitmap> Bmp = clBitmap::LoadImg(
g_FS->CreateReader("test.bmp") );
Texture = new clGLTexture();
Texture->LoadFromBitmap( Bmp );
Here,
g_FS
is a
FileSystem
object that we created in
Chapter 5
,
Cross-platform Audio
Streaming
.
There's more…
The texture loading we have dealt with so far is synchronous and is performed on the main
rendering thread. This is acceptable if we only have a few bitmaps to load. The real-world
approach is to load and decode images asynchronously, on another thread and then call
glTexImage2D()
and other related OpenGL commands only on the rendering thread.
We will learn how to do this in
Chapter 9
,
Writing a Picture Puzzle Game
.
See also
F
Chapter 4
,
Organizing a Virtual Filesystem
F
Chapter 9
,
Writing a Picture Puzzle Game