SGDK - Fading issues

SGDK only sub forum

Moderator: Stef

Post Reply
Helghast
Interested
Posts: 29
Joined: Sat May 25, 2013 8:53 pm
Location: Amsterdam, Netherlands
Contact:

SGDK - Fading issues

Post by Helghast » Wed May 29, 2013 11:43 am

Hey Guys,

I'm getting closer to understanding how this thing works ;)
I attempted to fade an image in and then out again.
The fading in part works, but when I start fading out, it's palette colours swap to white and then fade to black.
Can anyone help me explain why?

Here's the code I am using (I pasted the full thing, just so you can see what's going on).

Code: Select all

#include <genesis.h>

extern GenResTiles FRBackground;
extern GenResTiles FRLogo;

#define TILEPRIO	0

int main()
{
	// Set game to PAL format
	VDP_setScreenHeight240();
	
	// Load Data for background
	VDP_setPalette(PAL1, FRBackground.pal); // this palette needs to fade
	
	// load tiles in VRAM
	//  arg0 = tiles data
	//  arg1 = index for first destination tile
	//  arg2 = number of tiles to load
	//  arg3 = use DMA (1) or not (0)
	VDP_loadTileData(FRBackground.tiles, TILE_USERINDEX, FRBackground.width*FRBackground.height, 0);	
//	VDP_loadTileData(FRLogo.tiles, TILE_USERINDEX, FRLogo.width*FRLogo.height, 0);

	VDP_fadePalIn(PAL1, FRBackground.pal, 60, 1); // start fading in (before we draw the map, so it doesnt "pop" for a frame)
	
	// Draw images on screen
	// arg0 = draw plane (APLAN | BPLAN)
	// arg1 = tile data
	//		arg0 = pallette to use
	//		arg1 = priority
	//		arg2 = flip
	//		arg3 = flip
	//		arg4 = index
	//	arg2 = X position
	// arg3 = Y position
	// arg4 = width (in tiles)
	// arg5 = height (in tiles)
	VDP_fillTileMapRectInc(APLAN, TILE_ATTR_FULL(PAL1, TILEPRIO, 0, 0, TILE_USERINDEX), 0, 0, FRBackground.width, FRBackground.height);
//	VDP_fillTileMapRectInc(BPLAN, TILE_ATTR_FULL(PAL2, TILEPRIO, 0, 0, TILE_USERINDEX + tilesLoaded), 0, 0, FRLogo.width, FRLogo.height);
	
	// "Menu" text
	VDP_drawTextBG(BPLAN, "Press start to continue ", TILE_ATTR(PAL0, 1, 0, 0), 8, 24);
	
	// fading
	VDP_waitFadeCompletion(); // wait til fade has completed
	VDP_setPalette(PAL1, FRBackground.pal); // update palette (after fading, the colours still looked a tint darker)
	waitTick(TICKPERSECOND * 2); // wait for 2 seconds
	VDP_clearTextBG(BPLAN, 8, 24,	24); // remove text
	VDP_fadePalOut(PAL1, 60, 0); // Fade image out
	VDP_waitFadeCompletion(); // wait til fade has completed
	
	while(1)
	{
		//read input
		//move sprite
		//update score
		//draw current screen (logo, start screen, settings, game, gameover, credits...)
		
		//wait for screen refresh
		VDP_waitVSync();
	}
	return (0);
}
Hope someone can help me again!

regards,
Dennis

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: SGDK - Fading issues

Post by Stef » Wed May 29, 2013 4:09 pm

Hi,

Your code seems correct except you are setting your own palette at initialization where you should set black one:

Code: Select all

VDP_setPalette(PAL1, palette_black);
Then you can load your tiles and tilemap data and start your fade in to the desired palette:

Code: Select all

VDP_fadePalIn(PAL1, FRBackground.pal, 60, 1);
...
VDP_waitFadeCompletion();
and after a while just fade out:

Code: Select all

VDP_fadePalOut(PAL1, 60, 1);
...
VDP_waitFadeCompletion();
As i told you, your code is ok so i will check that i did not break anything in the last SGDK version with that :-/

Helghast
Interested
Posts: 29
Joined: Sat May 25, 2013 8:53 pm
Location: Amsterdam, Netherlands
Contact:

Re: SGDK - Fading issues

Post by Helghast » Thu May 30, 2013 12:15 pm

