Thanks, but this means that SDL_SetColorKey changes more than just the
"colorkey" value in the SDL_PixelFormat struct, right?
Does it recode the information in any other way?
A related question, I get a segmentation fault in SDL_DisplayFormat. This is
related because the segmentation fault disappears if I do not set the
transparancy color. The code below have the error.
stderr:
Initializing Simple DirectMedia Layer
Done…
ColorKey returned: 0
main. Convert to display format
Fatal signal: Segmentation Fault (SDL Parachute Deployed)
code:
//
// Initialize SDL library
//
fprintf(stderr, “Initializing Simple DirectMedia Layer\n”);
//initialize systems
SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_TIMER );
//set our at exit function
atexit ( SDL_Quit ) ;
fprintf(stderr, “Done…\n”);
//
// Set 320 x 200 x 16bit
//
SDL_Surface *sp = SDL_SetVideoMode(320, 200, 16, SDL_SWSURFACE |
SDL_DOUBLEBUF | SDL_FULLSCREEN);
SDL_Surface *s = 0;
s = IMG_Load(“dir1/dir2/file.pcx”);
if ( s == NULL )
{
throw int(-1);
}
//
// Convert to display format.
//
Uint16 trans = SDL_MapRGB(SDL_GetVideoSurface() -> format, 255, 0, 255);
int res = SDL_SetColorKey(s, SDL_SRCCOLORKEY, trans);
fprintf(stderr, “ColorKey returned: %d\n”, res);
fprintf(stderr, “main. Convert to display format\n”);
SDL_Surface *s2 = SDL_DisplayFormat(s);
fprintf(stderr, “Done\n”);
if ( s2 == NULL )
throw int(-1);
SDL_FreeSurface(s);
exit(0);
/ Niklas>From: Jonathan Atkins
Reply-To: sdl at libsdl.org
To: sdl at libsdl.org
Subject: Re: [SDL] Order of Surface “Filling” and transparant color
setting.
Date: Sun, 02 Jun 2002 11:38:02 -0500
Niklas Pettersson wrote:
Hello!
I’m new to SDL so this might be a stupid question. The background is that
I didn’t get transparancy when blitting even though I had set the
transparancy colour for the source surface. My initial algorithm was like
this:
- Create an empty surface of correct size.
- Set transparancy color
- Fill surface with data from pcx file using the “putpixel” in the SDl
documentation.
Then I changed place of step 2 and 3 and viola! Then it worked (blit is
transparent). Why is this? An explanation would be helpful to avoid
misstakes in the future.
sounds like you were using colorkey, which bases it’s work on the current
image…
so if you change the image after setting a color key, the alpha channel is
not re-keyed for you,
you would have to setup the colorkey after setting the surface image up
completely.
–
-==-
Jon Atkins
http://jcatki.2y.net/
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx