Advertisement

classes->conversion 2nd problem

Started by May 06, 2002 09:31 PM
1 comment, last by edwinnie 22 years, 4 months ago
okie, i am still trying to convert Mr LaMothe''s code to classes. i managed to get something like this: this is the header file currently:
  
class BITMAP_FILE
{
public:

      //member functions

      int Load_Bitmap_File(char *filename);
      int Flip_Bitmap(UCHAR *image, int bytes_per_line, int height);
      int Unload_Bitmap_File();
      int Copy_Screen(UCHAR *source_bitmap, UCHAR *dest_buffer, int lpitch, int transparent);

private:

      BITMAPFILEHEADER bitmapfileheader;  // this contains the bitmapfile header

      BITMAPINFOHEADER bitmapinfoheader;  // this is all the info including the palette

      PALETTEENTRY     palette[256];      // we will store the palette here

      UCHAR            *buffer;           // this is a pointer to the data

      char             *filename;         //L_B_F

      UCHAR            *image;            //F_B

      int              bytes_per_line; 
      int              height;
      UCHAR            *source_bitmap;    //C_S

      UCHAR            *dest_buffer;
	  int              lpitch;
	  int              transparent;
};
  
previously, i used to call this global function: Copy_Screen(bitmap24bit.buffer, primary_buffer, primary_lpitch, 0); where bitmap24bit is part of his BITMAP_FILE_TAG structure.
  
int BITMAP_FILE::Copy_Screen(UCHAR *source_bitmap, UCHAR *dest_buffer, int lpitch, int transparent)
{
// this function draws the bitmap onto the destination memory surface

// if transparent is 1 then color 0 (8bit) or 0.0.0 (16bit) will be transparent

// note this function does NOT clip, so be carefull!!!



   USHORT *dest_addr,   // starting address of bitmap in destination

          *source_addr; // starting adddress of bitmap data in source


   USHORT pixel;        // used to hold pixel value


   int index,           // looping vars

       pixel_x,
       lpitch_2 = lpitch >> 1; // lpitch in USHORT terms


   // compute starting destination address

   dest_addr = ((USHORT *)dest_buffer);

   // compute the starting source address

   source_addr = (USHORT *)*source_bitmap;

   // is this bitmap transparent

   if (transparent)
   {
   // copy each line of bitmap into destination with transparency

   for (index=0; index<SCREEN_HEIGHT; index++)
       {
       // copy the memory

       for (pixel_x=0; pixel_x<SCREEN_WIDTH; pixel_x++)
           {
           if ((pixel = source_addr[pixel_x])!=0)
               dest_addr[pixel_x] = pixel;

           } // end if


       // advance all the pointers

       dest_addr   += lpitch_2;
       source_addr += SCREEN_WIDTH;

       } // end for index

   } // end if

   else
      {
      // non-transparent version

      // copy each line of bitmap into destination


      int source_bytes_per_line = SCREEN_WIDTH*2;

      for (index=0; index < SCREEN_HEIGHT; index++)
          {
          // copy the memory

          memcpy(dest_addr, source_addr, source_bytes_per_line);

          // advance all the pointers

          dest_addr   += lpitch_2;
          source_addr += SCREEN_WIDTH;

          } // end for index


      } // end else


   // return success

   return(1);

} // end Copy_Screen

  
now that the structure exists as a class, how do i modify this member function considering, 1) *source_bitmap is still required? or not? 2) there is part in the function for source address which i dunno how to modify.
normally for blits, the member function always uses itself as the source and requires only the dest object, dest rect, and dest position (ie the xy in the source you are blitting to). take a look at the directdraw surface interface. you will see a good way to handle this in an oop manner.

looking over your class, i see many things wrong. it seems you took everything and put it all in the class, even if its not needed and dont make sense.

instead of doing the conversion, why not look over some c++ tutorials and learn a bit about oop and creating classes. i know you want to create games, but unless you take the time to learn the basics you wont get very far.
Advertisement
which i did b4

This topic is closed to new replies.

Advertisement