Results 1 to 7 of 7

Thread: How to do translucent graphics?

  1. #1

    How to do translucent graphics?

    I am using SDL to render my 2D game. I need to overlay a map when the user presses a key. I would like to show the map so that it is partly translucent. That was the user can still see what is going on under the map. Can this be done with SDL? If so, can someone give me some advice on what I need to set to do this.

  2. #2

    Re: How to do translucent graphics?

    Before you draw the map texture, set the alpha value of the glColor function (ie glcolor4ub(255,255,255,12). I'm not entirely sure what the equivalent is in SDL, though.

  3. #3

    Re: How to do translucent graphics?

    If you are using pure SDL, before you blit the surface use SDL_SetAlpha(MyValue), where MyValue is a byte value and 0 is completely translucent and 255 is completely visible. Use 128 as the value as often as you can, because it has been optimized for that case.
    Freeze Development | Elysion Game Framework | Twitter: @Stoney_FD
    Check out my new book: Irrlicht 1.7.1 Realtime 3D Engine Beginner's Guide (It's C++ flavored though)

    Programmer: A device for converting coffein into software.

  4. #4

    Re: How to do translucent graphics?

    Thanks for your help, that command works a treat

  5. #5
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Re: How to do translucent graphics?

    Hi and a late welcome to PGD!

    I'm curious about your project, just a few pieces of information and it sounds interesting already. Maybe you can post about it in the 'My Projects' forum?

    However getting back on topic, I'd like to note that while you *can* use SDL alone to do alpha fading, it will not be all that fast. If your map 'screen' will contain a single image or sprite then depending on the hardware it should be ok. However try to do several alpha blended sprites or images on the screen at a time and you'll quickly see that it slows down significantly. If your end goal is to make heavy usage of the alpha blend then you may be moving into OpenGL territory. Just a little caution on the alpha blending usage with SDL graphics.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  6. #6

    Re: How to do translucent graphics?

    Quote Originally Posted by WILL
    However try to do several alpha blended sprites or images on the screen at a time and you'll quickly see that it slows down significantly.
    I have to agree with you completely if you are using SDL_SWSURFACE or SDL_ANYFORMAT for your main window surface. In my experience slowdowns occur most of the time when SDL_DisplayFormat or SDL_DisplayFormatAlpha are not used.
    And of course, the slowdowns are not as stark as with DelphiX and alpha sprites.
    Freeze Development | Elysion Game Framework | Twitter: @Stoney_FD
    Check out my new book: Irrlicht 1.7.1 Realtime 3D Engine Beginner's Guide (It's C++ flavored though)

    Programmer: A device for converting coffein into software.

  7. #7

    Re: How to do translucent graphics?

    Quote Originally Posted by WILL
    Hi and a late welcome to PGD!

    I'm curious about your project, just a few pieces of information and it sounds interesting already. Maybe you can post about it in the 'My Projects' forum?
    Still lots to do but just added a short video on YouTube: http://www.youtube.com/watch?v=VMPG6McWAzw This is being written in Delphi 7 using JEDI SDL and BASS for the sound fx. I'll add mort detail in the projects section when I get some spare time

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •