aalineRGBA problem

Hello,

I have a little bit trouble with the call ‘aalineRGBA’ from the SDL_Gfx library.
When I create a surface with a bpp of 32bit, ‘aalineRGBA’ draws only vertical and horizontal lines (ticks of a meter).
Only the start and end point of all other lines are drawn.

On a surface with 8 bpp all lines are drawn, but the color is wrong.

I have attached a short example. What’s wrong in my code? ( I’m working under SuSE LINUX 9.0. )

Thank you

Armin______________________________________________________________________
XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130

-------------- next part --------------
A non-text attachment was scrubbed…
Name: ex1.c
Type: text/x-csrc
Size: 2258 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060612/87d1f0c5/attachment.c

When the lines are not straight the antialiasing reduces the pixel
colors just a tad away from white. And then your use of nonzero
Amask in the SDL_CreateRGBSurface causes the SDL_gfx to go for
alpha blending. And without alpha channel set in your image you
get didley on the image.

I suggest you skip the alpha stuff unless you need it and use
SDL_DisplayFormat to get an image suitable for blitting.
You’re using ABGR, which on little endian machines happens to be what
the opengl wants (big endiand RGBA), but using that to blit
on screen in 2D is probably not what you’re looking for, because I’m
betting you’re display surface has something other than ABGR
(could it be ARGB?).

It’s been a while since I last played with SDL_gfx, so take all that
with some salt, but your example would seem to work ok if you set the
Amask to zero in the SDL_CreateRGBSurface call or use SDL_setAlpha(image,0,255);
to get something non-transparent on the surface.

However, I distinctly recall that there was fishy with SDL_gfx
and the way it handled the alpha channeling. Or to be more precice,
I never got it to work the way I was looking for, but it’s quite
likely I overlooked something as I was never really that
keen on getting it to work.

Maybe I’ll check back with an example …

cheers,
Tommi Kyntola

Armin Steinhoff wrote:> Hello,

I have a little bit trouble with the call ‘aalineRGBA’ from the SDL_Gfx library.
When I create a surface with a bpp of 32bit, ‘aalineRGBA’ draws only vertical and horizontal lines (ticks of a meter).
Only the start and end point of all other lines are drawn.

On a surface with 8 bpp all lines are drawn, but the color is wrong.

I have attached a short example. What’s wrong in my code? ( I’m working under SuSE LINUX 9.0. )

Thank you

Armin


XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130


#include <stdlib.h>
#include <math.h>
#include “SDL.h”
#include “SDL_image.h”
#include “SDL_gfxPrimitives.h”

void cpoint(float rad, short cx, short cy, short radius, short * px, short * py)
{
// cx, cy are the center point of the circle
// px, py are points of the circle
*px = cx + (short)((float)radius * cosf(rad));
*py = cy + (short)((float)radius * sinf(rad));
}

int draw_tick(SDL_Surface * surf, float rad, short cx, short cy, short radius, short tick_len,
Uint8 r, Uint8 g, Uint8 b, Uint8 a )
{
short spx, spy, epx, epy;

cpoint(rad, cx, cy, radius, &spx, &spy);
cpoint(rad, cx, cy, radius - tick_len, &epx, &epy);

fprintf(stdout, "spx/spy %d,%d  epx/epy: %d/%d\n", spx, spy, epx, epy);     
return(aalineRGBA(surf, spx, spy, epx, epy, r, g, b, a)); 

}

int main()
{

SDL_Surface *display;
SDL_Surface *image;
int i, done, resp;
float rad;

SDL_Rect drect;
SDL_Rect srect;
SDL_Event event;

// init video stuff
if ( SDL_Init( SDL_INIT_VIDEO) < 0 )
{
 fprintf(stderr, "SDL konnte nicht initialisiert werden:  %s\n",
   SDL_GetError());
 exit(1);
}

atexit(SDL_Quit);

// init screen
display = SDL_SetVideoMode( 1024,768, 0, SDL_SWSURFACE);
if ( display == NULL )
{
 fprintf(stderr, "SDL_SetVideoMode %s\n", SDL_GetError());
 exit(1);
}

image = SDL_CreateRGBSurface(SDL_SWSURFACE, 1024, 768, 32, 0xFF, 0xFF00, 0xFF0000, 0xFF000000);
if ( image == NULL ) {
    fprintf(stderr, "SDL_CreateRGBSurface: %s\n",SDL_GetError());
    return(NULL);
}
//source rect
srect.x = 0;
srect.y = 0;
srect.w = (image->w); 
srect.h = image->h;   

// destination rect
drect.x = 0;
drect.y = 0;
drect.w = (image->w);
drect.h = image->h;

for (i=0; i < 360; i+=10)
{
    rad = 6.28 * (float)i/360.0;
      
    resp = draw_tick(image, rad, 150, 150, 50, 10, 255, 255, 255, 255 );
    fprintf(stdout, "resp: %d\n", resp);     
      
    SDL_BlitSurface(image, &srect, display, &drect);
    
    SDL_UpdateRects(display,1,&drect);
}      

SDL_Delay(6000);

SDL_FreeSurface(image);

}



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