Stef wrote: As i told you, your code is ok so i will check that i did not break anything in the last SGDK version with that :-/
I made the changes according to what you said, it still doesnt fade out properly.
Would you like me to upload my project so you can see what's going on?

regards, Dennis

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Thu May 30, 2013 7:29 pm

I just tried with your code (but my own image) and it works correctly so i guess you have something wrong in other part of your code.
Have you something special in your vint callback ?

Also what is your FRBackground structure by the way ? you have the Bitmap structure in SGDK which is common for that.

Helghast
Interested
Posts: 29
Joined: Sat May 25, 2013 8:53 pm
Location: Amsterdam, Netherlands
Contact:

Post by Helghast » Thu May 30, 2013 8:35 pm

Stef wrote:I just tried with your code (but my own image) and it works correctly so i guess you have something wrong in other part of your code.
Have you something special in your vint callback ?
No, I dont think I do.
However, my knowledge on loading tiles is close to non-existent, I asked in another thread before, but got no answer, so I really dont know how it's supposed to work properly, and I think the problem lies there.
Stef wrote: Also what is your FRBackground structure by the way ? you have the Bitmap structure in SGDK which is common for that.
I used GenRes to automatically convert the bitmaps (through the resource file).

You can download the whole project (including my music, and textures I used) here: http://www.designorhea.com/MegaDrive/FinalRun.rar

Hope this helps, if not, atleast might get me some insight in how it's supposed to work.

regards, Dennis

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri May 31, 2013 8:26 am

Thanks for the sample, indeed i can reproduce the same problem.
The problem comes from the fact you use the PAL1, i was using PAL0 in my test. Seems there is a bug in SGDK when we don't use the PAL0 for fade out effect so i suggest you to use PAL0 in the meantime. I will fix it in the next version ! Sorry for the trouble and waste of time with that. By the way, the way you are loading tiles is perfectly right ;)

Helghast
Interested
Posts: 29
Joined: Sat May 25, 2013 8:53 pm
Location: Amsterdam, Netherlands
Contact:

Post by Helghast » Fri May 31, 2013 9:23 am

Stef wrote:Thanks for the sample, indeed i can reproduce the same problem.
The problem comes from the fact you use the PAL1, i was using PAL0 in my test. Seems there is a bug in SGDK when we don't use the PAL0 for fade out effect so i suggest you to use PAL0 in the meantime. I will fix it in the next version ! Sorry for the trouble and waste of time with that. By the way, the way you are loading tiles is perfectly right ;)
Thanks, I'll use PAL0 for the time being (though I though that was used for the text somehow :P).
I get weird graphical issues when I try to load more then 1 image into the VRAM.
Could you explain how that is supposed to work?
In the example I am trying to load the FRLogo at the same time when I load the FRBackground. But that always produces graphic glitches for me.

Hope that is as easy as well, hehehe.

regards, Dennis

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri May 31, 2013 12:24 pm

Yeah the PAL0 is used by text but you can change it with this method:

Code: Select all

VDP_setTextPalette(u16 palette);
For the VRAM, you have a limited quantity of VRAM and you can't load plenty of big images at same time.
You can now the number of tile for user with TILE_USERLENGHT. Others part of VRAM is reserved by SGDK. For an image of 320x224 resolution your are already using 1120 tiles which is almost all the available tile space in VRAM.
You are not supposed to load several complete image at same time or you should at least optimize the redundant tiles (empty one).

Helghast
Interested
Posts: 29
Joined: Sat May 25, 2013 8:53 pm
Location: Amsterdam, Netherlands
Contact:

Post by Helghast » Fri May 31, 2013 5:42 pm

Stef wrote:Yeah the PAL0 is used by text but you can change it with this method:

Code: Select all

VDP_setTextPalette(u16 palette);
For the VRAM, you have a limited quantity of VRAM and you can't load plenty of big images at same time.
You can now the number of tile for user with TILE_USERLENGHT. Others part of VRAM is reserved by SGDK. For an image of 320x224 resolution your are already using 1120 tiles which is almost all the available tile space in VRAM.
You are not supposed to load several complete image at same time or you should at least optimize the redundant tiles (empty one).
figured. What is the Max number of tiles to load?
and how can i scale images? (say i load in the image half the size, but display it scaled 2X)

gards, Dennis

Post Reply