|
fading w/ color Displaying 1-9 of 9 total.
1
jrhee
|
I'm trying to code an image to fade out, with a color filter applied to it. If any of you are familiar with FF6, I'm talking about an effect similar to the pink fadeout that occurs when an enemy dies. The problem is when I try to TBlit my image, the colorfilter changes the death magenta that would normally filter, and I wind up displaying the parts that ought to be invisible. Does anyone know of a way to get around this? My code looks something like this:
void Fade() {
ColorFilter(CF_RED, img);
for(i = 0; i < 100; i++) {
Render();
TBlit(x, y, i, img, screen);
ShowPage();
}
}
Posted on 2006-10-14 19:11:32
|
Gayo
|
Isn't that obnoxious? A simple solution to this is high on my list of desired features, but right now you have to jump through a lot of hoops if you want to screw with an image without wrecking its transparency.
I can't honestly think of a way around this without doing pixel-by-pixel fuckery, using two source images, or using an alpha layer. You could take the alpha route. Alternatively, to get something sort of like the effect you want, you could silhouette the image to a dark cyan or something and then subtractive blit that over the real image, which would redden it. You could then increase the cyan intensity to make it more red. A similar result could be accomplished with additive blit. However, that won't give you exactly what you want. Sorry!
Posted on 2006-10-14 23:27:50
|
choris
|
I had this problem too, and yes, I ended up doing pixel-by-pixel fuckery. Surprisingly though, it didn't slow down verge at all and worked quite well.
Here's a generic version of what I did.
int makeImageColor(int imagePointer, int rgbcol)
{
int temp, x, y;
temp = duplicateImage(imagePointer);
setCustomColorFilter(rgbcol, rgbcol);
colorFilter(CF_CUSTOM, temp);
for(y=0;y<imageheight(temp);y++)
{
for(x=0;x<imagewidth(temp);x++)
{
if(getPixel(x, y, imagePointer) = RGB(255, 0, 255))
setpixel(x, y, getPixel(x, y, imagePointer), temp);
}
}
return temp;
freeimage(temp);
}
And you would use it like this.
int coloredImage;
coloredImage = makeImageColor(originalImage, RGB[R,G,B]);
// your blit lucent code here using coloredImage
free(coloredImage);
I think that code will work, I didn't check it.
Posted on 2006-10-15 00:14:01
|
choris
|
Ah I should explain something else.
I blit the new colored image onto my original image at a transparency, so THEN, it gave it the hue effect you'd want. You can do this gradually so it seems to turn a color, and then once it reaches the desired level, fade the image out to completely invisible. THAT should give you the desired effect.
Posted on 2006-10-15 00:19:35
|
jrhee
|
Thanks for the replies. I dug around and found an old thread that touches on this issue, where Overkill suggested a Silhouette and AlphaBlit based solution to the problem that actually works out nicely. My code wound up looking like this:
void Die(int me) {
int i;
SetCustomColorFilter(RGB(240,0,240),RGB(0,0,0));
for (i = 0; i < 100; i+=10) {
Render();
TBlitLucent(enemArray[me].x,
enemArray[me].y - ImageHeight(enemArray[me].sprite_handle),
i, RecolorImage(enemArray[me].sprite_handle, CF_CUSTOM), screen);
DrawBattleMenu();
WaitNoRender(5);
}
FreeImage(enemArray[me].sprite_handle);
FreeEnemy(me);
}
int RecolorImage(int img, int color_filter) {
int img2= DuplicateImage(img);
int sil = DuplicateImage(img);
int tempimg = DuplicateImage(img);
RectFill(0,0,ImageWidth(img2),ImageHeight(img2),RGB(255,0,255),img2);
//Silhouette crap.
RectFill(0,0,ImageWidth(sil),ImageHeight(sil),0,sil);
Silhouette(0,0,RGB(255,255,255),img,sil);
//Colorfilter crap
ColorFilter(color_filter,tempimg);
//Make the magenta (transparent) areas be unaffected by the colorfilter.
AlphaBlit(0,0,tempimg,sil,img2);
FreeImage(sil);
FreeImage(tempimg);
//Return the pointer to the new image.
return img2;
}
The original thread can be found here.
Posted on 2006-10-15 10:41:19 (last edited on 2006-10-15 14:38:22)
|
Overkill
|
Only notable problem with that method, is how you're creating a bunch of indentical image handles that aren't freed, causing some slowdown for each function call made, and memory leaks. Instead, make one recolored image, assign it to a variable before the for loop, and then free it as soon as you're finished.
Posted on 2006-10-15 14:35:13
|
Gayo
|
HEY OVERKILL. Why don't you put in the things I said I wanted to work around this problem? ^________^ Then everyone would be happy.
Well, except the people who can't or won't check out and compile the engine code.
Posted on 2006-10-16 21:04:59
|
Overkill
|
Actually, I'm pretty sure I added TColorFilter or ColorFilter that always adheres to transparancy within a Verge WIP build. But maybe it's only been incorporated in my private builds.
Posted on 2006-10-17 12:36:00 (last edited on 2006-10-17 12:36:15)
|
Gayo
|
Oh! Well, awesome. Then it just gets back to the only "someone release a new build" problem again.
Posted on 2006-10-17 21:01:59
|
Displaying 1-9 of 9 total.
1
|
|