|
This thread is locked; no one can reply to it. |
1
2
|
al_draw_text with alpha |
AMCerasoli
Member #11,955
May 2010
|
There is a way to draw text with "al_draw_text" with Alpha? I tried: al_draw_text(font, al_map_rgba(255, 255 ,255 ,120), 635, 645, 0, "aloha"); But didn't work, there is a way? or should I use bitmap fonts? Conclusion:Allegro Uses pre-multiplied alpha by default al_map_rgba works great with bitmaps but doesn't seems to work with text. al_map_rgba_f works fine with text, but instead of use a parameter number from 0-255 for RBG colors uses a ranging from 0.0f-1.0f. So if you wan to convert a color from 0-255 to 0.0f-1.0f you need to use division. Ex: normal RGB (180,120,100,127.5) Would be: And if you need convert from 0.0f-1.0f to 0-255 you need to use uses multiplication. Ex: normal RGB (0.705,0.470,0.392,0.5)
|
jmasterx
Member #11,410
October 2009
|
It should work its just pre multiplied alpha is on by default so at the top of your render loop try: al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); Agui GUI API -> https://github.com/jmasterx/Agui |
AMCerasoli
Member #11,955
May 2010
|
Thanks man, now is working! But, when it says: "Sets the function to use for blending for the current thread" what is saying? The current tread is the whole tread right? because I saw something about "threading interface" which allows me to do multi threading? but if I'm not using it there is just one thread, right?
|
jmasterx
Member #11,410
October 2009
|
What they mean I think is that it affects all of your displays. If you have many displays, you must set blender for each one. void render() { //set display //set blender //draw //set display2 //set blender //draw } But if you only have 1 display (1 window) you don't have to worry about it. Agui GUI API -> https://github.com/jmasterx/Agui |
AMCerasoli
Member #11,955
May 2010
|
Oh I see. But have just notice this problem: I put al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); {"name":"603492","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/e\/2e1ea87d9d52d4ffa11dfc586179bb35.jpg","w":505,"h":718,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/e\/2e1ea87d9d52d4ffa11dfc586179bb35"} Should be like the PhotoShop version. I'm using: al_draw_tinted_bitmap(PNG, al_map_rgba(255, 255, 255, 255), 0, 0, 0 ); it's a PNG which already have transparency.
|
jmasterx
Member #11,410
October 2009
|
This is because Photoshop premultiplies Alpha for Bitmaps so try to set it back to premultiplied before drawing bitmaps and before loading bitmaps, but use the other blender to draw text. Agui GUI API -> https://github.com/jmasterx/Agui |
Elias
Member #358
May 2000
|
Or premultiply the color you draw the text with then you never need to touch the blender. -- |
AMCerasoli
Member #11,955
May 2010
|
But by default Allegro is also premultiplaying alpha right? Because if I don't modify the blending, Allegro draw it the same as Photoshop does. "premultiply the color you draw the text" sounds better, that doesn't mean that if I premultiply the white color, all the bitmaps that are using the white color are going to be affected? 1) How can I premultiply just one color? (if that is what you're suggesting)
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
AMCERASOLI said:
1) How can I premultiply just one color? (if that is what you're suggesting)
1) Use al_map_rgba_f(255.0f*0.5f , 127.0f*0.5f , 64.0f*0.5f , 0.5f). Premultiplying the alpha means multiplying it yourself, which makes no sense to me. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Dennis
Member #1,090
July 2003
|
AMCERASOLI said: But by default Allegro is also premultiplaying alpha right? Last time I checked, Allegro had no multiplayer functions at all. Premultiplied alpha means this: Additional reading: --- 0xDB | @dennisbusch_de --- |
AMCerasoli
Member #11,955
May 2010
|
hahahahaha That would be good a Multiplayer function!!. You just have to call al_set_multiplayer(ALLEGRO_PC * pc); and that's it. I would like to do it the Elias way. But I don't even know what means the 'f' letter after the numbers. Can someone drop a link? I don't know how to search (google:"the "f" letter after a number c++"?), it's something related with Hexadecimals right? The al_map_rgba_f function that Edgar gave me, seems to instead of get transparent, become black (when I modify it), because if I use it as he gave it to me, the text is drawn blue. This surely is because I don't know how to use it. I never saw anything about that in my C++ Book.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Sorry, I used al_map_rgba_f wrong. The values go from 0.0 to 1.0, not 0 to 255. al_map_rgba_f(1.0f*0.5f , 0.5f*0.5f , 0.25f*0.5f , 0.5f); Would give you a slightly desaturated orange at 50% opacity. The _f at the end of al_map_rgba_f just means it takes floating point values. The f at the end of the number values means they are floating point values. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
AMCerasoli
Member #11,955
May 2010
|
But why are you multiplying all that? isn't the same: al_map_rgba_f(0.5f , 0.25f , 0.125 , 0.5f) well actually it is, I tried it. I like this way since I don't have to use blending. But if I do al_map_rgba_f(0.5f , 0.25f , 0.125 , 0.0f) It gets white instead of transparent. I have been reading and that is one of the difference between premultiply and the other way. But then what I have to do?, changing the whole blending mode it seems unnecessary I don't know. I want to make an "appearing effect". from completely invisible to visible. PS: Oh boy, jmasterx already have told me that premultiplied is on by default, and I asked again, I didn't see it . I didn't process correctly the info .
|
Evert
Member #794
November 2000
|
AMCERASOLI said: But why are you multiplying all that? isn't the same: al_map_rgba_f(0.5f , 0.25f , 0.125 , 0.5f) well actually it is, I tried it.
Of course it's the same. |
AMCerasoli
Member #11,955
May 2010
|
I did change the values with al_set_blender and then set it back, but I'm getting this effect, and I really don't like it. {"name":"603498","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/e\/0e0e895fbf9444353e9b5164277536a4.jpg","w":243,"h":159,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/e\/0e0e895fbf9444353e9b5164277536a4"} That black border. How does work al_map_rgb_f? Can someone show me an example drawing text completely transparent with al_map_rgb_f? no matter what color it's. Isn't as simple as used to... the unique way I can make it complytly transparent is doing this: al_map_rgba_f(0.0f , 0.0f , 0.0f , 0.0f), the thing is now I don't know how to control those variables... RGB are in most applications, but know what can I use as reference?
|
Dennis
Member #1,090
July 2003
|
AMCERASOLI said: ..but know what can I use as reference?
Yes, the manual: http://docs.liballeg.org/graphics.html#al_set_blender Be patient. Read those sections of the manual slowly and make sure you understand each sentence before reading the next one. If there are any words you don't understand, look them up. --- 0xDB | @dennisbusch_de --- |
Elias
Member #358
May 2000
|
It's very simple: al_map_rgba_f(0, 0, 0, 0) // 0% opaque (fully transparent) al_map_rgba_f(0.25, 0.25, 0.25, 0.25) // 25% opaque al_map_rgba_f(0.50, 0.50, 0.50, 0.50) // 50% opaque (half transparent) al_map_rgba_f(1, 1, 1, 1) // 100% opaque (default, no transparency) This is when using the default blending mode only of course. [edit: The black border will appear if you change to non-pre-multiplied alpha, so don't do that. Leave everything at the defaults unless you know what you are doing.] -- |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Elias said: The black border will appear if you change to non-pre-multiplied alpha, so don't do that. Why would there be a black border if you're not using pre multiplied alpha? Shouldn't the outcome be the same as if you were using premultiplied alpha? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Dennis
Member #1,090
July 2003
|
Elias said: Leave everything at the defaults unless you know what you are doing. ..and to reach a point where you know what you're doing, it helps to read and understand manuals, to look up unknown words and to seek more details about a topic and not just copy & pasting examples. --- 0xDB | @dennisbusch_de --- |
Elias
Member #358
May 2000
|
Edgar Reynaldo said: Why would there be a black border if you're not using pre multiplied alpha? Shouldn't the outcome be the same as if you were using premultiplied alpha? Not if you use any kind of filtering (which I assume he's doing, don't see how there could be dark borders otherwise) - and that's precisely the reason why we switched to using pre-multipled alpha. Linear-interpolation-alpha just doesn't work with the way OpenGL/DirectX do interpolation. -- |
AMCerasoli
Member #11,955
May 2010
|
Black borders appear when I'm not using pre-multiplied alpha. But anyway thack a lot Elias that examples help me a lot, I know that I gonna have to read, what Dennis gave me, but I already solve my problem. The thing is now I have no reference, if I see for example a text in HTML/PhotoShop/etc, which use simple RGB, with the maximum amount of color been always 255. What I have to do to transform that to this type of RGB, when the maximum amount of color is 1.0?. I haven't read the links above, so if I'm saying something that I can find there, just don't even bother...
|
J-Gamer
Member #12,491
January 2011
|
Just multiply the value between 0.0 and 1.0 with 255 and there you go " There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo |
jmasterx
Member #11,410
October 2009
|
N/A Agui GUI API -> https://github.com/jmasterx/Agui |
J-Gamer
Member #12,491
January 2011
|
Err... jmaster, it's what I said... With that part of the phrase, I meant when going from photoshop/inkscape/... values to allegro values. So here is something clearer. When converting from the allegro values to the photoshop/inkscape/... values, multiply with 255. " There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo |
AMCerasoli
Member #11,955
May 2010
|
Thanks to all problem solved!
|
|
1
2
|