Alpha blending

This is a discussion on Alpha blending within the Game Programming forums, part of the General Programming Boards category; Hello, I'm trying to write a cheap 'n' cheerful 24-bit alpha blending algorithm. I've so far got:- Code: (iAlpha is ...

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,262

    Alpha blending

    Hello,

    I'm trying to write a cheap 'n' cheerful 24-bit alpha blending algorithm. I've so far got:-
    Code:
    (iAlpha is alpha level, 0 to 255)
    (lpSrc is an unsigned char pointer to source data)
    (Guess what lpDest is)
    int i;
    unsigned long ulColour;
    
    ("For each pixel:")
    for (i=0;i<3;i++)
    {
    	ulColour = iAlpha * ((*(lpSrc++) - *lpDest) >> 8) + *lpDest;
    	*(lpDest++) = (unsigned char)ulColour;
    }
    This doesn't seem to give 100% of the desired effect unfortunately, as bright colours appear with increasing alpha. It's also worth noting that I'm testing this by using empty (Black) source data against a destination image (To fade the image). Might black blending be a special case?

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,262
    Never mind, I've sorted it out. Where alpha results were more than 255 or less than 0 nothing was being done to rectify the result within bounds. it works now (Albeit quite slow, I think I'll need to assemblerise it at some stage).

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Post your code. I'm sure you don't need to convert it to ASM... although perhaps storing the information in another file after you've computed it and then using that in the future would be a good idea.
    Away.

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    If you want it to be fast, forget assembler and use Direct3D.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Direct3D10 Sprites Alpha Blending
    By DarkMasterBosel in forum Game Programming
    Replies: 0
    Last Post: 01-17-2009, 06:17 AM
  2. Replies: 23
    Last Post: 07-09-2007, 04:49 AM
  3. 2 questions in DirectX
    By X PaYnE X in forum Game Programming
    Replies: 4
    Last Post: 12-02-2004, 08:38 AM
  4. Alpha blending w/o color loss
    By VirtualAce in forum Game Programming
    Replies: 37
    Last Post: 10-27-2004, 12:58 AM
  5. Alpha blending rocks
    By VirtualAce in forum Game Programming
    Replies: 12
    Last Post: 04-06-2004, 08:08 PM

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