Mixing bitmaps
Thinkal VB

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.
I tried different transparency for different terrains bitmaps - but it's not working.

What would I be doing wrong - is it even possible?

Edgar Reynaldo


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.

Thinkal VB

Thank you, Edgar Reynaldo, for replaying
I didn't quite get the idea. You meant every time I have to tint a bitmap while I draw it, I must multiply the alpha with the RGB value?


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

Thank you dthompson,
So tinting is way more complex than I thought. :'(::):P
I am a little alien to premultiplies alphas and hardcode graphics terms. RGB and Alpha are the farthest I have gone.


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

Thank you dthompson,
I will keep that in mind.
Can you suggest some improvements to my project? I am planning to include a spotlight type light. But I need some instructions to start.
I am planning to make an MMO 2D top-down shooter game and a framework along with it - for others to make their own game if they want. Custom made for MMO's.
I am planning to start developing the Network Engine the next month using ASIO, as I have some previous experience with ASIO during a failed attempt while making a similar game.


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 :P

Thinkal VB

Thank you dthompson,
No, it's not at all boring. In fact, it's really enlightening - I need opinions from peoples because I believe there is always something I can learn from everyone whether it be a kid or an adult with a good programming experience.
No, I had never made an MMO before - but I have made attempts to do so. Once I was really close but had to step back due to academic reasons and time carried away and the project was lost in time. But this time I am more determined to make it because I have a 2-month vacation before my college starts and I am intending to do it as my final year project. I am not behind big blockbuster games but a simple one as a proof of concept like a prototype model.


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

Thank you dthompson,
But in Kerala you need a working thing to get a pass mark on project 😂. But in my class of computer engineers 39 out of 45 have not even the slightest idea about programming.
So mostly they do is buy a project from some companies and submit it as thier project - and it's been going on like that for centuries here. 😂

Edgar Reynaldo

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

Before you get too far into this sort of thing, why don't you check out Mark Oates Allegro FLARE framework?

Thinkal VB

Thank you Edgar Reynaldo,
Oh my goodness, Where was allegro flare all these years?
Allegro Flare is promising. It's abstracting a lot of low-level details from us making the development more hassle-free. But there is no tutorial for it to get started. The main reason I chose Allegro is that it had a lot of tutorials on youtube and a good and active community to support it. Also, VCPKG doesn't have allegro flare - so even if I try to port it to allegro flare - I will be having a hard time integrating it to my IDE - because it's hard for me, most of the time something goes wrong.

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.

Thread #617480. Printed from Allegro.cc