[SDL] How to set an individual pixel to transparent?
Jonathan Dearborn
grimfang4 at hotmail.com
Mon Sep 24 09:28:28 PDT 2007
Hey, If you don't care about speed, you can try taking a plain pixel function and changing it to work for you. Here's something that might work... Every time you need a transparent pixel, call this function (or you could make a more general function to accept RGBA values instead of Uint32).
See code below...
I hope it helps,
Jonny D
void SetPixelTrans(SDL_Surface *surface, Sint16 x, Sint16 y, Uint32 color){
// The change
Uint8 r, g, b, a;
// This will probably warn you about addressing locals
SDL_GetRGBA(color, surface->format, &r, &g, &b, &a);
// Now give it transparent pixels
color = SDL_MapRGBA(surface->format, r, g, b, SDL_ALPHA_TRANSPARENT);
switch (surface->format->BytesPerPixel) {case 1: { /* Assuming 8-bpp */*((Uint8 *)surface->pixels + y*surface->pitch + x) = color;}break;case 2: { /* Probably 15-bpp or 16-bpp */*((Uint16 *)surface->pixels + y*surface->pitch/2 + x) = color;}break;case 3: { /* Slow 24-bpp mode, usually not used */Uint8 *pix = (Uint8 *)surface->pixels + y * surface->pitch + x*3;/* Gack - slow, but endian correct */*(pix+surface->format->Rshift/8) = color>>surface->format->Rshift;*(pix+surface->format->Gshift/8) = color>>surface->format->Gshift;*(pix+surface->format->Bshift/8) = color>>surface->format->Bshift;*(pix+surface->format->Ashift/8) = color>>surface->format->Ashift;}break;case 4: { /* Probably 32-bpp */*((Uint32 *)surface->pixels + y*surface->pitch/4 + x) = color;}break;}}}
> From: dbruce at tampabay.rr.com> To: sdl at lists.libsdl.org> Date: Sun, 23 Sep 2007 22:02:05 -0400> Subject: [SDL] How to set an individual pixel to transparent?> > Hi,> > Quick question - if p points to an individual pixel in a 32-bit RGBA > SDL_Surface, how do I set it to transparent for either a little- or > big-endian system?> > (I'm trying to write a function to round off the corners of rectangles, and I > think I've figured the rest out, but I'm having trouble with the actual > manipulation of the pixel data).> > Thanks for any help,> -- > David Bruce> _______________________________________________> SDL mailing list> SDL at lists.libsdl.org> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
_________________________________________________________________
Capture your memories in an online journal!
http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070924/ff819746/attachment.htm
More information about the SDL
mailing list