Allegro.cc Forums » Programming Questions » [A5] Draw a red light on a bitmap

 This thread is locked; no one can reply to it.
 [A5] Draw a red light on a bitmap
 anto80 Member #3,230 February 2003 Hello all,Since thread 615620 is locked, here is another chance for me to explain what I want to do.The first bitmap is the original bitmap.The second row is the same bitmap "blinking" 50% with red light; on the right it is 100% with red light.The third row is the same with white light. In Allegro 4 in 256 colors, we were using draw_lit_sprite to do this.In Allegro 5, al_draw_tinted_bitmap can't do the job. Drawing a filled rectangle is rather ugly, because the original sprite is not a rectangle.I have read the al_set_blender documentation as well as other "Most helpful discussions" on al_set_blender page.If I understand correcly, I would need to:1. First draw the source bitmap on destination2. Then set a blender to add{1,1,1,0} (Full White) and draw the result multiplied by {r,g,b, litLevel} on the destination. This way, draw a 50% red light corresponds to {r,g,b,litLevel} = {1,0,0, 0.5}How would I do this?Thank you ___________Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage
 NiteHackr Member #2,229 April 2002 I would simply draw the red or white bitmap over the first at 50% transparency. In my own game I use al_draw_tinted_bitmap(bitmap, al_map_rgb_f(.5, .5, .5), x, y, 0); to draw something at 50% transparency.I also have the following settings for my game which would effect this...al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR);al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
 anto80 Member #3,230 February 2003 Thank you for your reply but I'm still confused.NiteHackr said:I would simply draw the red or white bitmap over the first at 50% transparency. In my own game I use al_draw_tinted_bitmap(bitmap, al_map_rgb_f(.5, .5, .5), x, y, 0); to draw something at 50% transparency. Hmm when you say "the red or white bitmap", are you assuming that I must store 3 copies or the bitmap (the original, a full red one, and a full white one)?This is not the case for me: the original is loaded from a file, and I won't create file copies corresponding to each possible lit color for each sprite.NiteHackr said:I also have the following settings for my game which would effect this...al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR); Manual/5 said:ALLEGRO_MAG_LINEARWhen drawing a magnified version of a bitmap, use linear filtering. This will cause the picture to get blurry instead of creating a big rectangle for each pixel. It depends on how you want things to look like whether you want to use this or not. I don't see the point. Could you please explain?NiteHackr said: al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); Is this the way you can specify to display a red "version" of the sprite? ___________Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage
 Edgar Reynaldo Member #8,592 May 2007 Your best option was given to you in your last thread - use shaders.anto80 said: I don't see the point. Could you please explain? ALLEGRO_MAG_LINEAR is for when you are drawing magnified versions of your sprites - it uses smooth shading instead of blocky pixels.Quote: al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);Is this the way you can specify to display a red "version" of the sprite? No, what that does is set the blender for using premultiplied alpha. When using premultiplied alpha you specify colors by multiplying the rgb components by the alpha.```float alpha = .75; ALLEGRO_COLOR c = al_map_rgba_f(alpha*red , alpha*green , alpha*blue , alpha); ``` This will give you a 75% opaque color.Really, shaders are the way to go, because to 'light' your sprites you need to draw a light source over the top of them. One way is as NiteHackr suggests, to draw a light mask / map over your sprites. The second way is to use a shader, which you can set up to blend specified light levels with your sprites. Elizabeth Warren for President 2020! | Modern Allegro 4 and 5 binaries | Allegro 5 compile guideKing Piccolo will make it so
 anto80 Member #3,230 February 2003 OK I see now.I was looking at Allegro 5.0 manualand you certainly mean Shaders (which require to upgrade from 5.0 to the currently "unstable" 5.1 version)Is this correct?OK I've downloaded 5.1.8 version here : http://targonski.nazwa.pl/thedmd/allegro/5.1.8/But i can't compile (Error C1083: Cannot open include file: 'd3dx9.h': No such file or directory c:\allegro5-msvc9\include\allegro5\allegro_direct3d.h)```c:\allegro5-msvc9\include\allegro5\allegro_direct3d.h: #include #if defined ALLEGRO_CFG_SHADER_HLSL && defined __cplusplus #include #endif #include "allegro5/platform/alplatf.h" ``` What can I do ?Thank you ___________Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage
 Edgar Reynaldo Member #8,592 May 2007 You need DirectX to compile Allegro.You can get it here :http://alleg.sourceforge.net/files/dx9mgw.zipExtract it and then merge the folders with the appropriate compiler folders.Or you can install the DirectX SDK. Elizabeth Warren for President 2020! | Modern Allegro 4 and 5 binaries | Allegro 5 compile guideKing Piccolo will make it so
 NiteHackr Member #2,229 April 2002 Ah, okay, you weren't very clear on what you wanted to do. But if you're sprites are not going to be that big, I don't know why you are worried about there being copies of them. You're not programming for DOS on an 8bit machine anymore. My video card alone has 2gigs of RAM which is more than enough for most graphics, they really don't take up that much space, especially smaller ones so I couldn't jump through hoops to limit numbers like that.For my own game I have a circle I use for different spawns, I made it a white one with some alpha for the transparent areas, then I can set the colour using Allegro. I use the MAG_LINEAR stuff because then I can adjust my sprite sizes for any resolution monitor and they will still look nice. These days that is a breeze for all video cards anyhow, even cheap ones.I would redesign how you plan to display them to make things simpler. Shaders would work, but if you are having a difficult time with the simple commands I laid out, than I wouldn't suggest going anywhere near shaders just yet. What you could do is just make a shaded white sphere, then when you draw it, set the colour to whatever you wish and it will be drawn that colour using a tinted sprite. This way you're using one sprite and you can make it any colour you wish at runtime.
 Go to: Allegro Development Installation, Setup & Configuration Allegro.cc Comments Off-Topic Ordeals The Depot Game Design & Concepts Programming Questions Recent Threads