Game Programming Effects

This is a discussion on Game Programming Effects within the Game Programming forums, part of the General Programming Boards category; Hi, I was wondering..is there a way to create cool "pulse" effects without shaders? Allegro doesn't seem to support and ...

  1. #1
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629

    Game Programming Effects

    Hi,
    I was wondering..is there a way to create cool "pulse" effects without shaders? Allegro doesn't seem to support and OpenGl is too advanced for me, looks very hard to understand.

    I have made a 2d game that looks absolutely boring and I would like to add some effects to it.
    I tried the neon pharmacy effect thingy as a start, you know from green to red using line draws, but it doesn't work at all. The color remains the same, and the delay loop I used to control change doesn't make a difference...

    so any way I can add some effects, beginner effects and start from there? Thanks

    YouTube - Indie space shooter game lightfighter

    would that be asking too much from Allegro?

    Play 1 Starship Online at 2DPlay for Free

    or some effect like this would be cool, when the ship explodes.

    Any pointers? Thanks
    You ended that sentence with a preposition...Bastard!

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Please post a specific problem here and we can help you. Otherwise I'm going to move this thread to the Tech board.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,622
    For 2D games, all you need is a sequence of images played one after another. For 3D... well, that's another story!
    Devoted my life to programming...

  4. #4
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Hi, sorry didn't realize that there were any replies.

    I have a 2d game which I would like to add some effects to, blinking lights, pulse effects, whatever. But I have no idea how to implement it.

    @Sipher I don't have images, is it not possible to use the inbuilt vector graphics?

    Thanks
    You ended that sentence with a preposition...Bastard!

  5. #5
    Registered User
    Join Date
    Jan 2011
    Posts
    31
    This is only an idea but you can try to make a lightmap composed of alpha and white values with the size of your screen resolution and interpolate between the pixels on the screen to your lightmap.

    Know someone who faked fog of war with such a method. He used a black image with a filled white circle in the middle.

  6. #6
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    I think Sipher has the right idea, but if you don't want to use images maybe you should look at a really simple particle engine or just particle effects. You could probably find a simple one somewhere or even write your own. I've never written a particle engine, but I bet it'd be fun.

  7. #7
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Hey, thanks for replying.
    @JohnL
    The thing is I don't think allegro supports alpha blending or concepts like that. Even if it does, I wouldn;t know what to do.

    @IdioticCreation
    in fact I have a particle effect down, but the thing is..it is the most boring effect ever!
    The colors are "plain", as in I it chooses a random colorR,colorG,colorB but it doesn't "glint" or "sparkle" or "twinkle" lol I think you get the point.

    I would like to do stuff like that, but I don't know how to use OpenGl..
    but if I was to use images, how would I do it? I have a series of images and just iterate through them?
    You ended that sentence with a preposition...Bastard!

  8. #8
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,622
    OpenGL doesn't <"glint" or "sparkle" or "twinkle">. It's up to your algorithm to provide such effects, and if you don't like your particle system maybe you should change it.
    Devoted my life to programming...

  9. #9
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    The thing is I don't think allegro supports alpha blending or concepts like that. Even if it does, I wouldn;t know what to do.
    al_set_blender

    A neat neon sort of effect could be achieved with additive blending:
    Additive blending would be achieved with
    al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE)
    You'd have to give your particles some transparency of course. When particles intersect here, their colors 'add' together as like what's shown in this picture.
    Consider this post signed

  10. #10
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    @ Bernt, Oh my God! Yeah!! That is what I want to the effect I want to accomplish?
    Did you do that using allegro?
    how can i use transparency?
    I will go and look up the function now!

    @Sipher
    yeah ok, but..I wouldn't know where to start. I am not the most artistic person (I am not all, in fact) .
    You ended that sentence with a preposition...Bastard!

  11. #11
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    how can i use transparency?
    There are a few ways in Allegro, depending on what you're using as particles.

    If you're using sprite particles, I'd say just define transparency in the picture file itself. Use .png or the like, and an image editor that supports transparency. GIMP comes to mind, but I think paint.NET also supports transparency as well as being more lightweight. This allows for some complex transparency effects with minimal extra code.

    You can also use al_draw_tinted_bitmap for whole-image transparency.

    There's also the option of drawing particles yourself either with OpenGL or with allegro's primitives functions, in which case transparency is defined in the color you choose to draw with.
    Consider this post signed

  12. #12
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Unfortunately I can't make sprites, so I will have to stick with the functions.

    and by paint.NET do you mean the inbuilt paint.NET ?
    It is hard to believe, that software is the most annoying ever.

    I will go ahead and give it a go, and reply with some code if it doesn't work.

    Thanks.
    You ended that sentence with a preposition...Bastard!

  13. #13
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    em, not to sound stupid but can you explain what the al_set_blender does?
    I don't understand the variables
    Code:
    void al_set_blender(int op, int src, int dst)
    Sets the function to use for blending for the current thread.
    
    Blending means, the source and destination colors are combined in drawing operations.
    
    Assume the source color (e.g. color of a rectangle to draw, or pixel of a bitmap to draw) is given as its red/green/blue/alpha components (if the bitmap has no alpha it always is assumed to be fully opaque, so 255 for 8-bit or 1.0 for floating point): sr, sg, sb, sa. And this color is drawn to a destination, which already has a color: dr, dg, db, da.
    
    The conceptional formula used by Allegro to draw any pixel then depends on the op parameter:
    
    ALLEGRO_ADD
    
     r = dr * dst + sr * src
     g = dg * dst + sg * src
     b = db * dst + sb * src
     a = da * dst + sa * src
    ALLEGRO_DEST_MINUS_SRC
    
     r = dr * dst - sr * src
     g = dg * dst - sg * src
     b = db * dst - sb * src
     a = da * dst - sa * src
    ALLEGRO_SRC_MINUS_DEST
    
     r = sr * src - dr * dst
     g = sg * src - dg * dst
     b = sb * src - db * dst
     a = sa * src - da * dst
    Valid values for src and dst passed to this function are
    
    ALLEGRO_ZERO
    
     src = 0
     dst = 0
    ALLEGRO_ONE
    
     src = 1
     dst = 1
    ALLEGRO_ALPHA
    
     src = sa
     dst = sa
    ALLEGRO_INVERSE_ALPHA
    
     src = 1 - sa
     dst = 1 - sa
    Blending examples:
    
    So for example, to restore the default of using premultiplied alpha blending, you would use (pseudo code)
    
    al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA)
    If you are using non-pre-multiplied alpha, you could use
    
    al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA)
    Additive blending would be achieved with
      
          al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE)
         Copying the source to the destination (including alpha) unmodified
    
        al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO)
    You ended that sentence with a preposition...Bastard!

  14. #14
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Not sure if this is what you were talking about too but this is what I was referring to by Paint.NET: www.getpaint.net/

    al_set_blender changes how allegro calculates the final colors for pixels on the screen, in a sense.
    Learning some OpenGL would definitely help in understanding blending as well, but here's an attempt to explain what's going on.

    To achieve any transparency effect, each pixel from the source (what you're drawing to the screen) has to be blended with each pixel in the destination in some way.

    The docs say that the default is
    Code:
    al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA)
    ALLEGRO_ONE as the second argument means that each pixel from your source (sprite or otherwise) is multiplied by 1. In other words, nothing changes.
    ALLEGRO_INVERSE_ALPHA as the third argument means that each pixel in the destination is multiplied by 1-(alpha from source). So if source alpha=1, the destination pixels become 0, specifically RGBA = {0,0,0,0}. If source alpha=0, destination pixels don't change.

    Then ALLEGRO_ADD says that those two values are added together.

    ----------
    So let's say you're drawing a rectangle with RGBA={1,0,0,.5}.

    ALLEGRO_ONE says that for each pixel in the rectangle, we multiply by 1 to prepare for blending.
    ALLEGRO_INVERSE_ALPHA says that for each pixel in the destination, we multiply by [1-.5 =] .5 to prepare for blending. Multiplying by .5 gives the effect that color from the destination is being "blocked" to some degree by the source, like putting transparent plastic over an object.
    Then each pixel from the source {R,G,B,A} is added to each pixel from the destination {R*.5, G*.5, B*.5, A*.5}.
    The effect is a realistic blend of the two colors.
    ----------

    Using ALLEGRO_ONE for both source and destination means that no change is made for either source or destination pixels. The final computation is source {R,G,B,A} + destination {R,G,B,A} meaning that colors are added together without change. No color is "blocked" by overlapping shapes, creating bright spots in areas that overlap. The result is similar to spotlights shining on a wall.
    Consider this post signed

  15. #15
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    oh wow, yeah i think I sort of get it..
    so I guess I have no to do this calculations myself.
    the parameter doesn't say where to put the r,g,b values. So I would have to know what it is and provide the values?
    Code:
    void al_set_blender(int op, int src, int dst)
    so if the source rectangle pixels is (255,0,0) the src is 255?
    and if dest is (0,0,1) the dest is 1? I am not sure as to how to add the r,g,b values
    You ended that sentence with a preposition...Bastard!

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-07-2010, 11:08 PM
  2. So you want to be a game programmer?
    By dxfoo in forum Game Programming
    Replies: 23
    Last Post: 09-26-2006, 08:38 AM
  3. Try my game
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-15-2004, 11:58 AM
  4. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM

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