Gl blitting and alpha blending

--------------0022211E9D1E612C8D636B95
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

I am experimenting with SDL, OpenGL with blitting access and SDL_ttf
with blended fonts and can’t seem to get the keying and blending
working.

Starting from the stock gltest.c I’ve added:


SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, rgb_size[3] );

SDL_GL_GetAttribute( SDL_GL_ALPHA_SIZE, &value );
printf( “SDL_GL_ALPHA_SIZE: requested %d, got %d\n”,
rgb_size[3],value);

Problem(?): Alpha is reported to be 0.

Text is drawn usiung the code below. It shows a white box only (i.e no
text) while using a solid-mode black/white text drawing works and shows
the text but overwrites the background.


screen = SDL_GetVideoSurface();
if (text == NULL) {
text = TTF_RenderText_Blended (font, “Welcome to SDL!”, white);
} else {
dst.x = 100;
dst.y = 100;
dst.w = text->w;
dst.h = text->h;
SDL_BlitSurface(text, NULL, screen, &dst);
SDL_UpdateRects(screen, 1, &dst);
}

I also can’t get the icon.bmp’s white background to be keyed to black.
The gltest.c source code mentions some cool effects when changing alpha
setup. Can anyone send me some more specific code.

Any ideas, suggestions, pointers to tutorials or sample code would be
welcome. What I’d like to do is to blit with SDL to a GL window first,
draw GL second and blit again lastly.

Sorry to be so amateurish about this, but I am just starting to use SDL
and haven’t figured everything out yet… My setup for reference: Linux
RH 6.2/SDL 1.1.6/Mingw32-crosscompiled to run on a Voodoo3500 on Win32.

Thanks
Andreas–
| Andreas Schiffler aschiffler at home.com |
| 4707 Eastwood Cres., Niagara Falls, Ont L2E 1B4, Canada |
| +1-905-371-3652 (private) - +1-905-371-8834 (work/fax) |

--------------0022211E9D1E612C8D636B95
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>

Hi,

I am experimenting with SDL, OpenGL with blitting access and SDL_ttf with blended fonts and can't seem to get the keying and blending working.

Starting from the stock gltest.c I've added:

...
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, rgb_size[3] );
...
SDL_GL_GetAttribute( SDL_GL_ALPHA_SIZE, &value );
        printf( "SDL_GL_ALPHA_SIZE: requested %d, got %d\n", rgb_size[3],value);
...

Problem(?): Alpha is reported to be 0.

Text is drawn usiung the code below. It shows a white box only (i.e no text) while using a solid-mode black/white text drawing works and shows the text but overwrites the background.

...
screen = SDL_GetVideoSurface();
if (text == NULL) {
text = TTF_RenderText_Blended (font, "Welcome to SDL!", white);
} else {
                dst.x = 100;
                dst.y = 100;
                dst.w = text->w;
                dst.h = text->h;
                SDL_BlitSurface(text, NULL, screen, &dst);
                SDL_UpdateRects(screen, 1, &dst);
}
...

I also can't get the icon.bmp's white background to be keyed to black. The gltest.c source code mentions some cool effects when changing alpha setup. Can anyone send me some more specific code.

Any ideas, suggestions, pointers to tutorials or sample code would be welcome. What I'd like to do is to blit with SDL to a GL window first, draw GL second and blit again lastly.

Sorry to be so amateurish about this, but I am just starting to use SDL and haven't figured everything out yet.. My setup for reference: Linux RH 6.2/SDL 1.1.6/Mingw32-crosscompiled to run on a Voodoo3500 on Win32.

Thanks
Andreas

-- 
|  Andreas Schiffler                    aschiffler at home.com  |
|  4707 Eastwood Cres., Niagara Falls, Ont  L2E 1B4, Canada  |
|  +1-905-371-3652 (private)  -  +1-905-371-8834 (work/fax)  |
 

--------------0022211E9D1E612C8D636B95–

SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, rgb_size[3] );

Alpha frame buffer is very very different from using alpha
blending. Read your Red Book for more info.

And please don’t post mixed text/html email.

m.On Tue, Dec 19, 2000 at 05:51:11PM -0800, Andreas Schiffler wrote:


