[SDL] How to gray out a button image?
David Olsen
jolynsbass at gmail.com
Tue Apr 8 18:20:18 PDT 2008
If I haven't misunderstood, you're asking how to take an image and turn it
into just plain grayscale, to indicate a state of un-clickable. An easy way
to do this would be to scan the image with the Get_Pixel routine(loops in
the x and y directions) included in the documentation, and then average the
rgb values for each pixel into a new image. Viola, grayscale. (If that's
what you are looking for, that is)
psuedocode:
SDL_Surface * button_regular = SDL_LoadBMP("regular.bmp");
SDL_Surface * button_gray = SDL_CreateRGBSurface(make image of appropriate
size);
for (int y=0; y<button_regular->h; y++)
for (int x=0; x<button_regular->w; x++)
{
Uint 8 r,g,b,a;
Uint32 pixel = Get_Pixel(button_regular,x,y);
SDL_GetRGB(pixel, button_regular->fmt, &r, &g, &b);
r = g = b = (r+g+b)/3;
pixel = SDL_MapRGB(button_gray->fmt, r, g, b);
Put_Pixel(button_gray,x,y,pixel);
}
//button_gray should now look just like button_regular, but in grayscale.
the get_pixel and put_pixel routines can be found in the SDL Documentation
under the examples 2-4 and 2-5.
Hope that helps,
-Dave Olsen
----- Original Message -----
From: "Erik" <esigra at gmail.com>
To: "A list for developers using the SDL library. (includes SDL-announce)"
<sdl at lists.libsdl.org>
Sent: Tuesday, April 08, 2008 6:26 PM
Subject: [SDL] How to gray out a button image?
> We need to gray out[1] buttons with images on in our toolkit. I just
> wonder what is the best way to gray out the image. Has anyone done that
> before? Does it need SDL_gfx or just SDL?
>
> [1] [http://en.wikipedia.org/wiki/Grayed_out]
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
More information about the SDL
mailing list