Spriting, Invisible Background?

This is a discussion on Spriting, Invisible Background? within the Game Programming forums, part of the General Programming Boards category; How would I go about cutting out the background of bitmaps so that you only see the sprite? and not ...

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question Spriting, Invisible Background?

    How would I go about cutting out the background of bitmaps so that you only see the sprite? and not the entire colored background.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    You need to decide on a transparent color. This color will be in the sprite image but your code or the blitting code will not write these pixels to the screen or buffer. You need to use a color that you would not likely use in any image such as very very bright colors (255,255,0) or something like that.

    If you are using DirectX there are functions that will do this for you in any color depth provided that you tell it what the transparent color is. It is a little more difficult with DX8 and DX9 because DirectX has been merged with D3D and blits can become complicated. For a more detailed explanation of this check www.gamasutra.com or www.gamedev.net - I think www.gamedev.net has a tutorial for creating 2D games with DX8.

    If you are in DOS you really need to use assembly to get the function to be quick enough. Simply scan the image to be into the buffer, check for the transparent color, is it is the transparent color, advance in the frame buffer (screen or back buffer) without plotting pixels and advance in the image buffer or sprite. Do this for the entire image to be blitted and you are done. Very simple really.

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    The PNG format has support for transparency without having to choose a transparent color (color keying).

    Load the images with the D3DXCreateTextureFromFileEx() function.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #4
    droidhere
    Guest

    Talking rply:

    OpenGL, I am using.

  5. #5
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

  6. #6
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    hey drdroid, IM me, i've got some code to load transparent BMPs that works VERY nicely I use it all the time

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to load background pic/texture in OpenGl?
    By salman86 in forum Windows Programming
    Replies: 3
    Last Post: 08-07-2005, 06:37 PM
  2. Load Bitmap as Window Background
    By Epo in forum Windows Programming
    Replies: 6
    Last Post: 07-19-2005, 09:37 AM
  3. Windows background color
    By Exile in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2005, 06:55 AM
  4. Detect Close of a background process
    By Schwarzhelm in forum C Programming
    Replies: 1
    Last Post: 11-05-2003, 12:46 AM
  5. background process switches to stopped
    By bonkey in forum Linux Programming
    Replies: 3
    Last Post: 11-20-2002, 07:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21