I think what you need to do really (what I did) is create an SDL_Surface of
the required size (code for doing this is in the docs, I believe). For
example 32 x 32
After you had created the surface, fill it entirely with the colour you want
(for example red - 0xff, 0x00, 0x00).
You should now have a Surface of 32 * 32 size of a solid red colour
Finally, set the surface’s alpha value using SDL_SetAlpha()
You’ll now have a transparent red surface of 32 x 32 which you can put over
your tile when it is clicked.
You’ll have to be using a graphics depth of more than 8 bits to get alpha
blending to work properly.
I’ve got a function for my game that will do all the above for me and return
the surface. I just give the function a width and height and the colour I
want the surface to be.
Hope that’s what you’re looking to do… 
actually… here’s the two functions I have… hack them up as you need 
SDL_Surface *createSurface(int width, int height)
{
SDL_Surface *surface, *newImage;
Uint32 rmask, gmask, bmask, amask;
/* SDL interprets each pixel as a 32-bit number, so our masks must
depend
on the endianness (byte order) of the machine */
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
rmask, gmask, bmask, amask);
if (surface == NULL) {
fprintf(stderr, "CreateRGBSurface failed: %s\n",
SDL_GetError());
exit(1);
}
newImage = SDL_DisplayFormat(surface);
SDL_FreeSurface(surface);
return newImage;
}
SDL_Surface *alphaRect(int width, int height, Uint8 red, Uint8 green, Uint8
blue)
{
SDL_Surface *surface = createSurface(width, height);
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, red, green,
blue));
SDL_SetAlpha(surface, SDL_SRCALPHA|SDL_RLEACCEL, 128);
return surface;
}> -----Original Message-----
From: Robert Harrison [SMTP:rharrison at hgfip.com]
Sent: Tuesday, March 11, 2003 10:55 AM
To: sdl at libsdl.org
Subject: Re: [SDL] How do you put an effect over an image?
OK Still struggling.
I know, I know, I should give up now.
I have
SDL_Rect dest;
dest.x = 100;
dest.y = 100;
dest.w = 100;
dest.h = 100;
SDL_FillRect (screen, &dest,
SDL_MapRGBA(screen->format,0xFF,0x00,0xFF,myALPHA));
SDL_UpdateRect (screen, 100,100,100,100);
This gives me a lovely solid pink colour no matter what value I set
myALPHA to.
any ideas anyone.
Do I need to set the screen somehow to allow alpha filling to work?
Bill Kendrick wrote:
On Mon, Mar 10, 2003 at 03:48:16PM -0000, Robert wrote:
I have a load of tiles displayed on the screen.
You could do something like:
SDL_Rect dest;
…
dest.x = X;
dest.y = Y;
dest.w = myTILE->w;
dest.h = myTILE->h;
SDL_FillRect(mySURFACE, &dest,
SDL_MapRGBA(mySURFACE->format, 0x00, 0x00, 0xFF,
myALPHA));
(I think that’ll work.)
I’ve also done it like so:
…
SDL_SetAlpha(myBLUE_SURFACE, SDL_SRCALPHA, myALPHA);
SDL_BlitSurface(myBLUE_SURFACE, &src, myDEST_SURFACE, &dest);
-bill!
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
.sophos.3.65.03.11.