Two little patches

Hi,

Compiling SDL with a recent gcc (gcc 3.3.1, 3.3 doesn’t have this
behaviour) gives some nasty warnings :

SDL_blit_A.c: In function `BlitRGBtoRGBSurfaceAlpha128MMX’:
SDL_blit_A.c:223: warning: integer constant is too large for “long” type
SDL_blit_A.c:225: warning: integer constant is too large for “long” type
SDL_blit_A.c:227: warning: integer constant is too large for “long” type
[…]

The first attached patch (longlongfix.patch) tells gcc to really treat
those constants as unsigned long long and not long.

The second patch (nasinclude.patch) fixes an include problem I had while
compiling nas audio : when the <audio/audiolib.h> file lies in
/usr/X11R6/include, a -I/usr/X11R6/include option is needed or the file
isn’t found.

Stephane

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: longlongfix.patch
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030906/a9ace629/attachment.asc
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: nasinclude.patch
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030906/a9ace629/attachment.txt

I’m porting my 2D engine to OpenGL, learning it from scratch. I succeeded
to draw the sprites, but I can’t draw them with a colorkey correctly.
Using glBlendFunc(GL_SRC_ALPHA, GL_ONE) I can draw an sprite with a
black colorkey, but it happens that every other color blends with other
sprites and scenery (it is translucent). Is there a way to do it as a true
colorkey, ie, only the colorkey is omitted, and all other colors are drawed
with no translucency? Is there an specific color to use as the colorkey?

Paulo

I’m porting my 2D engine to OpenGL, learning it from scratch. I
succeeded to draw the sprites, but I can’t draw them with a
colorkey correctly. Using glBlendFunc(GL_SRC_ALPHA, GL_ONE) I
can draw an sprite with a black colorkey, but it happens that every
other color blends with other sprites and scenery (it is
translucent).

Actually, that’s additive blending you’re doing. :slight_smile: (Great for fire
and light effects.) It adds the “sprite” pixels to the background -
and that explains why black means “no effect”; adding 0 has no
effect.

Is there a way to do it as a true colorkey, ie, only
the colorkey is omitted, and all other colors are drawed with no
translucency? Is there an specific color to use as the colorkey?

I don’t know if OpenGL supports this without using some extension -
and you can’t rely on extensions as the only solution for something
like this…

What I do in glSDL is simply convert colorkeyed images to RGBA format;
that is the colorkeying is done in the conversion process, before it
gets to OpenGL. Then I just use normal alpha blending:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Sunday 07 September 2003 09.03, Paulo V W Radtke wrote:

BTW; forgot to say that since your texture doesn’t have an alpha
channel (I assume), all pixels are assumed to be opaque, and only
alpha modulation affects the blending. Unless you actually want to do
additive blending with modulation, you could just use this:

glBendFunc(GL_ONE, GL_ONE);

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Sunday 07 September 2003 11.48, David Olofson wrote:

On Sunday 07 September 2003 09.03, Paulo V W Radtke wrote:

I’m porting my 2D engine to OpenGL, learning it from scratch. I
succeeded to draw the sprites, but I can’t draw them with a
colorkey correctly. Using glBlendFunc(GL_SRC_ALPHA, GL_ONE) I
can draw an sprite with a black colorkey, but it happens that
every other color blends with other sprites and scenery (it is
translucent).

Actually, that’s additive blending you’re doing. :slight_smile: (Great for
fire and light effects.) It adds the “sprite” pixels to the
background - and that explains why black means “no effect”; adding
0 has no effect.

I don’t know if OpenGL supports this without using some extension -
and you can’t rely on extensions as the only solution for something
like this…

Color keying is not supported at all in any GL extensions I know (too many
issues with various stuff like, for example, filtering).

What I do in glSDL is simply convert colorkeyed images to RGBA format;
that is the colorkeying is done in the conversion process, before it
gets to OpenGL. Then I just use normal alpha blending:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Or one could use the Alpha test to do this. I have no idea which is faster
though :slight_smile:

                 LionelOn Sun, Sep 07, 2003 at 11:48:16AM +0200, David Olofson wrote:


Lionel Ulmer - http://www.bbrox.org/

You can use the alpha test, as for billboards.
Look at the documentation on functions:
glEnable(GL_ALPHA_TEST)
glAlphaFunc(GL_GREATER, 0.5) (for example)
glDisable(GL_ALPHA_TEST)

With these parameters for glAlphaFunc, only fragments with alpha > 0.5 will
be accepted, so you can keep your normal colors with an alpha value of 1,
and 0 for the alpha of your colorkey, so that it gets rejected.> ----- Original Message -----

From: "Paulo V W Radtke"
To:
Sent: Sunday, September 07, 2003 9:03 AM
Subject: [SDL] Colorkey 2D blitting with OpenGL

I’m porting my 2D engine to OpenGL, learning it from scratch. I succeeded
to draw the sprites, but I can’t draw them with a colorkey correctly.
Using glBlendFunc(GL_SRC_ALPHA, GL_ONE) I can draw an sprite with a
black colorkey, but it happens that every other color blends with other
sprites and scenery (it is translucent). Is there a way to do it as a true
colorkey, ie, only the colorkey is omitted, and all other colors are
drawed
with no translucency? Is there an specific color to use as the colorkey?

Paulo


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I don’t know if OpenGL supports this without using some extension

  • and you can’t rely on extensions as the only solution for
    something like this…

Color keying is not supported at all in any GL extensions I know
(too many issues with various stuff like, for example, filtering).

I heard something about 3dfx, but that’s about it. I can see why no
one would bother implementing it, if there is alpha blending anyway.

What I do in glSDL is simply convert colorkeyed images to RGBA
format; that is the colorkeying is done in the conversion
process, before it gets to OpenGL. Then I just use normal alpha
blending:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Or one could use the Alpha test to do this. I have no idea which is
faster though :slight_smile:

I guess it depends on the hardware. If the alpha test is carefully
implemented, it could be faster - but OTOH, hardware can optimize
the 0.0 and 1.0 alpha cases as well, and then it would only matter if
the alpha channel isn’t “clean”…

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Sunday 07 September 2003 12.00, Lionel Ulmer wrote:

On Sun, Sep 07, 2003 at 11:48:16AM +0200, David Olofson wrote:

What I do in glSDL is simply convert colorkeyed images to RGBA format;
that is the colorkeying is done in the conversion process, before it
gets to OpenGL. Then I just use normal alpha blending:

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     Ok, that means I can use SDL_SetColorKey to set the colorkey on a 

surface, convert it to RGBA, use the afore mentioned blending mode and
that’s it? BTW, I’m swapping bytes directly in the image to “convert” it to
RGBA, is there another way to do it (ie, one that doesn’t look like a hack)?

     Paulo

alpha modulation affects the blending. Unless you actually want to do
additive blending with modulation, you could just use this:

    glBendFunc(GL_ONE, GL_ONE);
     No, I'm reallye looking for a colorkey blitting :). Sure, the idea 

to use this for explosions and other cool effects is interesting ^_-.

     Paulo

What I do in glSDL is simply convert colorkeyed images to RGBA
format; that is the colorkeying is done in the conversion
process, before it gets to OpenGL. Then I just use normal alpha
blending:

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     Ok, that means I can use SDL_SetColorKey to set the

colorkey on a surface, convert it to RGBA, use the afore mentioned
blending mode and that’s it?

Yep. (IIRC, that’s not what I do in Kobo Deluxe, but that’s just
because I wanted a “colorkey fuzziness” control.)

BTW, I’m swapping bytes directly in
the image to “convert” it to RGBA, is there another way to do it
(ie, one that doesn’t look like a hack)?

If you’re creating a destination surface for a conversion blit, why
not just create it in the correct format right away? :slight_smile:

However, note that this is endian sensitive!

From glSDL:

—8<------------------------------------------------------------
/* Create a surface of the prefered OpenGL RGBA texture format */
static SDL_Surface *_CreateRGBASurface(int w, int h)
{
SDL_Surface *s;
Uint32 rmask, gmask, bmask, amask;
int bits = 32;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
s = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
bits, rmask, gmask, bmask, amask);
if(s)
GLSDL_FIX_SURFACE(s);

glSDL_AddTexInfo(s);
return s;

}
------------------------------------------------------------>8—

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Sunday 07 September 2003 17.28, Paulo V W Radtke wrote:

Yeah, that’s what I meant. Once you’re doing OpenGL, why not have some
fun? :slight_smile:

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Sunday 07 September 2003 17.46, Paulo V W Radtke wrote:

alpha modulation affects the blending. Unless you actually want to
do additive blending with modulation, you could just use this:

    glBendFunc(GL_ONE, GL_ONE);
     No, I'm reallye looking for a colorkey blitting :). Sure,

the idea to use this for explosions and other cool effects is
interesting ^_-.

     Ok, that means I can use SDL_SetColorKey to set the

colorkey on a surface, convert it to RGBA, use the afore mentioned
blending mode and that’s it?

Yep. (IIRC, that’s not what I do in Kobo Deluxe, but that’s just
because I wanted a “colorkey fuzziness” control.)

     I got it working yesterday, but it took me longer than I expected. 

SDL loads BMPs as 24bits BRG surfaces, so until I found that out, I had
lost half the day. After that, it was working smoothly :). And it was
REALLY fast ^_-.

     Paulo