Tricks of the Windows Game Programming Gurus:Vector Rasterization and 2D Transformations

All ITKnowledge Source Code Search Tips Advanced Search |

| Tricks of the Windows Game Programming Gurus by Andre LaMothe Sams, Macmillan Computer Publishing ISBN: 0672313618 Pub Date: 09/27/99

Search this book:

Previous | Table of Contents | Next

Purpose:

`Destroy_Bitmap()` is used to release the memory allocated during the creation of a `BITMAP_IMAGE` object. You should call this function on your object when you’re all done working with it—usually during the shutdown of the game, or if the object has been destroyed in a bloody battle. Returns `TRUE` if successful.

Example:

    // destroy the previously created BITMAP_IMAGE

    Destroy_Bitmap(&ship);

Function Prototype:

    int Load_Image_Bitmap(

     BITMAP_IMAGE_PTR image, // bitmap to store image in

     BITMAP_FILE_PTR bitmap, // bitmap file object to load from

     int cx,int cy, // coordinates where to scan (cell or abs)

     int mode); // image scan mode: cell based or absolute

    #define BITMAP_EXTRACT_MODE_CELL  0

    #define BITMAP_EXTRACT_MODE_ABS   1

Purpose:

`Load_Image_Bitmap()` is used to scan an image from a previously loaded `BITMAP_FILE` object into the sent `BITMAP_IMAGE` storage area. This is how you get objects and image bits into a `BITMAP_IMAGE`. Now, to use the function, you first must load a `BITMAP_FILE` and create the `BITMAP_IMAGE`. Then you make the call to scan an image of the same size out of the bitmap data stored in the `BITMAP_FILE`. There are two ways the function works, cell mode or absolute mode:

  • In cell mode, `BITMAP_EXTRACT_MODE_CELL`, the image is scanned making the assumption that all the images are in the `.BMP` file in a template that is some given size, m×n, with a 1-pixel border between each cell. The cells usually range from 8×8, 16×16, 32×32, 64×64, and so on. Take a look at `TEMPLATE*.BMP` on the CD; it contains a number of templates. Cell numbers range from left to right, top to bottom, and they start with (0,0).
  • The second mode of operation is absolute coordinate mode, `BITMAP_EXTRACT_MODE_ABS`. In this mode, the image is scanned at the exact coordinates sent in cx, cy. This method is good if you want to load your artwork with various-sized images on the same `.BMP`; hence, you can’t template them.

Example:

    // assume the source bitmap .BMP file is 640x480 and

    // has a 8x8 matrix of cells that are each 32x32

    // then to load the 3rd cell to the right on the 2nd

    // row (cell 2,1), you would do this

    // load in the .BMP file into memory

    BITMAP_FILE bitmap_file;

    Load_Bitmap_File(&bitmap_file,"images.bmp");

    // initialize the bitmap

    BITMAP_IMAGE ship;

    Create_Bitmap(&ship, 0,0, 32,32);

    // now scan out the data

    Load_Image_Bitmap(&ship, &bitmap_file, 2,1,

                      BITMAP_EXTRACT_MODE_CELL);

To load the exact same image, assuming it’s still in the template, but using the absolute mode, you have to figure out the coordinates. Remember that there’s a 1-pixel partitioning wall on each side of the image.

    Load_Image_Bitmap(&ship, &bitmap_file,

                      2*(32+1)+1,1*(32+1)+1,

                      BITMAP_EXTRACT_MODE_ABS);

Function Prototype:

    int Draw_Bitmap(BITMAP_IMAGE_PTR source_bitmap, // bitmap to draw

                    UCHAR *dest_buffer, // video buffer

                    int lpitch,  // memory pitch

                    int transparent); // transparency?

Purpose:

`Draw_Bitmap()` draws the sent bitmap on the destination memory surface with or without transparency. If `transparent` is 1, `transparency` is enabled and any pixel with a color index of 0 will not be copied. Function returns `TRUE` if successful.

Example:

    // draw our little ship on the back buffer

    Draw_Bitmap( &ship, back_buffer, back_lpitch, 1);

    Function Prototype:

    int Flip_Bitmap(UCHAR *image, // image bits to vertically flip

                    int bytes_per_line, // bytes per line

                    int height); // total rows or height

Purpose:

`Flip_Bitmap()` is usually called internally to flip upside-down `.BMP` files during loading to make them right-side up, but you might want to use it to flip an image yourself. The function does an in-memory flip and actually inverts the bitmap line by line, so your original sent data will be inverted. Watch out! Returns `TRUE` if successful.

Example:

    // for fun flip the image bits of our little ship

    Flip_Bitmap(ship->buffer, ship->width, ship_height);

Previous | Table of Contents | Next

Copyright © Macmillan Computer Publishing, Inc.

Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.