Game Development Reference
In-Depth Information
m_bits,
// Pointer to bits
m_bmi,
// BITMAPINFO
DIB_RGB_COLORS,
// Options
SRCCOPY);
// Raster operation code (ROP)
Loading a TGA file
TGA files are similar to Windows bitmaps in that the pixel data in an
uncompressed file are presented in a simple block. The header for a TGA
is given here:
typedef struct stTGAHEADER
{
BYTE IdLength;
// Image ID Field Length
BYTE CmapType;
// Color Map Type
BYTE ImageType;
// Image Type
WORD CmapIndex;
// First Entry Index
WORD CmapLength;
// Color Map Length
BYTE CmapEntrySize;
// Color Map Entry Size
WORD X_Origin;
// X-origin of Image
WORD Y_Origin;
// Y-origin of Image
WORD ImageWidth;
// Image Width
WORD ImageHeight;
// Image Height
BYTE PixelDepth;
// Pixel Depth
BYTE ImagDesc;
// Image Descriptor
} TGAHEADER;
We are interested mainly in the 'ImageWidth', 'ImageHeight' and
'PixelDepth' members. In this sample we are only considering the case of
loading an uncompressed 24-bit file. In the sample code for Toon3D you
will find details for loading 8- and 32-bit compressed and uncompressed
TGA files if you need this facility.
Given an open file, we start by reading the file header. A TGA file can
have a comment about the file following the header. The TGAHEADER
member IdLength gives the length in bytes of this comment and in the
sample code we simply skip over it. Because we are only supporting
24-bit uncompressed files, we check for this by referring to the
'CmapType', which should be 0 to indicate no colour palette; 'PixelDepth'
should be 24 and the 'ImageType' should be TGA_RGB. The file could be
compressed in just the same way as a Windows bitmap is compressed,
i.e. by using run length encoding; if this was the case then the
Search Nedrilad ::




Custom Search