Problem with transparency SDL / OpenGL

hello,

i am writing a 2d game and i need your help :slight_smile:
i use C, SDL, SDL_image and openGL to render 2D with 3D acceleration

i discover a library : OSL which implements all i need for using OpenGL
but i have a problem : the colorkey, used to render transparency doesn’t
work

i use PNG and transparency works with the SDL standard primitives, namely :

…
rwop=SDL_RWFromFile(“romdisk_pc/divers/fantome.png”, “rb”);
Fantome=IMG_LoadPNG_RW(rwop);
SDL_SetColorKey(Fantome, aff , SDL_MapRGB(Fantome->format,0,0,0));
…
SDL_BlitSurface(Fantome, NULL, MainScreen, &dest);

this works well

Now, with OSL, the transparency doesn’t work with the same PNG :
…
Fantome=OSL_LoadImagePNG(“romdisk/divers/fantome.png”, 1,0,0,0);
…
OSL_2dBlitS(Fantome, x, y,w,h);

with this code, the transparent parts of the fantome appears black

Here is the OSL functions i modified to implement PNG files :

typedef struct {
unsigned texture;
int w,h;
int colorkey;
SDL_Surface *image;
}OSL_Image;

OSL_Image OSL_LoadImagePNG(const char *filename, int withcolorkey, int r,
int g, int b)
{
SDL_Surface *bitmap, *conv;
unsigned texture;
OSL_Image image;
int format;
SDL_RWops *rwop;

rwop=SDL_RWFromFile(filename, "rb");
bitmap = IMG_LoadPNG_RW(rwop);
if (!bitmap) {
	fprintf(stderr, "%s: n'existe pas\n", filename);
	exit(1);
}
image.colorkey=withcolorkey;

if (withcolorkey) {
	Uint32 color = SDL_MapRGB(bitmap->format, (Uint8)r, (Uint8)g, (Uint8)b);
	SDL_SetColorKey(bitmap, SDL_SRCCOLORKEY, color);
}

image.w=bitmap->w;
image.h=bitmap->h;

/* Konvertiere ins 32-Bit RGBA-Format /
conv = SDL_CreateRGBSurface(SDL_SWSURFACE, bitmap->w, bitmap->h, 32,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
#else
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
#endif
SDL_BlitSurface(bitmap, 0, conv, 0);
/
Erstelle eine OpenGL-Textur */
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch /
conv->format->BytesPerPixel);

if (withcolorkey)
	format = 4;
else

	format = 3;

glTexImage2D(GL_TEXTURE_2D, 0, format, conv->w, conv->h, 0, GL_RGBA,
	GL_UNSIGNED_BYTE, conv->pixels);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);

/* Gib die verwendeten Surfaces und Speicherplatz frei */
SDL_FreeSurface(bitmap);
image.image=conv;
conv=NULL;
image.texture=texture;
return image;
}

void OSL_2dBlitS(OSL_Image image, int x, int y,int w, int h)
{

GL_TexEnable(1);
GL_Bind(image.texture);
glBegin(GL_QUADS);
    glTexCoord2f(0, 0);    glVertex2i(x, y);
    glTexCoord2f(1, 0);    glVertex2i(x+w, y);
    glTexCoord2f(1, 1);    glVertex2i(x+w, y+h);
    glTexCoord2f(0, 1);    glVertex2i(x, y+h);
glEnd();
GL_TexEnable(0);

}

can someone help me ?_________________________________________________________________
T?l?chargez gratuitement MSN Messenger ! http://www.msn.fr/msger/default.asp