Sorry to bother you

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_________________________________________________________________
F? styr p? dine billeder gratis med Windows Live Billedgalleri
www.windowslive.dk/billedgalleri

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

Hmm. I tried drawing the tempframe directly after ,filling it with the colorkey color and setting the colorkey, to the screen, and it paints a magneta color. I’m pretty sure my problem isn’t related to the image im drawing from (gense.bmp), becouse i can do that just fine. gense.bmp has a background color of (255,0,255) and if i fill tempframe with, for example (255,0,0) and draws it to the screen, then it draws the image on gense.bmp with a red background. I think im setting the colorkey correct. Setting all the mask’s to zero doesn’t work either.> Date: Sat, 22 Dec 2007 11:32:45 -0500> From: xucaen at gmail.com> To: sdl at lists.libsdl.org> Subject: Re: [SDL] Sorry to bother you> > 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> > > SDL mailing list> SDL at lists.libsdl.org> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org__________________
Saml dine online aktiviteter p? din PC med Windows Live
www.windowslive.dk/suite

Hey,

Does colorkeying definitely work with SDL_SRCALPHA?

Jonny DFrom: madsj_6@hotmail.com
To: sdl at lists.libsdl.org
Date: Sat, 22 Dec 2007 13:48:33 +0000
Subject: [SDL] Sorry to bother you

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

Kombiner det bedste fra Windows og nettet med Windows Live Hent det nu!


i?m is proud to present Cause Effect, a series about real people making a difference.
http://im.live.com/Messenger/IM/MTV/?source=text_Cause_Effect

I usually does not use it. it seems i got the tempframe to display correct on the screen. It seems if i do the following:SDL_Surface* tempframe1 = SDL_CreateRGBSurface( SDL_SWSURFACE, genseframes[frame1].w, genseframes[frame1].h, 32,0,0,0,0); SDL_SetColorKey(tempframe1, SDL_SRCCOLORKEY , SDL_MapRGB(tempframe1->format, 255, 0, 255)); SDL_Surface* tempframe =SDL_DisplayFormatAlpha( tempframe1 ); SDL_FreeSurface(tempframe1); SDL_SetAlpha(tempframe,NULL,0); SDL_FillRect(tempframe, NULL,SDL_MapRGB(tempframe->format, 255, 0, 255)); apply_surface(0,0,tempframe,screen); apply_surface(0,0,gense,tempframe,&genseframes[frame1]); temp1 = rotozoomSurface(tempframe,rotation1*(-180/b2_pi),1,0); if i put colorkey before displayformatalpha() then the colorkey isn’t being used by tempframe1/tempframe. However if i put it after, it is. However, anyway i end up with the pink rectangles around my grey sprites both ways…If i have colorkey after displayformatalpha(), apply_surface(0,0,tempframe,screen); draws nothing in the upper left corner, however putting colorkey before, it draws the pink rectangle in the upper left corner.this is the function im currently using for loading 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; }From: grimfang4@hotmail.comTo: sdl at lists.libsdl.orgDate: Sat, 22 Dec 2007 19:48:20 -0500Subject: Re: [SDL] Sorry to bother you

Hey,Does colorkeying definitely work with SDL_SRCALPHA?Jonny D

From: @mads_jorgensenTo: sdl at lists.libsdl.orgDate: Sat, 22 Dec 2007 13:48:33 +0000Subject: [SDL] Sorry to bother you

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 surfaceSDL_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.jpgThanks for your time,Mads

Kombiner det bedste fra Windows og nettet med Windows Live Hent det nu!

i?m is proud to present Cause Effect, a series about real people making a difference. Learn more


F? styr p? dine billeder gratis med Windows Live Billedgalleri
www.windowslive.dk/billedgalleri

mads j?rgensen wrote:

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;
}

What happens if you call SDL_DisplayFormat() instead of
SDL_DisplayFormatAlpha()? I think SDL_DisplayFormatAlpha() is only used
if you are using an alpha channel.

Jim