Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Blending textures

This thread is locked; no one can reply to it. rss feed Print
Blending textures
Wilson Saunders
Member #5,872
May 2005
avatar

I am trying to draw a top down view of the ground in my game world by patching a bunch of tiles next to each other. The thing is that my world is out doors/natural and I don't like hard edges between my tiles. To solve this I would like to blend the colors from one tile into it's adjoining tile.

However the only way I can see to do this with allegro is to pull the RGB color values of a pixel from one tile and average it with the RGB values of another tile. Then making a new color from the averaged RGB values and put it where it belongs. Needless to say this is very slow and unacceptable for the speed I want my ground to scroll.

Is there anyway, with allegro, to draw a tile with Alpha softened edges? I will need a smooth Alpha transition like in a .tga file or else I would just use magenta .bmp files. I tried RTM but a function name would be most helpfull.

________________________________________________
Play my games at http://monkeydev.com

GullRaDriel
Member #3,861
September 2003
avatar

something like this ?

set_alpha_blender();
draw_trans_sprite( bmp , sprite -> spr[ frame ] , x - sprite -> x , y - sprite -> y );

The only thing I do not know ( If someone can tell ):

After a call to set_alpha_blender, can I use several call to draw_trans_sprite or do I need to call it each time before draw_trans_sprite ?

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Fladimir da Gorf
Member #1,565
October 2001
avatar

You need to call it only once. Better to pre-calculate the results, though. Allegro's blenders are really slow.

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

GullRaDriel
Member #3,861
September 2003
avatar

Wilson Saunders, could you tell us if the answer was the one you were waiting for ?

( Thanks Flad ;-) I only use allegro's blender as fallback, I tend to use allegrogl instead. )

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Wilson Saunders
Member #5,872
May 2005
avatar

Well I will try set_alph_blender() but I will need to know how you load a bmp which has an alpha layer. Also if blending is slow I may have to forgo this entirely. I am needing to do a lot of blends on 64x64 or 128x128 tiles. I guess the real test will be in game performance. I just got off my 10 hour shift at work so I am not going ot impliment this now.

________________________________________________
Play my games at http://monkeydev.com

TeamTerradactyl
Member #7,733
September 2006
avatar

For a map assuming 16x16 pixels, just make all the tiles 18x18 and make them overlap each other by that 1 extra pixel per side. Use draw_trans_sprite() to put them into their places, and the edges will blend by themselves.

Oh yea... the game might run a little slow, but that's alright, right? :P

FuriousOrange
Member #7,305
June 2006
avatar

Or draw the tiles so they wrap properly...

Go to: