What kind of ‘area’? A polygon? A mask? Just a rectangle?
I’ll assume the latter, since it’s the simplest.
What kind of gradient? Horizontal? Vertical? 45-degree diagonal?
Some arbitrary direction? Is it a linear gradient? A circle? Rectangular?
I’ll assume it’s vertical, since it’s one of the simplest, and most used.
How many colors? Just one color to another? Or a whole array of them?
I’ll assume the former, since it’s the simplest. (The latter could be done
by piecing together the former a number of times.)
Let’s see… Off the cuff and untested, as usual:
void vertgradient(SDL_Surface * surf, SDL_Color c1, SDL_Color c2)
{
int y, width, height;
Uint8 r, g, b;
SDL_Rect dest;
Uint32 pixelcolor;
width = surf->w;
height = surf->h;
for (y = 0; y < height; y++)
{
r = (c2.r * y / height) + (c1.r * (height - y) / height);
g = (c2.g * y / height) + (c1.g * (height - y) / height);
b = (c2.b * y / height) + (c1.b * (height - y) / height);
dest.x = 0;
dest.y = y;
dest.w = width;
dest.h = 1;
pixelcolor = SDL_MapRGB(surf->format, r, g, b);
SDL_FillRect(surf, &dest, pixelcolor);
}
}
(Okay, I actually did test it, and it did work )
Enjoy!
-bill!On Sun, Apr 13, 2003 at 10:57:23AM -0300, Eduardo B. Fonseca wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello,
I need to have a function that fills any specified area with a gradient. Do
you guys have any example code that implements this?