Hi,
I’m having problems with colorkeyed opengl textures. I can load and display the
textures without trouble but they look strange. See picture below.
http://www.student.lu.se/~nbi99mla/sdl-opengl-texture.png
The image is a simple 128x128 bitmap. The colorkey here is (255,0,255) on a
white background. It looks like some of the colorkey still remain. The following
code is used to load the texture:
GLuint loadTextureCK(char *filepath, int ckr, int ckg, int ckb){
GLuint texture;
SDL_Surface *imagesurface;
SDL_Surface *tmpsurface;
Uint32 colorkey;
int w, h;
imagesurface = SDL_LoadBMP(filepath);
if (!imagesurface)
return 0;
w = imagesurface->w;
h = imagesurface->h;
/* create temporary surface with the correct OpenGL format */
tmpsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x000000FF,
0x0000FF00,
0x00FF0000,
0xFF000000
#else
0xFF000000,
0x00FF0000,
0x0000FF00,
0x000000FF
#endif
);
if (!tmpsurface)
return 0;
/* set colour key */
colorkey = SDL_MapRGBA(tmpsurface->format, ckr, ckg, ckb, 0);
SDL_FillRect(tmpsurface, NULL, colorkey);
colorkey = SDL_MapRGBA(imagesurface->format, ckr, ckg, ckb, 0);
SDL_SetColorKey(imagesurface, SDL_SRCCOLORKEY, colorkey);
SDL_BlitSurface(imagesurface, NULL, tmpsurface, NULL);
/* create OpenGL texture */
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h,
0, GL_RGBA, GL_UNSIGNED_BYTE, tmpsurface->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
SDL_FreeSurface(imagesurface);
SDL_FreeSurface(tmpsurface);
return texture;
}
Anyone know what the problem is?
Thank you in advance,
Marcus