gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Implementing a FadeOut/FadeIn

#8416 - jcpredator - Thu Jul 10, 2003 12:07 am

I am trying to implement a fadeout from my titlescreen to just a black plain. At the moment nothing happens and the titlescreen is displayed with no fading in or out. I will include my code below:

From gamemode.c (the file that is responsible from switching from pregame mode to the real game)

Quote:
void gamemode_fadeOut(void)
{
SetBlendMode(BD_TARGET | MODE3 | BG3_START);
SetColY(0x10);
}

void gamemode_enter(void)
{
gamemode_fadeOut();
while(1);
}


From my fades.c (file that contains register BLDMOD defines)

Quote:
#define REG_BLDMOD *(volatile word*)0x04000050
#define REG_COLY *(volatile word*)0x04000054

#define BG0_TARGET 0x1
#define BG1_TARGET 0x2
#define BG2_TARGET 0x4
#define BG3_TARGET 0x8
#define OBJ_TARGET 0x10
#define BD_TARGET 0x20
#define MODE0 0x00
#define MODE1 0x40
#define MODE2 0x80
#define MODE3 0x100
#define BG0_START 0x200
#define BG1_START 0x400
#define BG2_START 0x800
#define BG3_START 0x1000
#define OBJ_START 0x2000
#define BD_START 0x4000

#define SetBlendMode(mode) REG_BLDMOD = (mode)

#define SetColY(factor) REG_COLY = (factor)


This is my first try at implementing a fade in/out. Thanks in advance for your help.

-Jc-
_________________
There is no spoon...

#8417 - tepples - Thu Jul 10, 2003 1:03 am

jcpredator wrote:
I am trying to implement a fadeout from my titlescreen to just a black plain. At the moment nothing happens and the titlescreen is displayed with no fading in or out.

void gamemode_fadeOut(void)
{
SetBlendMode(BD_TARGET | MODE3 | BG3_START);
SetColY(0x10);
}

That's your problem. You have to slowly ramp up (or down) the value passed to SetColY().
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#8470 - jcpredator - Fri Jul 11, 2003 1:24 pm

How might I slowly ramp down or up the value? Tried using a for loop but all i got was the same problem of it not showing up at all.
_________________
There is no spoon...

#8473 - tepples - Fri Jul 11, 2003 4:06 pm

jcpredator wrote:
How might I slowly ramp down or up the value?

You might be ramping it up or down too fast. You have to wait for vblank after each increment.

Another possibility is that you're not enabling the effect properly. Try setting it to halfway (0x08) and leaving it there; if it doesn't show up, then either you're not setting the registers properly to enable the effect, or you've turned off transparency effects in your emulator.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#8526 - jcpredator - Sun Jul 13, 2003 1:36 am

Thanks again tepples, still not showing the fade out effect after I tried setting it halfway at 0x08. Im using VisualBoyAdvance, wondering if you or anybody else knows how to make sure you have transparency effects enabled.
_________________
There is no spoon...

#8564 - MayFly - Mon Jul 14, 2003 7:31 pm

Hi jcpredator,

Here is the function I use to create a fade out effect.

This function requires that a global variable global_frame_count is accessible. This global_frame_count (cast as a 32-bit integer) counts how many VBLANKs have occurred since the program started execution.

The global_frame_count should be incremented in a VBLANK interrupt routine. Each VBLANK occurs approximately 1/60 seconds. Using a delta value of 5 should give you a nice result.

Using this global_frame_count variable is one way to control the timing of your fading leaving the machine's timers alone.

Hope this helps.

Regards,
MayFly

/********************************************************************/
// The background fades to black, the delta parameter specifies
// how many frames the REG_COLY will stay at a constant value
void FadeOut( u16 delta )
{
// Setting the Reg for neato fading effect
REG_BLDMOD = 0x1FDF;

u16 loop;
u32 fade_out_frame_count = 0;

// The GBA has 16 levels of darkness/lightness
for( loop = 0; loop < 17; ++loop )
{
fade_out_frame_count = global_frame_count + delta;

REG_COLY = loop;

while( fade_out_frame_count > global_frame_count )
{
// wait.
}

}
}

#8580 - jcpredator - Tue Jul 15, 2003 1:08 pm

Thanks MayFly, I now have a working fadeout/in function. Looks really cool by the way. Greatly appreciate the help.
_________________
There is no spoon...

#8581 - MayFly - Tue Jul 15, 2003 3:05 pm

My pleasure.

I've been down the fade in/out road you're on, I felt your frustration/struggle.

MayFly