Programmer “Ha ha.” “Ha ha.” "What are you laughing at?"
Loki Software "Just the horror of being alive."
http://lokigames.com/~briareos/ - Tony Millionaire

Michael Vance wrote:

SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, rgb_size[3] );

Alpha frame buffer is very very different from using alpha
blending. Read your Red Book for more info.

I realize that … the point is though, I can’t seem to get an
alpha-channel through the


video_flags = SDL_OPENGLBLIT;
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, rgb_size[3] );
SDL_SetVideoMode( w, h, bpp, video_flags )

call sequence (regardless if I need it for alpha blending/blitting or
not).

And please don’t post mixed text/html email.

Sorry about that … its a netcape default. (and a habit of mine).

Cheers
Andreas> On Tue, Dec 19, 2000 at 05:51:11PM -0800, Andreas Schiffler wrote:


| Andreas Schiffler aschiffler at home.com |
| 4707 Eastwood Cres., Niagara Falls, Ont L2E 1B4, Canada |
| +1-905-371-3652 (private) - +1-905-371-8834 (work/fax) |

I realize that … the point is though, I can’t seem to get an
alpha-channel through the

Right–very few consumer hardware devices support it. The Matrox G450
might, I know Mattias was raving about it at some point. But I haven’t
ever seen a card do it…

video_flags = SDL_OPENGLBLIT;
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, rgb_size[3] );

Yeah, this isn’t going to get you anywhere.

call sequence (regardless if I need it for alpha blending/blitting or
not).

Alpha blending is done through glEnable( GL_BLEND ) and using
glBlendFunc, etc. Nothing to do with the GLX alpha size. That’s for
high end SGI type fun.

m.On Tue, Dec 19, 2000 at 06:22:21PM -0800, Andreas Schiffler wrote:


Programmer “Ha ha.” “Ha ha.” "What are you laughing at?"
Loki Software "Just the horror of being alive."
http://lokigames.com/~briareos/ - Tony Millionaire

Andreas Schiffler wrote:

Michael Vance wrote:

SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, rgb_size[3] );

Alpha frame buffer is very very different from using alpha
blending. Read your Red Book for more info.

I realize that … the point is though, I can’t seem to get an
alpha-channel through the

Well, does your HW (and the driver) support it? Try running glxinfo (I think
it’s part of the Mesa demos).

DRI CVS tdfx-3-0-0 branch on a Voodoo 5

visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav
id dep cl sp sz l ci b ro r g b a bf th cl r g b a ns b eat>> On Tue, Dec 19, 2000 at 05:51:11PM -0800, Andreas Schiffler wrote:

0x23 24 tc 0 24 0 r y . 8 8 8 0 0 16 0 0 0 0 0 0 0 None
0x24 24 tc 0 24 0 r y . 8 8 8 0 0 16 8 16 16 16 0 0 0 None
0x25 24 dc 0 24 0 r y . 8 8 8 0 0 16 0 0 0 0 0 0 0 None
0x26 24 dc 0 24 0 r y . 8 8 8 0 0 16 8 16 16 16 0 0 0 None

NVIDIA drivers on a GeForce 2 GTS

visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav
id dep cl sp sz l ci b ro r g b a bf th cl r g b a ns b eat

0x21 24 tc 0 32 0 r y . 8 8 8 8 0 24 8 16 16 16 16 0 0 None
0x22 24 dc 0 32 0 r y . 8 8 8 8 0 24 8 16 16 16 16 0 0 None
0x23 24 tc 0 32 0 r . . 8 8 8 8 0 24 0 16 16 16 16 0 0 None
0x24 24 tc 0 32 0 r . . 8 8 8 8 0 24 8 16 16 16 16 0 0 None
0x25 24 tc 0 32 0 r y . 8 8 8 0 0 24 0 16 16 16 16 0 0 None
0x26 24 tc 0 32 0 r y . 8 8 8 8 0 24 0 16 16 16 16 0 0 None
0x27 24 tc 0 32 0 r y . 8 8 8 0 0 24 8 16 16 16 16 0 0 None
0x28 24 tc 0 0 0 c . . 0 0 0 0 0 0 0 0 0 0 0 0 0 None
0x29 24 tc 0 0 0 c . . 0 0 0 0 0 0 0 0 0 0 0 0 0 None
0x2a 24 dc 0 32 0 r . . 8 8 8 8 0 24 0 16 16 16 16 0 0 None
0x2b 24 dc 0 32 0 r . . 8 8 8 8 0 24 8 16 16 16 16 0 0 None
0x2c 24 dc 0 32 0 r y . 8 8 8 0 0 24 0 16 16 16 16 0 0 None
0x2d 24 dc 0 32 0 r y . 8 8 8 8 0 24 0 16 16 16 16 0 0 None
0x2e 24 dc 0 32 0 r y . 8 8 8 0 0 24 8 16 16 16 16 0 0 None
0x2f 24 dc 0 0 0 c . . 0 0 0 0 0 0 0 0 0 0 0 0 0 None
0x30 24 dc 0 0 0 c . . 0 0 0 0 0 0 0 0 0 0 0 0 0 None

                        Daniel Vogel, Programmer, Loki Software Inc.

