Load

bool Load(
const char *filename );

Loads the Bitmap from a bitmap file, which may contain an alpha channel. Returns true in success.


bool Load(
const char *rgbFilename, const char *alphaFilename );

Loads the Bitmap from two separate bitmaps, one bitmap for the color information and one 8-bit bitmap for the transparency information. Returns true in success.


bool Load(
BITMAP *allegroBmp, bool hasAlphaChannel = false,
bool convertMagicPink = false );

Loads the bitmap from an Allegro bitmap. If convertMagicPink is true the magic pink pixels in the bitmap will be converted to transparent pixels in the Bitmap.

OpenLayer doesn't free the passed BITMAP even if the Bitmap is destroyed.

bool Load(
BITMAP *allegroBmp, int conversionMode );

Same as above but the parameters are given by using a bitwise "or" of the following conversion parameters: HAS_ALPHA_CHANNEL and CONVERT_MAGIC_PINK.


The loaded bitmap may be in any format that is supported by Allegro (bmp, pcx, tga) or by any add-on libraries you've installed (Loadpng for pngs or JPGAlleg for JPEGs, for example).

Installing Loadpng is recommended as png files may contain an alpha channel to allow for transparent or translucent pixels. Png files also compress better than tga files. The latest OpenLayer's packages contain the loadpng, libpng and libz -libraries which are required to load png images.

It's best to check if the loading succeedes or not. The file may not be found or the format may not be supported. OpenLayer logs all loading failures in allegro.log, though, so you can also check the log file to find out if the loading has failed. But instead of letting your program crash it's better to display a message for the end user to let him know what went wrong. You'll get better feedback for your game that way ;)

Examples

// Remember to call Setup::SetupProgram and Setup::SetupScreen before loading any bitmaps! //

// Load myBmp from gfx/Bitmap.png //
Bitmap myBmp;
myBmp.Load"gfx/Bitmap.png" );

// It's best to check if the loading succeedes! (Bitmap really exists) //
Bitmap myBmp;
if( myBmp.Load"gfx/Bitmap.png" ) == false ) {
   // Display an error message //
   allegro_message( "Bitmap couldn't be loaded!" );
   // Exit the program //
   exit(-1);
}

// If you have BitmapColor.bmp that has the color information //
// and an 8-bit BitmapAlpha.bmp that contains the translucency: //
Bitmap myBmp;
myBmp.Load"gfx/BitmapColor.bmp""gfx/BitmapAlpha.bmp" );


Other functions of the class Bitmap
Load
Loads the bitmap
Blit
Draws the Bitmap to the screen
BlitRotated
Draws the Bitmap to the screen rotated along a point
BlitStretched
Draws the Bitmap to the screen stretched to the specified size
BlitTransformed
Draws the Bitmap to the screen rotated and stretched
BlitDistorted
Draws the Bitmap to the screen with the given corner points
Width
Returns the width of the Bitmap
Height
Returns the height of the Bitmap
LoadListOfBitmaps
Loads a list of bitmaps from the disk
GetPixel
Returns the color value of a pixel
Destroy
Destroys the Bitmap
IsValid
Checks if the Bitmap was loaded correctly
Save
Saves the Bitmap to disk with the specified filename
CopyFromScreen
Copies a region of the game window to the Bitmap
GetMemoryBitmap
Returns a memory bitmap copy of (part of) the Bitmap
GetCollisionPoly
Returns the generated collision polygon for the Bitmap
SetDefaultPivot
Sets the default pivot point
GetDefaultPivot
Returns the default pivot point

Advanced functions

GetPixelPacked
Returns the color value of the specified pixel in a packed integer
SendToGPU
Sends the Bitmap to the graphics card
UnloadFromGPU
Unloads the Bitmap from the graphics card
Select
Selects the Bitmap as the active texture of OpenGL
UseAutoDelete
Chooses the Bitmap to be automatically deleted when the program quits
HasAlphaChannel
Checks if the Bitmap has an alpha channel
StartFastBlitting
This function should be called right before using FastBlit
FastBlit
A faster version of Blit
FinishFastBlitting
This function should be called after calling FastBlit
UnloadToMemory
Unloads the Bitmap from the graphics card keeping the image data saved in the Bitmap
TexturedQuad
Outputs a raw textured quad to the video card


Questions about Load? Click here.