Hi
Does anyone have some code that walks an SDL_Surface and compares a pixel
color and then sets the alpha value ?
I’m trying to implement a colorkey effect for drawing sprites in OpenGL, and
it seems the solution is to check each pixel, and if it’s a certain color,
say 0 for black, then set the alpha value for that pixel to 255, otherwise
set it to 0. Then when rendering the texture, you can set the alpha value
to reject that pixel, therefore, getting a colorkey effect.
The code to load a surface to OpenGL works fine. I thought the best place to
put the code would be just before uploading the pixel data to OpenGL
SDL_BlitSurface(surface, &area, image, &area);
//
// Restore the alpha blending attributes
if ((savedFlags & SDL_SRCALPHA) == SDL_SRCALPHA)
SDL_SetAlpha(surface, savedFlags, savedAlpha);
//
// Create an OpenGL texture for the image
else
{
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
--> Convert surface here
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
GL_UNSIGNED_BYTE, image->pixels);
}
Any pointers would be welcomed.
Thanks
David—
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.391 / Virus Database: 222 - Release Date: 18/09/02
The information transmitted is for the use of the intended recipient only
and may contain confidential and/or legally privileged material. Any
review, re-transmission, disclosure, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited and may result in
severe penalties. If you have received this e-mail in error please notify
the Security Adviser of the Department of Communications, Information
Technology and the Arts, telephone (02) 6271-1880 and delete all copies of
this transmission together with any attachments.