Daniel Vogel wrote:

Andreas Schiffler wrote:

Michael Vance wrote:

SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, rgb_size[3] );

Alpha frame buffer is very very different from using alpha
blending. Read your Red Book for more info.

I realize that … the point is though, I can’t seem to get an
alpha-channel through the

Well, does your HW (and the driver) support it? Try running glxinfo (I think
it’s part of the Mesa demos).

DRI CVS tdfx-3-0-0 branch on a Voodoo 5

ups, that was indirect rendering, but well, proves my point anyways - check
whether the HW/driver actually supports it or not.

                        Daniel Vogel, Programmer, Loki Software Inc.>>> On Tue, Dec 19, 2000 at 05:51:11PM -0800, Andreas Schiffler wrote:

--------------E33F2FD5B48043922E8F4B44
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Daniel Vogel wrote:

Andreas Schiffler wrote:

Michael Vance wrote:

SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, rgb_size[3] );

Well, does your HW (and the driver) support it? Try running glxinfo (I think
it’s part of the Mesa demos).

OK, forget the hardware alpha blending in OpenGL. I was just poking at the
settings because its there and I might have had something to do with my
problem.

What about the SDL blitting functions (in software). Alpha Blits don’t seem to
work anymore on an OpenGL surface. And as far as I understand, they should be
independent of the target surface i.e. an alpha blit RGBA --> RGB/OpenGL
should work and give the same results as RGBA --> RGB/SDL-SW or RGBA -->
RGB/SDL-HW.

Just try to mix the testgl.c and testalpha.c programs … testalpha.c doesn’t
work for an OPENGLBLIT surface. I also compared the results on the
Win32/Voodoo3 version with a Linux/G450 version of the program. Both don’t work
(i.e. no blending is done) and actually give different results visually.

I am not sure if this is a GL driver issue, a coding problem/mistake on my part
or bug in SDL.

Thanks for all your tips and comments so far.
Andreas> >> On Tue, Dec 19, 2000 at 05:51:11PM -0800, Andreas Schiffler wrote:


| Andreas Schiffler aschiffler at home.com |
| Senior Systems Engineer - Deskplayer Inc., Buffalo |
| 4707 Eastwood Cres., Niagara Falls, Ont L2E 1B4, Canada |
| +1-905-371-3652 (private) - +1-905-371-8834 (work/fax) |

--------------E33F2FD5B48043922E8F4B44
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>

