![]() |
|
Mixing bitmaps |
Thinkal VB
Member #16,859
May 2018
|
I was trying to mix different terrain bitmaps to make mixed terrains. But however, it is not working. Every time I render it, it turns out to be white. But when I try the same with individual bitmaps it's working fine. What would I be doing wrong - is it even possible? |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
https://github.com/ThinkalVB/NearEarth/blob/master/RenderingEngine/Texture.cpp#L39-L42 Well, your colors are wrong. :/ You're tinting white at full and zero alpha. Of course its white. Allegro uses pre-multiplied alpha. That means you need to use al_map_rgba(r*a , g*a , b*a , a) for your color 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 |
Thinkal VB
Member #16,859
May 2018
|
Thank you, Edgar Reynaldo, for replaying |
dthompson
Member #5,749
April 2005
![]() |
At first, I found it difficult to understand why Allegro 5 uses premultiplied alpha. "Surely this'll just make my textures unnecessarily darker when drawn" was my first thought. Have a look at this article for some explanation as to why it's useful. Funnily enough, it's written by a guy called Shawn Hargreaves - same name as the guy who wrote the original Allegro! (no idea whether it's the same person.) EDIT well I'll be damned, it is. Guess he's still useful after all these years. ______________________________________________________ |
Thinkal VB
Member #16,859
May 2018
|
Thank you dthompson, |
dthompson
Member #5,749
April 2005
![]() |
Not too complex if you're using Allegro, most of the time. In this instance you just need to set your alpha value to 1. A word of advice on this: Allegro's blenders make it easy to tint your textures if you want to remove colour (ie. make them darker). If you want to "tint them brighter", you'll probably need to write a shader. ______________________________________________________ |
Thinkal VB
Member #16,859
May 2018
|
Thank you dthompson, |
dthompson
Member #5,749
April 2005
![]() |
I'll have to get back to you once I've written a proper engine myself. It's an admirable undertaking - be warned that this will without any doubt be a huge amount of work for you, though. Frameworks are not easy to write! You mention that you've had some experience with this, but I'd have to warn you to be careful that you're not optimising prematurely. The page I've linked to mainly talks about code speed, though it applies just as much to code organisation. Have you written an entire MMO before? If not, it might be worth doing that first, identifying the patterns that your framework could address, then stripping down the source of your game to create the framework. Sorry if this sounds boring, but it could save you a lot of time ______________________________________________________ |
Thinkal VB
Member #16,859
May 2018
|
Thank you dthompson, |
dthompson
Member #5,749
April 2005
![]() |
Building a prototype would be a great idea - even moreso if you're attempting to submit it academically, as {prototypes, failed attempts, previous projects} are useful in demonstrating your thinking process. ______________________________________________________ |
Thinkal VB
Member #16,859
May 2018
|
Thank you dthompson, |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
You can change the blender and use non-pm alpha if you want, but you might as well get used to it. It's pretty much the norm. OpenGL uses it too I think. Here is some example code : ALLEGRO_COLOR red_full_alpha = al_map_rgba_f(1.0 , 0.0 , 0.0 , 1.0); ALLEGRO_COLOR white_half_alpha = al_map_rgba_f(1.0*0.5 , 1.0*0.5 , 1.0*0.5 , 0.5); al_draw_tinted_bitmap(sprite1 , red_full_alpha , 0 , 0 , 0); al_draw_tinted_bitmap(sprite2 , white_half_alpha , 0 , 0 , 0); Here's some sample blender code : al_set_blender(ALLEGRO_ADD , ALLEGRO_ONE , ALLEGRO_ZERO);/// Overwrite blender al_set_blender(ALLEGRO_ADD , ALLEGRO_ONE , ALLEGRO_INVERSE_ALPHA);/// Default Pre Multiplied Alpha blender al_set_blender(ALLEGRO_ADD , ALLEGRO_ALPHA , ALLEGRO_INVERSE_ALPHA);/// Regular alpha blender, non-pm
EDIT 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 |
Thinkal VB
Member #16,859
May 2018
|
Thank you Edgar Reynaldo, I personally think allegro must support more features like the allegro flare - inbuilt support for light, animation, shadow, 3D objects etc... So that if we want we can create one, or for those who want the hard way around can go for it (building things from scratch). T think until I have a prototype I should move forward with allegro, Before porting it to other frameworks - else I never hit the finish line. In future working with Ogre would be nice. But I need to have a clear understanding before moving on to 3D. So Allegro is good for now. |
|