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

i havent messed with transparent pixels before, but here is info from
the wiki about the pixel format,

http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fPixelFormat

you should use this to find what the rgb format is. no need for
#ifdef bigendian, if you have that.

i would guess you are trying to use the apha on the pixel ?

mattOn Sep 23, 2007, at 9:02 PM, David Bruce wrote:

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

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 + ysurface->pitch + x) = color;}break;case 2: { /* Probably 15-bpp or 16-bpp /((Uint16 )surface->pixels + ysurface->pitch/2 + x) = color;}break;case 3: { /* Slow 24-bpp mode, usually not used /Uint8 pix = (Uint8 )surface->pixels + y * surface->pitch + x3;/ 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 + ysurface->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