Any code to walk SDL_Surface

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.


Yes, in glSDL - although that supports only 24 bit RGB and 32 bit RGBA so
far. (Tried to keep things simple until all the features are in place.
Supporting other pixel formats directly is more of a performance hack.)

http://olofson.net/mixed.html

You’ll find the code if you look for normal SDL alpha stuff in glSDL.c.

If you want the latest glSDL version, it’s in the unofficial KoboDeluxe
0.4pre9. (PPC fix for Debian, and some other stuff - don’t know if I got
it right yet, as I can’t test it myself.)

http://olofson.net/skobo/download/KoboDeluxe-0.4pre9.tar.gz

//David Olofson - Programmer, Composer, Open Source Advocate

.- Coming soon from VaporWare Inc…------------------------.
| The Return of Audiality! Real, working software. Really! |
| Real time and off-line synthesis, scripting, MIDI, LGPL…|
-----------------------------------> (Public Release RSN) -' .- M A I A -------------------------------------------------. | The Multimedia Application Integration Architecture |----------------------------> http://www.linuxdj.com/maia -’
http://olofson.nethttp://www.reologica.se —On Tuesday 15 October 2002 05:16, Berry, David wrote:

Hi

Does anyone have some code that walks an SDL_Surface and compares a
pixel color and then sets the alpha value ?