[SDL] Checking pixel color w/ transparent color
Ricardo Amores Hernández
ricky at telecable.es
Tue Aug 12 15:56:01 PDT 2003
Damiano escribió:
I think you must lock the surface in order to use getPixel()
Hum, i´ve just read the docs and yes, you MUST lock the surface. Taken
from the docs:
> Hello,
>
> I'd like to know how I could check if a pixel at a specifed (x, y) position
> in an SDL_Surface is transparent. The SDL_Surface comes from a
> TTF_RenderText function call by the way.
>
> I've tried this but it doesn't seem to work :
>
> SDL_Surface *img = TTF_RenderText...(...);
if ( SDL_MUSTLOCK(screen) )
if ( SDL_LockSurface(screen) < 0 ) {
fprintf(stderr, "Can't lock screen: %s\n", SDL_GetError());
return;
}
> // getpixel() taken from the doc
> // at 'Chapter 2'
> Uint32 pixel = getpixel(img, x, y);
if ( SDL_MUSTLOCK(screen) )
SDL_UnlockSurface(screen);
> if ( pixel == img->format->colorkey )
> printf("Pixel @ (%d, %d) is transparent\n", x, y);
> }
> Can you help me ?
>
> Thanks,
>
Hope it works now.
--
---------------------------------------------------
Ricardo Amores Hernández
ICQ: 19463735
MSN: zheo_ (at) hotmail (dot) es
---------------------------------------------------
More information about the SDL
mailing list