Thread: Translucent gfx (i.e. for explosion)

  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    Translucent gfx (i.e. for explosion)

    Hi guys! I'm working on some stuff right now (my cheesy "space-shooterz" game to be specific) with DirectDraw, and I've come to a point where I want to add cool explosions. In my head, I'm picturing the screen brightening (as in everything turns just a shade closer to white) for a sec, and a translucent explosion blossoming out and engulfing the sad-looking hand-drawn aliens that look like strange turnips. Ok, so it's not so practical But that's the idea.

    So my question is, how could I achieve this translucent effect? Would I:
    A) just draw a bitmap that has alternating transparent/non-transparent pixels (don't think so, but who knows...)?
    B) Use alpha-blending or something?
    C) Other

    If (B), how could I go about doing so? (from DirectX docs: The IDirectDrawSurface7::Blt method performs a bit block transfer (blit). This method does not support z-buffering or alpha blending (see alpha channel) during blit operations.)

    P.S. Or, if it's your real opinion, should I just give up and go home?
    Last edited by Hunter2; 02-04-2003 at 10:43 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Give up? Hardly.

    Gamma:
    You mentioned something about everything brightening one shade. This can be done easily. Simply lock the back buffer and walk through the pixels incrementing the RGB components by 1. Make sure to check for overflow though! This is basically a gamma effect. This may not be what you want though. One shade brighter will barely be noticeable IMO.

    Alpha Blending:
    Alpha blending isn't that bad either! Even if you don't use 32bpp bitmaps you can fake an alpha channel by a constant value. If you want I can write you out a brief overview on alpha blending and some pseudo code you can use. Let me know.

    Not sure exactly if that is what you were looking for or not. If not, let me know and I'll re-gather my messy thoughts and try again.

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    MrWizard to the rescue again! I'm thinking that gamma should work fine (as long as it doesn't slow things down, which it doesn't sound like it should), although I guess I'd be brightening it several shades instead of just one

    But about the alpha-blending, how would I go about creating a 32-bit bitmap? Paint didn't seem to be capable of using 32 bits the last time I checked And also, what about the ominous warning in the docs about alpha-blending not being supported by Blt()?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    windows bitmaps are only able to go up to 24BPP. But that is not what he was talking about. You can use any bit depth for your images. You make the screen itself 32bit. Then you can apply alpha junk to it.

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Hmm, so the alpha stuff isn't built into the bitmap file? You mean it has to be manually entered pixel by pixel in the code or something?

    **EDIT**
    I tried doing gamma and made a huge mess of it... then I searched for gamma stuff on Google, and I ended up at the archived DirectX 7 docs, with gammaramps, gammacontrol, and other gammabohemianarchbishopcoinheadgongs. If I'm trying to do gamma stuff, am I supposed to be using gammaramps, or am I supposed to be doing the manual pixel-setting that MrWizard suggested?
    Last edited by Hunter2; 02-05-2003 at 06:43 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #6
    no, don't think of it that way. You are thinking on a sprite level, you need to break from that. Think about the screen.

    But the common way of this is you have a 24 bit bitmap. You use alpha to blit the 24 bit bitmap to the screen. It makes all the pixels of the bitmap to be blitted with the specified alpha value.

  7. #7
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Hmm, what I was referring to was this:
    Even if you don't use 32bpp bitmaps
    It sounds like you're talking about this:
    fake an alpha channel by a constant value
    Am I right? But my question is, how would I create/generate/acquire/whatever such a "32bpp bitmap" that doesn't use a "fake" alpha channel?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Hunter2
    Hmm, what I was referring to was this:
    It sounds like you're talking about this:

    Am I right? But my question is, how would I create/generate/acquire/whatever such a "32bpp bitmap" that doesn't use a "fake" alpha channel?
    Ah, this thread has expanded since I last was here!

    Alpha:
    You can have 32bpp bitmaps. I don't see the problem. If you aren't using 32bpp bitmaps ( i.e. 24-bit / 16-bit ) then you'll need to fake it. I'm just going to write up a paper on it and attach it to this post when I get home in a few hours. Hopefully it'll explain everything clearly.

    Gamma:
    You can use the GammaRamp functions ( using hardware ) or emulate it in software. If you are having trouble with this I can post you a snippet of code later tonight.

    Well I have some work to do but when I leave I will post some things on alpha-blending in software and gamma stuff.


    I just read where you said something about being warry with DirectX not supporting alpha-blends. This is why you do it yourself in software!
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  9. #9
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Heh, well, as for the gamma I've already sort of added GammaRamp functionality to my GFX class, with two different intensity-level calculating algorithms But any help on the software-emulation version would be greatly appreciated, as well as the essay on alpha
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Well the Gamma in software is actually pretty easy. Its very easy but if you need to see the code I can e-mail / post some source. Basically all you need to do is use the Lock method to get a pointer to the actual surface bits. Then just go through the pixels incrementing each component ( B G R ordering ) by a certain amount. Not much to it.

    I have attached a very simple alpha blending document. I wrote it up real quick and may have made some mistakes, who knows. If it helps then great. I should have took more time but I know you wanted to read something on it.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  11. #11
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    DirectDraw is an obsolete interface.

    Use DirectGraphics/Direct3D and you can use alternative A) with hardware support = very fast

    Here's a good article:

    http://www.gamasutra.com/features/20010629/geczy_01.htm
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  12. #12
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    DirectGraphics??? Strange, I've never heard of it... and I thought that Direct3D was only for 3D... But what is alternative A)? If it's gamma, I dunno what you mean because I thought gammaramps were hardware.

    *Also, I can't go to the link because I'm not a member...

    P.S. Thanks for the help on alpha MrWizard. But about the manual-pixel-setting gamma, I tried that but found it a bit hard to figure out while trying to maintain support for all of 8-bit, 16-bit, and 32-bit resolutions
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  13. #13
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    DirectDraw is no longer being updated by Microsoft. Instead all graphics, 3D and 2D should use the same set of interfaces, DirectX Graphics. It's actually Direct3D.
    I recommend reading that article, it taught me alot. I didn't know membership was required, but it's free anyway.

    IMO, Direct3D is superior to DirectDraw for 2D. It's much faster and easier to set up. It has built-in support for sprites etc. It is also possible to use nice hardware-features like alpha-blending and rotation, scaling and "color blending" (don't know what it's called).

    Forget all about manual alpha blending and let DirectX do it for you.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  14. #14
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Hunter2
    P.S. Thanks for the help on alpha MrWizard. But about the manual-pixel-setting gamma, I tried that but found it a bit hard to figure out while trying to maintain support for all of 8-bit, 16-bit, and 32-bit resolutions
    Try getting it working with one format then try to add support for the others. This is usually done be keeping track of the user's bits per pixel. Then you need to get the channels ( BPP / 8 ). So lets so I'm running in 24-bpp and you wanted to support that. Whenever you are going to manipulate the bits you need something like this.

    NOTE: Assume lpR, lpG, lpB to be pointers to the RGB components of the surface. Assume lPitch to already been initialized to the pitch of the surface.

    Code:
    unsigned char channels = BPP / 8;
    lpB = (lpPixelBits + (y * lPitch) + (x * channels));
    lpG = (lpPixelBits + (y * lPitch) + (x * channels) + 1);
    lpR = (lpPixelBits + (y * lPitch) + (x * channels) + 2);
    
    // MAKE SURE YOU CLAMP THESE VALUES! ( 0 - 255 )
    *lpB += 25; // Brighten by 25
    *lpG += 25;
    *lpR += 25;
    Good luck and if you get stuck I'll take a look at the code.

    Sang-drax:

    While I do agree with you that Direct3D is taking over for not only 3D graphics ( obviously ) but also the 2D graphics seeing as DirectDraw is no longer supported. Learning DirectDraw before I learned Direct3D made the transition easier for me though. Don't you also think its important to understand how things work in software before using hardware support ( i.e. Alpha-Blending )? I think that is very important.

  15. #15
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    No, I don't think that is extremly important.

    If you don't use alpha-blending "automatically" with Direct3D without knowing the underlying technique, then why do you use DirectDraw without extrensible knowlege of graphic driver programming or video memory allocation for different hardware brands?
    DirectDraw is not low-level. I'm sure you are using Blt() without knowing exacly how the hardware handles the memory.

    The whole point in using API's (and the whole OOP concept) is that you don't have to care about what's going on beneath the surface; you only have to care about the interface.

    Although knowlege is never wrong (I myself has programmed DirectDraw once) it is not imperative
    Last edited by Sang-drax; 02-09-2003 at 05:47 PM.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making my own gfx engine
    By jverkoey in forum Game Programming
    Replies: 4
    Last Post: 06-07-2003, 02:06 PM