![]() |
|
Transparent pixel |
blakat
Member #15,991
June 2015
|
My question regards going about the transparent pixel of my sprite, I use 24 bit .tga's with no alpha channel(obviously) and load them using al_load_bitmap(*char); |
RPG Hacker
Member #12,492
January 2011
![]() |
I'm asuming you're using Allegro 5. In case you're actually using Allegro 4, "magic pink" (R: 255, G: 0, B: 255) is the color you want for transparency. If you're using Allegro 5, though, this is the function you want: void al_convert_mask_to_alpha(ALLEGRO_BITMAP *bitmap, ALLEGRO_COLOR mask_color); It converts all pixels on an image with a certain color to transparent.
|
blakat
Member #15,991
June 2015
|
I am using Allegro 5 |
RPG Hacker
Member #12,492
January 2011
![]() |
blakat said: would this function only work if my tga had a alpha channel Maybe Allegro automatically picks a bitmap format without Alpha when loading an image that doesn't have an alpha channel. You can override the bitmap format, though. Just call this function before loading your image: void al_set_new_bitmap_format(int format); Just pass it any format that supports alpha like ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA, ALLEGRO_PIXEL_FORMAT_ARGB_8888 etc. I recommend first calling int al_get_new_bitmap_format(void); to backup the currently active bitmap format and then restore this format after loading your bitmap (so that all bitmaps loader afterwards will be created with the originally set bitmap format).
|
Polybios
Member #12,293
October 2010
|
Well... Are you sure you got the color right (maybe try full black / white)? Are you sure you use the function on the very bitmap you draw later? |
blakat
Member #15,991
June 2015
|
I got it to work, I simply had the wrong rgb value. My final question is how come when pass a ALLEGRO_COLOR variable directly into the second arguement of al_convert_mask_to_alpha() it doesnt seem to have effect? It only seems to work when I write al_convert_mask_to_alpha(*, al_map_rgb(short, short, short)); |
RPG Hacker
Member #12,492
January 2011
![]() |
ALLEGRO_COLOR uses float values for color components (0.0f to 1.0f). Could that have been your mistake?
|
blakat
Member #15,991
June 2015
|
I tried modifying my operation with the info you shared |
Audric
Member #907
January 2001
|
It should work... ALLEGRO_COLOR col = al_map_rgb(0, 255, 114); YourFunction(col); Definition: void Yourfunction(ALLEGRO_COLOR transparent_color) { ... al_convert_mask_to_alpha(bmp, transparent_color); }
|
RPG Hacker
Member #12,492
January 2011
![]() |
blakat said: transparentPixal = al_map_rgb(0.0f, 255.0f, 114.0f); You don't need to use floats, unless you use al_map_rgb_f() (in which case you use values from 0.0f to 1.0f). If you use al_map_rgb(), integers will do (ranging from 0 to 255). Aside from that, nothing wrong with your code. It should work the way you posted it here. Is that the exact code from your game? Can you copy & paste the snippet directly from your game?
|
blakat
Member #15,991
June 2015
|
Line 56 and 57 are the ones of focus, transparentPixal is declared on line 20. This is just a test program, once test succeed i paste it's snippets into my game. |
RPG Hacker
Member #12,492
January 2011
![]() |
blakat said: I'm stumped As I suggested: RPG Hacker said: Can you copy & paste the snippet directly from your game?
|
blakat
Member #15,991
June 2015
|
Sorry i posted that without refreshing the page, I only saw Audric's message. That edited post has a file attachment. |
RPG Hacker
Member #12,492
January 2011
![]() |
I'm seeing nothing that strikes me as obviously wrong with your code. Are you sure that passing transparentPixal to the function doesn't work and passing al_map_rgb(0, 255, 114) to the function directly DOES work? That is the only thing that is puzzling me. I'm not currently at my home computer, so I can't test the code myself. If you look at transparentPixal in your debugger after asigning the value to it, what does it say? And in case you have access to the Allegro source while debugging, if you step into the call al_convert_mask_to_alpha(bmp, al_map_rgb(0, 255, 114)); What does the color argument say when looking at it in the debugger? Also, what OS are you on, what version of Allegro are you using and which compiler did you compile this with?
|
blakat
Member #15,991
June 2015
|
Edit: Here are the results of both calls. |
RPG Hacker
Member #12,492
January 2011
![]() |
I don't have too much experience with Linux systems unfortunately, so maybe someone else can provide better help. In any case, two IDEs for Linux I know of are Eclipse and Code::Blocks. Just pick whichever IDE you like best. I haven't worked much with either of those, so I can't give any specific instructions on how to do it, but basically you'll want to find out how to set breakpoints and view the value of a variable. In many IDEs, both things are pretty straight-forward. For example, in Visual Studio you just click a line number to set a breakpoint and hover the mouse over a variable to view its value. I can imagine it's similar with the two aforementioned IDEs, but you'll have to find that out for yourself. Quote: allegro 5 Yeah, I figured as much. But which specific version of Allegro 5? As in, Allegro 5.X.X?
|
Audric
Member #907
January 2001
|
int main(int argc, char **argv) { (...) ALLEGRO_COLOR transparentPixal = al_map_rgb(0, 255, 114);
This calls al_map_rgb() before allegro and its graphic mode get initialized. |
RPG Hacker
Member #12,492
January 2011
![]() |
Oh, well spotted! I totally overlooked that! al_map_rgb(a) seems to convert colors by taking its values from an array called "_al_u8_to_float" (using the integer color component value as an index). I can imagine that said array isn't initialized until either Allegro is installed or the graphics system is.
|
blakat
Member #15,991
June 2015
|
That was a complete duh moment, thanks guys for all the help, it works as I intend it to. |
Polybios
Member #12,293
October 2010
|
RPG Hacker said: I can imagine that said array isn't initialized until either Allegro is installed or the graphics system is. Yes, I can confirm that. The float variants will work without initialization, but converting from integers won't work without calling al_init(). |
Bruce Pascoe
Member #15,931
April 2015
![]() |
@Polybios The reason, incidentally, is that Allegro uses a lookup table for the integer variants instead of calculating it directly (which would require 3-4 expensive FP divisions), and the tables aren't initialized until you call al_init().
|
|