Thread: Transparent bitmaps

  1. #1
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428

    Transparent bitmaps

    Alright thus far I have been using simple shapes as the character in my games but I want to do something more dynamic. I looked up sprite animation, but the only drawing program I have is microsoft paint and I cannot seem to find a way to make the background color transparent for my character animations. I want the character to not look like a giant square blocking out the background. Any shortcuts to this or do I need to buy a new drawing program? Thank you for your time.

  2. #2
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    Any shortcuts to this or do I need to buy a new drawing program?
    Most graphics libraries allow you to define a ColorKey which can be tested against if you are AlphaBlending.

    So for example if I have a sprite with a pink background and I set the ColorKey color to that color. Then all the pixels which are of that color will not be rendered.
    Last edited by Spidey; 07-14-2009 at 05:22 AM.

  3. #3
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    ok I am using Dev C++ what would be the proper syntax for setting ColorKey? Is it already predefined or do I have to define it first. Then I assume I must use the hexidecimal code for the color? Or R G B?

  4. #4
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    ok I am using Dev C++ what would be the proper syntax for setting ColorKey? Is it already predefined or do I have to define it first. Then I assume I must use the hexidecimal code for the color? Or R G B?
    Dev C++ is an IDE, not a graphics library. Those would be allegro,SDL, openGL, DirectX etc
    Each one has its own different way of handling color key's.

  5. #5
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    forgive my ignorance. I am currently learning SDL.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Direct3D does not have the idea of a color key. You use alpha blending to get transparency or alpha testing to get an all or nothing blend.
    In D3DX you can use D3DXCreateTextureFromFileEx() which allows you to specify a transparent color. Under the hood it is creating an alpha channel for you.

  7. #7
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    Do you know how to define the bitmap transparency color in SDL though? or have a link to a tutorial that does?

  8. #8
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    Take a look at SDL_SetColorKey. It should do it.

  9. #9
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Take a look at SDL_SetColorKey. It should do it.
    Yep, that would be what you want.

    Alpha transparency is neat when you want to draw semi transparent things. PNGs would probably be a better image type to use than bitmaps in general; might be worth checking out the SDL_Image lib too.

  10. #10
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285

  11. #11
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    Thank you guys continually for the help. I appreciate it. I finally got my first SDL game complete that continually generates new levels, or at least a mode of it. Whats in my mind now is way bigger than what I had set out to do lol, and I could't do it without this message board having alot of great minds. I appreciate it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Transparent, Editbox, HOLLOW_BRUSH, Marking text?
    By Dampy in forum Windows Programming
    Replies: 6
    Last Post: 09-22-2008, 07:17 PM
  2. Transparent panels overlapped
    By AtomRiot in forum C# Programming
    Replies: 3
    Last Post: 04-21-2007, 09:16 PM
  3. DX9 Not Displaying Bitmaps
    By Sentral in forum Game Programming
    Replies: 9
    Last Post: 01-31-2006, 05:35 AM
  4. MFC: Multiple clicks shows multiple bitmaps - how?
    By BrianK in forum Windows Programming
    Replies: 0
    Last Post: 06-20-2004, 07:25 PM
  5. Transparent bitmaps
    By Mithoric in forum Windows Programming
    Replies: 5
    Last Post: 03-11-2004, 03:14 PM