Jump to content
  • Advertisement
Sign in to follow this  
darenking

Allegro fblend installed, help using library required!

This topic is 4847 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I recently got the fblend library installed (if that's the correct term), with help from people on this message board. I can use this function to draw sprites to the screen: fblend_trans(sprite, buffer, x, y, 255); The problem is, it just draws the sprite solid (or the whole sprite translucent if I alter the final value). If I use the following Allegro routine, the sprite is drawn with the alpha layer. (I create the bitmaps in Photoshop, with an alpha layer, and export them as 32 bit TGA image files. They're RGBA images. And I know they're loading in as Allegro BITMAPs correctly as the Allegro routines below draw the alpha blended pixels correctly.) Here's the Allegro stuff, which works perfectly, but is too slow if I draw a lot of bitmaps: drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); set_alpha_blender(); draw_trans_sprite(buffer, sprite, x, y); First question, am I using the correct fblend function? I want to draw the bitmap so that it uses the alpha layer for the blending rather than say drawing the entire image translucent. Second question, do I have to 'set_alpha_blender' or any other such command? I've read the help files that come with fblend but they don't really seem to explain anything, certainly not in terms that I understand!

Share this post


Link to post
Share on other sites
Advertisement
Unfortunately, Fblend doesn't blend from an alpha channel. Fblend just takes the parameter you pass to it and blends your bitmap with the destination you blit it to based on that. Most blending these days is being done in hardware via Direct3D and OpenGL which makes it much faster. But you can still get some kool effects from Fblend and Allegro, you just won't be able to use your TGA alpha channel.

Share this post


Link to post
Share on other sites
You might also want to make sure drawing_mode() and set_alpha_blender() are only being called as often as necessary -- if possible, once at initialization of your program. Once per frame would probably be acceptable, if necessary.

Most computers nowadays are fast enough to do an enormous amount of blitting, even with alpha blending. I've, personally, never had any problems with Allegro's speed in that department. You may want to your own code for possible design flaws.

Share this post


Link to post
Share on other sites
At the moment some of my sprites are drawn solid and some with alpha blending.

I've been setting drawing_mode and alpha_blender each loop, before I draw the alpha sprites:

drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
set_alpha_blender();

then after drawing the alphas I've gone back to solid mode:

drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);

ready for drawing solid sprites next time.

I've just changed it so that it stays in TRANS mode all the time, and it runs fine (and probably a lot faster).

Thinking about it, I can't see any reason why you would have to keep changing between solid mode and trans mode, or why you would have to set the alpha blender more than once, can you?

I mean, being in trans mode doesn't mean you have to draw translucent sprites: you can draw a solid sprite (with transparency for the pink colour) with draw_sprite (instead of draw_trans_sprite) and you can draw a completely solid sprite with blit.

Or does trans mode slow down regular drawing (draw_sprite or blit)? I can't think of any reason why it should!

Share this post


Link to post
Share on other sites
Hm. This might have helped with the slowdown too: you're calling drawing_mode(), but are you using any of the "drawing" functions? drawing_mode() doesn't affect any of the blitting and sprite functions, so if you aren't using things like rect() or putpixel(), you can skip that function call altogether.

And, yeah, I'm pretty sure set_alpha_blender() only affects the trans functions. Regular blit() and draw_sprite() shouldn't be affected.

Cheers,
Twilight Dragon

Share this post


Link to post
Share on other sites
That's nice and simple then. I just do set_alpha_blender() right at the start with this lot:

allegro_init();
set_color_depth(MONITOR_DEPTH);
set_gfx_mode(MONITOR_MODE, bufferWidth, bufferHeight, 0, 0);
set_alpha_blender();
install_keyboard();

...then just draw my bitmaps with blit and draw_sprite and draw_trans_sprite.


I'm a bit baffled by fblend though. If it doesn't look at the alpha layer of a RGBA bitmap, what is the point in using it? If your game is just bitmap (sprite and tile) based rather than using vector style graphics I mean.

Share this post


Link to post
Share on other sites
Anyone else know? I'm sure it must be useful for something!

Maybe there is a way of using it to access the alpha layer of RGBA bitmaps, even if you have to write your own method.

Share this post


Link to post
Share on other sites
Quote:
Original post by darenking
Anyone else know? I'm sure it must be useful for something!
Cross-fading two bitmaps? (It's a long, long time since I used Allegro, so maybe this is something it does natively anyway).
From a quick poke around in the documentation, FBlend doesn't seem to do an awful lot beyond fast bitmap (just the RGB) blending and a very simple 2X stretch. Maybe you could fiddle around in the source to allow it to take the alpha channel into consideration, but as it claims to be so fast and written in ASM, I don't know how easy the source is to work with.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!