Daniel Vogel wrote:
Andreas Schiffler <aschiffler at home.com> wrote:
>Michael Vance wrote:
>
>> On Tue, Dec 19, 2000 at 05:51:11PM -0800, Andreas Schiffler wrote:
>>
>> > SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, rgb_size[3] );
>>
Well, does your HW (and the driver) support it? Try running glxinfo (I think
it's part of the Mesa demos).
 
OK, forget the hardware alpha blending in OpenGL. I was just poking at the settings because its there and I might have had something to do with my problem.

What about the SDL blitting functions (in software). Alpha Blits don't seem to work anymore on an OpenGL surface. And as far as I understand, they should be independent of the target surface i.e. an alpha blit  RGBA --> RGB/OpenGL should work and give the same results as RGBA --> RGB/SDL-SW or RGBA --> RGB/SDL-HW.

Just try to mix the testgl.c and testalpha.c programs ... testalpha.c doesn't work for an OPENGLBLIT surface. I also compared the results on the Win32/Voodoo3 version with a Linux/G450 version of the program. Both don't work (i.e. no blending is done) and actually give different results visually.

I am not sure if this is a GL driver issue, a coding problem/mistake on my part or bug in SDL.

Thanks for all your tips and comments so far.
Andreas

-- 
|  Andreas Schiffler                    aschiffler at home.com  |
|  Senior Systems Engineer    -    Deskplayer Inc., Buffalo  |
|  4707 Eastwood Cres., Niagara Falls, Ont  L2E 1B4, Canada  |
|  +1-905-371-3652 (private)  -  +1-905-371-8834 (work/fax)  |
 

--------------E33F2FD5B48043922E8F4B44–

--------------DF0ACD98C6BA2D50F55587D1
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Daniel Vogel wrote:

Well, does your HW (and the driver) support it? Try running glxinfo (I think
it’s part of the Mesa demos).

You are right … the Xfree86-4.01/Mesa3.3 GLX driver doesn’t support a alpha
channel in the colorbuffer for the Voodoo3.

Here is the output of glxinfo - same as for your Voodoo5.

visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav
id dep cl sp sz l ci b ro r g b a bf th cl r g b a ns b eat----------------------------------------------------------------------
0x24 16 tc 0 16 0 r . . 5 6 5 0 0 0 0 0 0 0 0 0 0 None
0x25 16 tc 0 16 0 r y . 5 6 5 0 0 16 8 16 16 16 16 0 0 None
0x26 16 dc 0 16 0 r y . 5 6 5 0 0 16 8 16 16 16 16 0 0 None
0x27 16 dc 0 16 0 r y . 5 6 5 0 0 16 8 16 16 16 16 0 0 None


| Andreas Schiffler aschiffler at home.com |
| Senior Systems Engineer - Deskplayer Inc., Buffalo |
| 4707 Eastwood Cres., Niagara Falls, Ont L2E 1B4, Canada |
| +1-905-371-3652 (private) - +1-905-371-8834 (work/fax) |

--------------DF0ACD98C6BA2D50F55587D1
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>

Daniel Vogel wrote:
 
Well, does your HW (and the driver) support it? Try running glxinfo (I think
it's part of the Mesa demos).
You are right ... the Xfree86-4.01/Mesa3.3 GLX driver doesn't support a alpha channel in the colorbuffer for the Voodoo3.

Here is the output of glxinfo - same as for your Voodoo5.

   visual  x  bf lv rg d st colorbuffer ax dp st accumbuffer  ms  cav
 id dep cl sp sz l  ci b ro  r  g  b  a bf th cl  r  g  b  a ns b eat
----------------------------------------------------------------------
0x24 16 tc  0 16  0 r  .  .  5  6  5  0  0  0  0  0  0  0  0  0 0 None
0x25 16 tc  0 16  0 r  y  .  5  6  5  0  0 16  8 16 16 16 16  0 0 None
0x26 16 dc  0 16  0 r  y  .  5  6  5  0  0 16  8 16 16 16 16  0 0 None
0x27 16 dc  0 16  0 r  y  .  5  6  5  0  0 16  8 16 16 16 16  0 0 None
 

-- 
|  Andreas Schiffler                    aschiffler at home.com  |
|  Senior Systems Engineer    -    Deskplayer Inc., Buffalo  |
|  4707 Eastwood Cres., Niagara Falls, Ont  L2E 1B4, Canada  |
|  +1-905-371-3652 (private)  -  +1-905-371-8834 (work/fax)  |
 

--------------DF0ACD98C6BA2D50F55587D1–

Wed, 20 Dec 2000 Andreas Schiffler wrote:

What about the SDL blitting functions (in software).

Simple: Don’t do it.

Unless I’m failing to understand what you’re talking about, the problem is that
you’re not supposed to software blit, or in fact, do any 2D operations at all
on an OpenGL surface. I’m surprized that SDL seems to try to do it anyway (?),
as it’s not supposed to be possible, AFAIK…

Besides, it’s nearly always a performance problem mixing 2D and 3D
operations, and even worse, mixing 3D and CPU access to the framebuffer.

//David

…- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' ..- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -’