Complete program listing

A complete listing of the program is shown in Listing 5 below.

Listing 5. Source code for program named ImageDisplay01.
/*Project ImageDisplay01

The purpose of this project is to show how to load an
image file into memory and to display it in an onscreen
window.

Two image files are loaded into bitmaps in memory.
According to the docs for the load_bitmap function, BMP,
LBM, PCX, and TGA files are supported by default. I
understand from other web sources that an Allegro
extension can be installed to also support JPEG files,
but I have not installed that extension. In this program,
both image files are PCX files. I used a program named
Lview to convert the original JPEG files to PCX files.

An onscreen window is created that is of sufficient size
to contain both images.

The two images are copied into the onscreen window with
one image above the other.

Pressing any key causes the program to terminate.
*/
#include <allegro.h>

int main(){
  //Typical Allegro setup.
  allegro_init();
  install_keyboard();
  set_color_depth(32);
  //Create an onscreen window 332x651 pixels in size.
  set_gfx_mode(GFX_AUTODETECT_WINDOWED,332,651,0,0);

  //Declare a pointer variable capable of pointing to a
  // bitmap.
  BITMAP *picA = NULL;
  //Load an image file from the current directory.
  picA = load_bitmap("starfish.pcx", NULL);
  //Copy the image to the upper-left corner of the
  // onscreen window.
  blit(picA, screen, 0,0,0,0,324,330);
  
  //Load a second image and copy it to the onscreen
  // window immediately below the first image.
  BITMAP *picB = NULL;
  picB = load_bitmap("tree.pcx", NULL);
  blit(picB, screen, 0,0,0,330,294,321);
  
  //Block and wait until the user presses a key.
  readkey();
  
  //Destroy bitmaps to avoid memory leaks.
  destroy_bitmap(picA);
  destroy_bitmap(picB);

  return 0;//Return 0 to indicate a successful run.
}//end main function
END_OF_MAIN()