Color key and transparency problem

Hi,

I want to use colorkey and transparency (separatetly), but both of them
are not working.
Here the code that doesn’t work.

In (*1) is where I tried to set the colorkey.
In (*2) is where I tried to set the transparency.

Can somebody tell me what is wrong ?
Thank, Marce.

/***************** Init Part ***************************************/
//SDL Inits
SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_TIMER );
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

//Create the video and take a pointer to the video surface

SDL_Surface *gSurface;
gSurface = SDL_SetVideoMode(640, 480, 16, SDL_ANYFORMAT | SDL_HWSURFACE
| SDL_OPENGL |

SDL_OPENGLBLIT);

//Load a truecolor bmp with (255,255,255) as the color I want not to be
seen.

SDL_Surface *imagebmp;
imagebmp = SDL_LoadBMP(“figure.bmp”);
bmp = SDL_DisplayFormat(imagebmp);
SDL_FreeSurface(imagebmp);

//Create a small surface

small = SDL_CreateRGBSurface (SDL_HWSURFACE | SDL_SRCALPHA | SDL_SRCCOLORKEY,
100, 50,
gSurface->format->BitsPerPixel, gSurface->format->Rmask,
gSurface->format->Gmask, gSurface->format->Bmask, gSurface->format->Amask);

//(*1)
//Try to ser ColorKey of the bmp surface

SDL_SetAlpha(bmp, SDL_SRCALPHA, 255);
SDL_SetColorKey(bmp, SDL_SRCCOLORKEY, SDL_MapRGB(bmp->format, 255, 255,
255));

//Compose the bmp surface into the small surface

SDL_Rect dstrect;
dstrect.x = 0;
dstrect.y = 0;
dstrect.w = bmp->w;
dstrect.h = bmp->h;
SDL_BlitSurface(bmp, NULL, small, &dstrect);
SDL_UpdateRects(small, 1, &dstrect);

init_GL();

//(*2)
//Try to set the transparency to the small surface
SDL_SetAlpha(small, SDL_SRCALPHA, 128);

/********************* Draw cicle part ***********************************/

//Clear and draw opengl
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawOpenGLScene();

//draw the small surface on the video surface using SDL directives.
dstrect.x = 50;
dstrect.y = 50;
dstrect.w = small->w;	
dstrect.h = small->h;
SDL_BlitSurface(small, NULL, gSurface, &dstrect);
SDL_UpdateRects(gSurface, 1, &dstrect);

/******************************** End ***********************************/--------
E-mail y acceso a Internet UltraVeloz totalmente GRATIS en Buenos Aires,
Rosario, Cordoba, Mendoza, La Plata y Pilar
http://www.Argentina.com
Nro. de acceso 5078-5000 Usuario: Argentina Password: Argentina

Hi, It’s me again.
I realize that the tranparency does work but from one SDL_Surface to another
SDL_Surface.
I want to make the SDL_Surface transparent to the OpenGL scene just drawn.
Any clue to do that ?

By the way, colorkey is still not working.
Any help ?

:)>-- Mensaje Original –

From: nievas_marcela at Argentina.com
To: sdl at libsdl.org
Subject: [SDL] color key and transparency problem
Reply-To: sdl at libsdl.org
Date: Mon, 9 Feb 2004 11:44:20 -0300

Hi,

I want to use colorkey and transparency (separatetly), but both of them
are not working.
Here the code that doesn’t work.

In (*1) is where I tried to set the colorkey.
In (*2) is where I tried to set the transparency.

Can somebody tell me what is wrong ?
Thank, Marce.

/***************** Init Part ***************************************/
//SDL Inits
SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_TIMER );
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

//Create the video and take a pointer to the video surface

SDL_Surface *gSurface;
gSurface = SDL_SetVideoMode(640, 480, 16, SDL_ANYFORMAT | SDL_HWSURFACE
| SDL_OPENGL |

SDL_OPENGLBLIT);

//Load a truecolor bmp with (255,255,255) as the color I want not to be
seen.

SDL_Surface *imagebmp;
imagebmp = SDL_LoadBMP(“figure.bmp”);
bmp = SDL_DisplayFormat(imagebmp);
SDL_FreeSurface(imagebmp);

//Create a small surface

small = SDL_CreateRGBSurface (SDL_HWSURFACE | SDL_SRCALPHA | SDL_SRCCOLORKEY,
100, 50,
gSurface->format->BitsPerPixel, gSurface->format->Rmask,
gSurface->format->Gmask, gSurface->format->Bmask, gSurface->format->Amask);

//(*1)
//Try to ser ColorKey of the bmp surface

SDL_SetAlpha(bmp, SDL_SRCALPHA, 255);
SDL_SetColorKey(bmp, SDL_SRCCOLORKEY, SDL_MapRGB(bmp->format, 255, 255,
255));

//Compose the bmp surface into the small surface

SDL_Rect dstrect;
dstrect.x = 0;
dstrect.y = 0;
dstrect.w = bmp->w;
dstrect.h = bmp->h;
SDL_BlitSurface(bmp, NULL, small, &dstrect);
SDL_UpdateRects(small, 1, &dstrect);

init_GL();

//(*2)
//Try to set the transparency to the small surface
SDL_SetAlpha(small, SDL_SRCALPHA, 128);

/********************* Draw cicle part ***********************************/

//Clear and draw opengl
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawOpenGLScene();

//draw the small surface on the video surface using SDL directives.
dstrect.x = 50;
dstrect.y = 50;
dstrect.w = small->w;
dstrect.h = small->h;
SDL_BlitSurface(small, NULL, gSurface, &dstrect);
SDL_UpdateRects(gSurface, 1, &dstrect);

/******************************** End ***********************************/


E-mail y acceso a Internet UltraVeloz totalmente GRATIS en Buenos Aires,
Rosario, Cordoba, Mendoza, La Plata y Pilar
http://www.Argentina.com
Nro. de acceso 5078-5000 Usuario: Argentina Password: Argentina


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


E-mail y acceso a Internet UltraVeloz totalmente GRATIS en Buenos Aires,
Rosario, Cordoba, Mendoza, La Plata y Pilar
http://www.Argentina.com
Nro. de acceso 5078-5000 Usuario: Argentina Password: Argentina