Tommi Kyntola <tommi.kyntola at ray.fi> schrieb am 13.06.2006 11:44:53:

When the lines are not straight the antialiasing reduces the pixel
colors just a tad away from white. And then your use of nonzero
Amask in the SDL_CreateRGBSurface causes the SDL_gfx to go for
alpha blending. And without alpha channel set in your image you
get didley on the image.

Yes … it is now working with the Amask set to zero :slight_smile:

I suggest you skip the alpha stuff unless you need it and use
SDL_DisplayFormat to get an image suitable for blitting.
You’re using ABGR, which on little endian machines happens to be what
the opengl wants (big endiand RGBA), but using that to blit
on screen in 2D is probably not what you’re looking for, because I’m
betting you’re display surface has something other than ABGR
(could it be ARGB?).

Sorry … I don’t understand fully the concept behind these RGBA masks.

It’s been a while since I last played with SDL_gfx, so take all that
with some salt, but your example would seem to work ok if you set the
Amask to zero in the SDL_CreateRGBSurface call or use SDL_setAlpha(image,0,255);
to get something non-transparent on the surface.

Thank you for your help.

Best Regards

Armin>

However, I distinctly recall that there was fishy with SDL_gfx
and the way it handled the alpha channeling. Or to be more precice,
I never got it to work the way I was looking for, but it’s quite
likely I overlooked something as I was never really that
keen on getting it to work.

Maybe I’ll check back with an example …

cheers,
Tommi Kyntola

Armin Steinhoff wrote:

Hello,

I have a little bit trouble with the call ‘aalineRGBA’ from the SDL_Gfx library.
When I create a surface with a bpp of 32bit, ‘aalineRGBA’ draws only vertical and horizontal lines (ticks of a meter).
Only the start and end point of all other lines are drawn.

On a surface with 8 bpp all lines are drawn, but the color is wrong.

I have attached a short example. What’s wrong in my code? ( I’m working under SuSE LINUX 9.0. )

Thank you

Armin


XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130


#include <stdlib.h>
#include <math.h>
#include “SDL.h”
#include “SDL_image.h”
#include “SDL_gfxPrimitives.h”

void cpoint(float rad, short cx, short cy, short radius, short * px, short * py)
{
// cx, cy are the center point of the circle
// px, py are points of the circle
*px = cx + (short)((float)radius * cosf(rad));
*py = cy + (short)((float)radius * sinf(rad));
}

int draw_tick(SDL_Surface * surf, float rad, short cx, short cy, short radius, short tick_len,
Uint8 r, Uint8 g, Uint8 b, Uint8 a )
{
short spx, spy, epx, epy;

cpoint(rad, cx, cy, radius, &spx, &spy);
cpoint(rad, cx, cy, radius - tick_len, &epx, &epy);

fprintf(stdout, "spx/spy %d,%d  epx/epy: %d/%d\n", spx, spy, epx, epy);     
return(aalineRGBA(surf, spx, spy, epx, epy, r, g, b, a)); 

}

