Sign in to follow this  
timsoft

change in behaviour of srccolorkey in new sdl

Recommended Posts

timsoft    122
I have just updated my sdl library from 1.2.6/1.2.8 to 1.2.10/11 and it has broken a case of using colorkey in my program with a new surface. using SDL_SetColorKey works fine with images loaded with SDL_LoadBMP but the problem occurs with a surface created. minimapsurf=SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_SRCCOLORKEY|SDL_RLEACCEL,100,100,screendepth,Frmask,Fgmask,Fbmask,Famask); i=SDL_SetColorKey(minimapsurf,SDL_SRCCOLORKEY|SDL_RLEACCEL,SDL_MapRGB(minimapsurf->format,0,0,0)); I draw to the surface by clearing it with void calcminimap(SDL_Surface *minmap) { /* this calculates the minimap and writes it to the minimap surface */ Uint32 color; color = SDL_MapRGB (minmap->format, 0, 0, 0); SDL_FillRect (minmap, NULL, color); /*.... and then draw a minimap in a diamond shape on the surface using mulitple SDL_FillRect calls. ....*/ } then it drawn to the screen in another function with the minimapsurf passed to it. void showminimap(SDL_Surface *minmap) { /*the destrect definition is next. omitted for brevity */ SDL_BlitSurface(minmap,NULL,SDL_GetVideoSurface(),&destrect); } This code used to work fine, with the minimap shown as a diamond in the appropriate part of the screen. now it behaves incorrectly in two ways. first, I should say that the actual screen depth is 16 bit. if the screendepth variable used in creating the minimapsurf is set to 16 nothing appears to be put on the screen at all. If screendepth variable is set to 32, then the minimap is put on the screen, but I get a rectangle, not a diamond - ie the srccolorkey is being ignored. Has anyone come accross this before and got any ideas ? thanks.

Share this post


Link to post
Share on other sites
timsoft    122
fixed the problem. regardless of weither the color depth was 16 or 32 alphablending needed to be turned off explicitly. so after the SDL_CreateRGBSurface line
but before the SD_SetColorKey line this line was needed
SDL_SetAlpha(minimapsurf,0,0);

Why it should be needed for a 16 bit surface or one created RGB - not RGBA is beyond me - looks like a bug in SDL, but this fixes it. - now to try this fix all the other places new surfaces didn't work as expected......

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this