Opengl - blit with SDLColourKey

Hello,

I’m trying to blit on Opengl Views a surface with a SDLColourKey set,
alas, it renders the SDLColourKey as what is beneath the OpenGl view,
but works fine when blit is made upon an SDL Surface.

This is my init code:

[…]
if ( SDL_Init( SDL_INIT_VIDEO ) > -1 )
{
printf(“SDL_Init fails \n”);
}

/* Fetch the video info */
videoInfo = SDL_GetVideoInfo( );

if ( !videoInfo )

{
fprintf( stderr, “Video query failed: %s\n”,
SDL_GetError( ) );
}

SDL_Init(SDL_INIT_VIDEO);
printf(“SDL_Init \n”);
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 );
if ( SDL_SetVideoMode( 800, 400, 16, SDL_OPENGLBLIT | SDL_RESIZABLE ) ==
NULL ) {
fprintf(stderr, “Couldn’t set 800x400 GL mode: %s\n”, SDL_GetError());
SDL_Quit();
exit(1);
}
/* the flags to pass to SDL_SetVideoMode /
videoFlags = SDL_OPENGLBLIT; /
Enable OpenGL in SDL /
videoFlags |= SDL_GL_DOUBLEBUFFER; /
Enable double buffering /
videoFlags |= SDL_HWPALETTE; /
Store the palette in hardware /
videoFlags |= SDL_RESIZABLE; /
Enable window resizing */

/* This checks to see if surfaces can be stored in memory */
if ( videoInfo->hw_available )

videoFlags |= SDL_HWSURFACE;
else
videoFlags |= SDL_SWSURFACE;

/* This checks if hardware blits can be done */
if ( videoInfo->blit_hw )

videoFlags |= SDL_HWACCEL;

/* Sets up OpenGL double buffering
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );*/

/* get a SDL surface */
if (SDL_SetVideoMode( WIDTH, HEIGHT, 16,
videoFlags )== NULL ) {

fprintf(stderr, “Couldn’t set %dx%d in GL mode: %s\n”,
WIDTH,HEIGHT,SDL_GetError());
SDL_Quit();
exit(1);
[…]

Jocelyn.

You can fake the color-key in OpenGL by using a alphatest of 0.

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_NOTEQUAL,0.0f);

What it really does is remove any pixel that is completely transparant.

I think alpha blending needs to be on for this to work, I haven’t exactly
checked, but in case it doesn’t work, this is what you need:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Bille2
Sent: October 16, 2001 1:34 PM
To: sdl at libsdl.org
Subject: [SDL] Opengl - blit with SDLColourKey

Hello,

I’m trying to blit on Opengl Views a surface with a SDLColourKey set,
alas, it renders the SDLColourKey as what is beneath the OpenGl view,
but works fine when blit is made upon an SDL Surface.

This is my init code:

[…]
if ( SDL_Init( SDL_INIT_VIDEO ) > -1 )
{
printf(“SDL_Init fails \n”);
}

/* Fetch the video info */
videoInfo = SDL_GetVideoInfo( );

if ( !videoInfo )

{
fprintf( stderr, “Video query failed: %s\n”,
SDL_GetError( ) );
}

SDL_Init(SDL_INIT_VIDEO);
printf(“SDL_Init \n”);
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 );
if ( SDL_SetVideoMode( 800, 400, 16, SDL_OPENGLBLIT | SDL_RESIZABLE ) ==
NULL ) {
fprintf(stderr, “Couldn’t set 800x400 GL mode: %s\n”, SDL_GetError());
SDL_Quit();
exit(1);
}
/* the flags to pass to SDL_SetVideoMode /
videoFlags = SDL_OPENGLBLIT; /
Enable OpenGL in SDL /
videoFlags |= SDL_GL_DOUBLEBUFFER; /
Enable double buffering /
videoFlags |= SDL_HWPALETTE; /
Store the palette in hardware /
videoFlags |= SDL_RESIZABLE; /
Enable window resizing */

/* This checks to see if surfaces can be stored in memory */
if ( videoInfo->hw_available )

videoFlags |= SDL_HWSURFACE;
else
videoFlags |= SDL_SWSURFACE;

/* This checks if hardware blits can be done */
if ( videoInfo->blit_hw )

videoFlags |= SDL_HWACCEL;

/* Sets up OpenGL double buffering
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );*/

/* get a SDL surface */
if (SDL_SetVideoMode( WIDTH, HEIGHT, 16,
videoFlags )== NULL ) {

fprintf(stderr, “Couldn’t set %dx%d in GL mode: %s\n”,
WIDTH,HEIGHT,SDL_GetError());
SDL_Quit();
exit(1);
[…]

Jocelyn.


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

“Bille2” wrote:

I’m trying to blit on Opengl Views a surface with a SDLColourKey set,
alas, it renders the SDLColourKey as what is beneath the OpenGl view,
but works fine when blit is made upon an SDL Surface.

[…]

videoFlags = SDL_OPENGLBLIT; /* Enable OpenGL in SDL */

I suggest you avoid SDL_OPENGLBLIT — it doesn’t really do anything
you can’t do yourself in a portable way using SDL and OpenGL. It is slow
and rather restricted in what you can do.

If you use SDL_OPENGL you can’t blit SDL surfaces directly to the screen,
but you can still use SDL calls for manipulating software surfaces which
can be handy for preparing images for openGL