int main()
{

SDL_Surface *display;
SDL_Surface *image;
int i, done, resp;
float rad;

SDL_Rect drect;
SDL_Rect srect;
SDL_Event event;

// init video stuff
if ( SDL_Init( SDL_INIT_VIDEO) < 0 )
{
 fprintf(stderr, "SDL konnte nicht initialisiert werden:  %s\n",
   SDL_GetError());
 exit(1);
}

atexit(SDL_Quit);

// init screen
display = SDL_SetVideoMode( 1024,768, 0, SDL_SWSURFACE);
if ( display == NULL )
{
 fprintf(stderr, "SDL_SetVideoMode %s\n", SDL_GetError());
 exit(1);
}

image = SDL_CreateRGBSurface(SDL_SWSURFACE, 1024, 768, 32, 0xFF, 0xFF00, 0xFF0000, 0xFF000000);
if ( image == NULL ) {
    fprintf(stderr, "SDL_CreateRGBSurface: %s\n",SDL_GetError());
    return(NULL);
}
//source rect
srect.x = 0;
srect.y = 0;
srect.w = (image->w); 
srect.h = image->h;   

// destination rect
drect.x = 0;
drect.y = 0;
drect.w = (image->w);
drect.h = image->h;

for (i=0; i < 360; i+=10)
{
    rad = 6.28 * (float)i/360.0;
      
    resp = draw_tick(image, rad, 150, 150, 50, 10, 255, 255, 255, 255 );
    fprintf(stdout, "resp: %d\n", resp);     
      
    SDL_BlitSurface(image, &srect, display, &drect);
    
    SDL_UpdateRects(display,1,&drect);
}      

SDL_Delay(6000);

SDL_FreeSurface(image);

}



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


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


Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
http://smartsurfer.web.de/?mc=100071&distributionid=000000000071

I suggest you skip the alpha stuff unless you need it and use
SDL_DisplayFormat to get an image suitable for blitting.
You’re using ABGR, which on little endian machines happens to be what
the opengl wants (big endiand RGBA), but using that to blit
on screen in 2D is probably not what you’re looking for, because I’m
betting you’re display surface has something other than ABGR
(could it be ARGB?).

Sorry … I don’t understand fully the concept behind these RGBA masks.

the RGBA mask defines where in a single pixelvalue the different color
channels get stored. this means, for example, if you are in a 32 bit mode,
one pixel is stored in a 32 bit integer and each color of RGBA use 8 bits.

pixel = 00101001 00101111 10101011 00011100

if the masks are set as follwing:

amask = 0xff000000
rmask = 0x000000ff
gmask = 0x0000ff00
bmask = 0x00ff0000

then the MSB holds the alpha value of the pixel and the LSB the red
colour channel. you get the idea?

hope this helps …
clemens

“clemens kirchgatterer” schrieb am 13.06.2006 13:41:16:

I suggest you skip the alpha stuff unless you need it and use
SDL_DisplayFormat to get an image suitable for blitting.
You’re using ABGR, which on little endian machines happens to be what
the opengl wants (big endiand RGBA), but using that to blit
on screen in 2D is probably not what you’re looking for, because I’m
betting you’re display surface has something other than ABGR
(could it be ARGB?).

Sorry … I don’t understand fully the concept behind these RGBA masks.

the RGBA mask defines where in a single pixelvalue the different color
channels get stored. this means, for example, if you are in a 32 bit mode,
one pixel is stored in a 32 bit integer and each color of RGBA use 8 bits.

pixel = 00101001 00101111 10101011 00011100

if the masks are set as follwing:

amask = 0xff000000
rmask = 0x000000ff
gmask = 0x0000ff00
bmask = 0x00ff0000

then the MSB holds the alpha value of the pixel and the LSB the red
colour channel. you get the idea?

Yes … but does it mean I can define the pixel format in that way for my individual surfaces ?
What happens if I use mask values different from 0xFF?

Thanks

–Armin__________________________________________________________________________
Erweitern Sie FreeMail zu einem noch leistungsst?rkeren E-Mail-Postfach!
Mehr Infos unter http://freemail.web.de/home/landingpad/?mc=021131

Armin Steinhoff wrote:

“clemens kirchgatterer” schrieb am 13.06.2006 13:41:16:

I suggest you skip the alpha stuff unless you need it and use
SDL_DisplayFormat to get an image suitable for blitting.
You’re using ABGR, which on little endian machines happens to be what
the opengl wants (big endiand RGBA), but using that to blit
on screen in 2D is probably not what you’re looking for, because I’m
betting you’re display surface has something other than ABGR
(could it be ARGB?).
Sorry … I don’t understand fully the concept behind these RGBA masks.
the RGBA mask defines where in a single pixelvalue the different color
channels get stored. this means, for example, if you are in a 32 bit mode,
one pixel is stored in a 32 bit integer and each color of RGBA use 8 bits.

