[SDL] Sorry to bother you

James Barrett xucaen at gmail.com
Sat Dec 22 08:32:45 PST 2007


Hi, I'm not completely sure, but could it be the mask values you pass in
to SDL_CreateRGBSurface()? I set all 4 mask values to zero. I also don't
use the colorkey. Instead, I make my images with transparency using The
Gimp software so it may work differently for you. Does your image
already have a background color? Maybe it is slightly different than the
colorkey you set?

jim



mads jørgensen wrote:
> Hello. I have a very stupid problem. I have tried for several days to
> get it working, but i can't seem to get it right.
> I am actually trying to do the simple thing to make a empty surface,
> and then draw another image into it. My code is the following (c++):
>
> //code for drawing from one surface to another:
>
> void apply_surface( float x, float y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
> 	{
> 		//Holds offsets
> 		SDL_Rect offset;
> 	    
> 		//Get offsets
> 		offset.x = x;
> 		offset.y = y;
> 		
> 		   
> 		//Blit
> 		SDL_BlitSurface( source, clip, destination, &offset );
> 	}
>
> //code for loading an image from memory:
> SDL_Surface *load_image( string filename ) 
> 	{
> 		//The image that's loaded
> 		SDL_Surface* loadedImage = NULL;
> 	    
> 		//The optimized surface that will be used
> 		SDL_Surface* optimizedImage = NULL;
> 	    
> 		//Load the image
> 		loadedImage = IMG_Load( filename.c_str() );
> 	    
> 		//If the image loaded
> 		if( loadedImage != NULL )			
> 		{
> 		  SDL_SetColorKey( loadedImage, SDL_SRCCOLORKEY, SDL_MapRGB( loadedImage->format, 255, 0, 255 ) );
> 			//Create an optimized surface
> 			optimizedImage = SDL_DisplayFormatAlpha( loadedImage );
> 	        
> 			//Free the old surface
> 			SDL_FreeSurface( loadedImage );
> 	        
> 	       
> 	        
> 		}
> 		//Return the optimized surface
> 		return optimizedImage;
> 	}
>
> //the code for making the empty surface(tempframe) and applying the appropriate sprite from the sprite sheet
> // loaded from memory:
> //create an empty surface
> SDL_Surface* tempframe = SDL_CreateRGBSurface( SDL_SWSURFACE|SDL_SRCALPHA,
>                                                genseframes[frame1].w,
>                                               genseframes[frame1].h,
>                                                32,
>                                                gense->format->Rmask,
>                                             gense->format->Gmask,
>                                 gense->format->Bmask,
>                              gense->format->Amask);
> //fill it with the colorkey color       
> SDL_FillRect(tempframe, NULL,SDL_MapRGB(tempframe->format, 255, 0, 255));
>
>
>
> //assaign the colorkey                                
> SDL_SetColorKey(tempframe, SDL_SRCCOLORKEY , SDL_MapRGB(tempframe->format, 255, 0, 255))   ;
> //draw the current frame from the gense spritesheet  
> apply_surface(0,0,gense,tempframe,&genseframes[frame1]);
>
>   
> /////////////////////////////
> the result is the following (look at the sprite on the left with the
> pink rectangle around it, it is supposed to be completely transparent)
> http://img297.imageshack.us/my.php?image=notdrawingqv8.jpg
>
> Thanks for your time,
> Mads



More information about the SDL mailing list