Thread: bitmap blues

  1. #1
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210

    bitmap blues

    I was wondering if anyone had any experience with bitmap and vector graphix for use in 2D sidescrollers... good ones like mario and stuff.

    I'm experimenting with blitting and I've got some bitmap images finished for the animation of my character running. I was really dissappointed when I blitted my images though.

    It seems some of the shading I did around the characters edges produces an udesired hard line around him. This happens because the color I used to fill the background for my transperency merges with the shaded edges and produces several colors which are just out of range of the transperency.

    Someone suggested I use the color of my characters costume for the background, but this work because it's several colors. I could use black, but I really don't want heavy black lines. I could also hardline the edges, but then they would look horribly blocky and unprofessional.

    I want to do some really nice 2D graphix that have a 3D look to them, commercial looking 2D I guess. I'm looking for techniques.

    Using Gimp.

    Edit: forgot to mention I'm blitting with SDL

    Thanks.
    Last edited by Invincible; 05-12-2002 at 06:03 AM.
    "The mind, like a parachute, only functions when open."

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    This code will correctly blit images to the screen regardless of their location. If the bitmap lies outside of the boundaries of the screen then no blit is performed. Sorry for the labels being outside of asm blocks, but my compiler would not let me use them inside of them. I could re-write this in my Borland compiler for Windows, but haven't yet (it allows labels inside of asm blocks).

    To blit the image taking into account transparent pixels, use PutImageEx.

    I use 255 as the transparent color in all my 256 color graphics.

    Code:
    void PutImageEx(int x,int y,BYTE far *Buffer,WORD width,WORD height,BYTE tcolor)
    {
       WORD BitmapStartOffsetX=0;
       WORD BitmapStartOffsetY=0;
       WORD ScreenOffset=0;
       WORD BitmapOffset=0;
       int ScreenWidth=width;
       int ScreenHeight=height;
      
       if (x<0)
      {
         BitmapStartOffsetX=0-x;
         ScreenWidth+=x;
         if (ScreenWidth<0) ScreenWidth=0;
         width=ScreenWidth;
         x=0;
      }
    
      if (y<0)
     {
        BitmapStartOffsetY=0-y;
        ScreenHeight+=y;
        if (ScreenHeight<0) ScreenHeight=0;
        y=0;
     }
    
      ScreenOffset=ScreenAddr[y]+x;
       BitmapOffset=BitmapStartOffsetY*(width)+BitmapStar
    tOffsetX;
      if ((x+width)>320) ScreenWidth=(320-x);
      if ((y+height)>200) ScreenHeight=201-y;
    
    
      ScreenHeight--;
    
      if (ScreenWidth && ScreenHeight)
      {
      asm {
         push ds
         cld
         les di,[ScreenPtr]
         mov di,[ScreenOffset]
    
         lds si,[Buffer]
         mov si,[BitmapOffset]
         add si,4
    
         xor cx,cx
         xor dx,dx
        }
    
        DRAWBITMAP:
        asm {
            inc dx
            mov cx,[ScreenWidth]
        }
    
        DRAWLINE:
        asm {
          mov al,[ds:si]
          cmp al,tcolor
          jz  NOBLIT
          movsb
          LOOP DRAWLINE
          jmp NEXTLINE
        }
    
        NOBLIT:
        asm {
          inc si
          inc di
          LOOP DRAWLINE
        }
    
        NEXTLINE:
        asm {
          mov bx,[BitmapOffset]
          add bx,[width] 
          add bx,[BitmapStartOffsetX]
          mov [BitmapOffset],bx 
          mov si,bx 
          add si,4 
          mov bx,[ScreenOffset] 
          add bx,320		
          mov [ScreenOffset],bx
          mov di,bx			
          cmp dx,[ScreenHeight]	
          je DONE			
          jmp DRAWBITMAP		
         }
         DONE:
         asm { pop ds }
       }
    }
    
    void PutImage(int x,int y,BYTE far *Buffer,WORD width,WORD height)
    {
      WORD BitmapStartOffsetX=0;
      WORD BitmapStartOffsetY=0;
      WORD ScreenOffset=0;
      WORD BitmapOffset=0;
      int ScreenWidth=width;
      int ScreenHeight=height;
    
      if (x<0)
      {
        BitmapStartOffsetX=0-x;
        ScreenWidth+=x;
        if (ScreenWidth<0) ScreenWidth=0;
        width=ScreenWidth;
        x=0;
      }
    
      if (y<0)
      {
        BitmapStartOffsetY=0-y;
        ScreenHeight+=y;
        if (ScreenHeight<0) ScreenHeight=0;
        y=0;
      }
    
      ScreenOffset=ScreenAddr[y]+x;
       BitmapOffset=BitmapStartOffsetY*(width)+BitmapStar
    tOffsetX;
      if ((x+width)>320) ScreenWidth=(320-x);
      if ((y+height)>200) ScreenHeight=201-y;
    
      ScreenHeight--;
    
      if (ScreenWidth && ScreenHeight)
      {
       asm {
          push ds
          cld
          les di,[ScreenPtr]
          mov di,[ScreenOffset]
          lds si,[Buffer]
          mov si,[BitmapOffset]
          add si,4
          xor cx,cx
          xor dx,dx
        }
        
        DRAWBITMAP:
        asm {
          inc dx
          mov cx,[ScreenWidth]
          rep movsb
          mov bx,[BitmapOffset]
          add bx,[width]
          add bx,[BitmapStartOffsetX]
          mov [BitmapOffset],bx
          mov si,bx
          add si,4
          mov bx,[ScreenOffset]
          add bx,320
          mov [ScreenOffset],bx
          mov di,bx
          cmp dx,[ScreenHeight]
          je DONE
          jmp DRAWBITMAP
         }
         DONE:
         asm { pop ds }
      }
    }
    Now I'm working on rotating the bitmaps. I'm going to rotate the bounding box of the bitmap, scan convert it, and then fill the bounding box from top to bottom like a polygon filler. This will allow me to rotate my bitmaps to any angle on x,y,z and will also produce complete bitmaps with no holes in them. It's essentially a linear texture map onto a 2D surface, the 2D surface being the bounding box of the bitmap (the dimensions of the bitmap).
    Rotation is performed via my matrix class and is very fast.
    I have a class that will load BMPs for you as well. If you wish to use other bitmap file types like GIF, JPEG, etc., you must derive from class Bitmap and then implement your algorithm for decoding the file in the Load() function. Note that you can call other functions from the Load() function as well.

    The class will automatically extract the RGB values, discarding the third value, and placing them in the correct order. Then it will automatically set the palette for the bitmap as well.

    If you are interested in any of this, PM me and I'll give you the libs.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loading a bitmap (Without using glaux)
    By Shamino in forum Game Programming
    Replies: 7
    Last Post: 03-16-2006, 09:43 AM
  2. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  3. Loading a Bitmap resource for OpenGL Texture[x]
    By the dead tree in forum Game Programming
    Replies: 4
    Last Post: 08-26-2004, 01:12 PM
  4. bitmap not going onto screen
    By stallion in forum Windows Programming
    Replies: 4
    Last Post: 02-22-2003, 10:07 AM
  5. texture is all white in opengl!
    By Crossbow in forum Game Programming
    Replies: 7
    Last Post: 03-31-2002, 11:54 AM