pixel = 00101001 00101111 10101011 00011100

if the masks are set as follwing:

amask = 0xff000000
rmask = 0x000000ff
gmask = 0x0000ff00
bmask = 0x00ff0000

then the MSB holds the alpha value of the pixel and the LSB the red
colour channel. you get the idea?

Yes … but does it mean I can define the pixel format in that way for my individual surfaces ?

I stand corrected, but my understanding is that yes. Those masks, and
those alone once bpp has been defined, define how SDL and others (like
SDL_gfx) use the per pixel bits when they draw onto that surface aswell
as when they blit from that surface.

For example giving correct bitmasks and 32 bpp is all that it takes
for a surface to be compatible with opengl.

(granted there are things like SRCALPHA and other flags that also have
effect here, but basically that’s how it goes)

What happens if I use mask values different from 0xFF?

Hmmm, someone with more insight on this might shed some more
light on this, but my guess is that most sw assume that the
bits in each mask are at least consecutive. Without that
assumption it’s a tad more difficult to calculate the range
of each color.

In any case, wither it’s supported or not to use masks like
0x00aaaa00, 0x55550000, 0xaa0000aa, 0x00005555, or not, I’d
still call such masks “asking for it”.

cheers,
Tommi Kyntola

Tommi Kyntola <tommi.kyntola at ray.fi> schrieb am 14.06.2006 10:28:59:

Armin Steinhoff wrote:

“clemens kirchgatterer” schrieb am 13.06.2006 13:41:16:
[ clip …]

then the MSB holds the alpha value of the pixel and the LSB the red
colour channel. you get the idea?

Yes … but does it mean I can define the pixel format in that way for my individual surfaces ?

I stand corrected, but my understanding is that yes. Those masks, and
those alone once bpp has been defined, define how SDL and others (like
SDL_gfx) use the per pixel bits when they draw onto that surface aswell
as when they blit from that surface.

The example ‘testbitmap.c’ is using mask values which are plain zero (LoadXBM)
That’s confusing …

For example giving correct bitmasks and 32 bpp is all that it takes
for a surface to be compatible with opengl.

OK

(granted there are things like SRCALPHA and other flags that also have
effect here, but basically that’s how it goes)

What happens if I use mask values different from 0xFF?

Hmmm, someone with more insight on this might shed some more
light on this, but my guess is that most sw assume that the
bits in each mask are at least consecutive. Without that
assumption it’s a tad more difficult to calculate the range
of each color.

In any case, wither it’s supported or not to use masks like
0x00aaaa00, 0x55550000, 0xaa0000aa, 0x00005555, or not, I’d
still call such masks “asking for it”.

Seems to be related to R-, B-, G- nd Aloss ?

Sorry for these dumb questions again :slight_smile:

Thanks

–Armin______________________________________________________________
Verschicken Sie romantische, coole und witzige Bilder per SMS!
Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193

Armin Steinhoff wrote:

I stand corrected, but my understanding is that yes. Those masks,
and those alone once bpp has been defined, define how SDL and
others (like SDL_gfx) use the per pixel bits when they draw onto
that surface aswell as when they blit from that surface.

The example ‘testbitmap.c’ is using mask values which are plain zero
(LoadXBM) That’s confusing …

that is for letting SDL deside which pixelformat to use. if you do not
need to know the exact pixel data layout, it is best to let SDL pick
the best fitting one.

clemens

Clemens Kirchgatterer <clemens at 1541.org> schrieb am 15.06.2006 11:29:54:

Armin Steinhoff wrote:

I stand corrected, but my understanding is that yes. Those masks,
and those alone once bpp has been defined, define how SDL and
others (like SDL_gfx) use the per pixel bits when they draw onto
that surface aswell as when they blit from that surface.

The example ‘testbitmap.c’ is using mask values which are plain zero
(LoadXBM) That’s confusing …

that is for letting SDL deside which pixelformat to use. if you do not
need to know the exact pixel data layout, it is best to let SDL pick
the best fitting one.

After looking into the sources and the structure of the format of the pixel, now I believe to understand the semantic of these masks :slight_smile:
Thank’s all for responding to my questions.

Best Regards

–Armin>

clemens


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


Verschicken Sie romantische, coole und witzige Bilder per SMS!
Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193