Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » AllegroGL

This thread is locked; no one can reply to it. rss feed Print
AllegroGL
Mariusz
Member #1,634
November 2001

Hi,

First of all I am totally new to AllegroGL. What I am trying to do is to set background (bmp) and then blit a PNG image on top that has a alpha channel. My final goal is to achieve an alpha blending around the edges of a PNG image to make is a smooth as possible.

Can anyone point me to some examples, please?

Thank you,
M.

Steve Terry
Member #1,989
March 2002
avatar

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glBind(blah);

Should be all you need. Allegro doesn't support PNG natively but you can use loadpng or a bitmap + grayscale mask to achieve the same effect.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Fladimir da Gorf
Member #1,565
October 2001
avatar

Maybe you should take a look at an Allegro add-on called OpenLayer. It's specifically suited for rendering 2D graphics - especially for rendering bitmaps with alpha channels (check the manual for Bitmap). With AllegroGL you can't (as far as I know) to rotate or stretch images with alpha channels or apply special effects to them. Also with AllegroGL you'll get a lot of overhead as it sends the bitmap data to the graphics card over and over when you render it.

OpenLayer comes with all pre-built libraries which are required to load png images. Installing everything is only 3 copy-paste operations ;)

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)

Bob
Free Market Evangelist
September 2000
avatar

Quote:

Also with AllegroGL you'll get a lot of overhead as it sends the bitmap data to the graphics card over and over when you render it.

Unless you just use video bitmaps, obviously.

Quote:

With AllegroGL you can't (as far as I know) to rotate or stretch images with alpha channels or apply special effects to them.

You can't yet, but it's not too difficult to add now that Allegro has had the suitable enhancements.

--
- Bob
[ -- All my signature links are 404 -- ]

Fladimir da Gorf
Member #1,565
October 2001
avatar

Quote:

Unless you just use video bitmaps, obviously.

Well, that makes sense indeed.

Quote:

You can't yet, but it's not too difficult to add now that Allegro has had the suitable enhancements.

Yeah, I've heard that Allegro will include functionality from AllegroGL and possibly even OpenLayer. The question is that how soon this will happen?

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)

Bob
Free Market Evangelist
September 2000
avatar

Quote:

Yeah, I've heard that Allegro will include functionality from AllegroGL and possibly even OpenLayer.

No that's not it. Allegro used to not have vtable entries for little things like stretch_bitmap(). This means that when you called stretch_bitmap(), Allegro software routines would kick in, even when you used AllegroGL!

The recent changes to Allegro allow AllegroGL to overload stretch_bitmap() (and others) so that these calls can be hardware accelerated.

--
- Bob
[ -- All my signature links are 404 -- ]

Peter Hull
Member #1,136
March 2001

Quote:

Unless you just use video bitmaps, obviously.

Bob, I ran into a problem with this on Linux. It seems that video bitmaps are always 32-bit, and therefore if you don't ask for a 32-bit screen mode (or, in my case, ask for but don't get), Allegro diverts the blit to the colour-depth conversion code, which means that it runs slower than a memory bitmap would. Have you any thoughts on this? I guess you've been too busy recently to do much on Allegro GL?

Pete

Bob
Free Market Evangelist
September 2000
avatar

Quote:

Allegro diverts the blit to the colour-depth conversion code, which means that it runs slower than a memory bitmap would.

I'm 99% sure I fixed that in Allegro. I guess it's still happening. Can you tell me which version of Allegro and AllegroGL you are using?

Quote:

I guess you've been too busy recently to do much on Allegro GL?

I'm doing some much-needed improvements now. I should have an RC out today or next week (I hope).

--
- Bob
[ -- All my signature links are 404 -- ]

Peter Hull
Member #1,136
March 2001

Allegro: 4.2.0
Allegro GL: 0.2.4
(both recently updated from CVS)
Here's my test program

1#include <allegro.h>
2#include <alleggl.h>
3#include <time.h>
4#include <cstdio>
5using namespace std;
6 
7#define FR 100
8 
9float test (BITMAP * bm)
10{
11 float t = clock ();
12 for (int j = 0; j < FR; ++j) {
13 for (int i = 0; i < 1000; ++i) {
14 blit (bm, screen, 0, 0, 0, 0, bm->w, bm->h);
15 }
16 allegro_gl_flip ();
17 }
18 float f = clock ();
19 return float (f - t) / float (CLOCKS_PER_SEC);
20}
21 
22int main ()
23{
24 allegro_init ();
25 install_allegro_gl ();
26 allegro_gl_set (AGL_COLOR_DEPTH, 32);
27 allegro_gl_set (AGL_DOUBLEBUFFER, 1);
28 set_gfx_mode (GFX_OPENGL_WINDOWED, 640, 480, 0, 0);
29 BITMAP *bm = create_bitmap (64, 64);
30 clear_to_color (bm, makecol (0, 0, 0));
31 circle (bm, 32, 32, 20, makecol (128, 255, 0));
32 BITMAP *vbm = create_video_bitmap (bm->w, bm->h);
33 blit (bm, vbm, 0, 0, 0, 0, bm->w, bm->h);
34 printf ("mem %f\n", test (bm));
35 printf ("vid %f\n", test (vbm));
36 return 0;
37}
38 
39END_OF_MAIN ()

Typical output: (times are in seconds)

Quote:

mem 3.800000
vid 7.320000

Pete

[edit] That was on Linux, on OSX I get the astonishing result of

Quote:

mem 52.549999
vid 1.570000

:o

Bob
Free Market Evangelist
September 2000
avatar

Can you check, under both Linux and OSX, which code path is being taken in AGL?

--
- Bob
[ -- All my signature links are 404 -- ]

Go to: