Page 1 of 1

sprite palettes, 256 colors[solved]?

Posted: Mon Feb 02, 2009 8:11 pm
by Tomdev
hey everyone, i was experimenting with 256 color sprites. when i tried to load two different 256 color sprites, one sprite screwed up: it used the palette of the first sprite. ok, i began searching, and read that it was impossible to have two or more 256 color palletes. but when i used palib, you could have different 256 palletes, so how is this possible?

Re: sprite palettes, 256 colors?

Posted: Wed Feb 04, 2009 5:09 am
by Sylus101
It's certainly not impossible. What you're looking for is enabling extended palettes which gives you 16 256 color palettes for each screen they're enabled for.

Haven't quite tackled how this is enabled yet myself though... I can see how it would be done by setting registers, but it would be best to see if someone more experienced comes along to show maybe a typical way to handle it.

Here's the gbatek info on it: http://nocash.emubase.de/gbatek.htm#dsv ... edpalettes

Re: sprite palettes, 256 colors?

Posted: Wed Feb 04, 2009 7:23 am
by Tomdev
ok, i have heard about that vram bank h or something was used for extended palletes

Re: sprite palettes, 256 colors?

Posted: Thu Feb 05, 2009 5:06 pm
by dovoto
In writing a quick example to address this question I found a few issues with libnds sprite ext palette handling. These have been repaired and uploaded to the svn. Here is an example for sprite ext palette usage via libnds (requires current svn of libnds as of 2-5-2009)

Code: Select all

/*---------------------------------------------------------------------------------

Simple extended palette demo.  Creates two sprites on the main display
using palette 0 and palette 1.

-- dovoto

---------------------------------------------------------------------------------*/
#include <nds.h>

//---------------------------------------------------------------------------------
int main(void) {
	//---------------------------------------------------------------------------------
	int i = 0;

	touchPosition touch;

	videoSetMode(MODE_0_2D);
	
	vramSetBankA(VRAM_A_MAIN_SPRITE);

	oamInit(&oamMain, SpriteMapping_1D_128, true);

	u16* gfx1 = oamAllocateGfx(&oamMain, SpriteSize_16x16, SpriteColorFormat_256Color);
	u16* gfx2 = oamAllocateGfx(&oamMain, SpriteSize_16x16, SpriteColorFormat_256Color);

	// notice both sprites are filled with color 1
	for(i = 0; i < 16 * 16 / 2; i++)
	{
		gfx1[i] = 1 | (1 << 8);
		gfx2[i] = 1 | (1 << 8);
	}

	// unlock vram (cannot write to vram while it is mapped as a palette)
	vramSetBankF(VRAM_F_LCD);

	VRAM_F_EXT_PALETTE[0][1] = RGB15(31,0,0);
	VRAM_F_EXT_PALETTE[1][1] = RGB15(0,31,0);

	// set vram to ex palette
	vramSetBankF(VRAM_F_SPRITE_EXT_PALETTE);

	while(1) {

		scanKeys();

		if(keysHeld() & KEY_TOUCH)
			touchRead(&touch);

		oamSet(&oamMain, //main graphics engine context
			0,           //oam index (0 to 127)  
			touch.px, touch.py,   //x and y pixle location of the sprite
			0,                    //priority, lower renders last (on top)
			0,					  //this is the palette index if multiple palettes or the alpha value if bmp sprite	
			SpriteSize_16x16,     
			SpriteColorFormat_256Color, 
			gfx1,                  //pointer to the loaded graphics
			-1,                  //sprite rotation data  
			false,               //double the size when rotating?
			false,			//hide the sprite?
			false, false, //vflip, hflip
			false	//apply mosaic
			);              
		
		
		oamSet(&oamMain, 
			1, 
			SCREEN_WIDTH - touch.px, 
			SCREEN_HEIGHT - touch.py, 
			0, 
			1,  //use second palette
			SpriteSize_16x16, 
			SpriteColorFormat_256Color, 
			gfx2, 
			-1, 
			false, 
			false,			
			false, false, 
			false	
			);              
	
		swiWaitForVBlank();

		
		oamUpdate(&oamMain);
	}

	return 0;
}

Re: sprite palettes, 256 colors?

Posted: Thu Feb 05, 2009 5:18 pm
by Tomdev
thanks, i will download the libnds out of the svn.

edit: stupid but i can't find the svn(i never look in a svn) :oops: can someone say where i can find it?

Re: sprite palettes, 256 colors?

Posted: Fri Feb 06, 2009 5:10 am
by WinterMute
You're probably best waiting for the stable release which should hopefully be available in a few days. SVN is generally in a state of flux and not always in a state that can be compiled by end users.

Re: sprite palettes, 256 colors?

Posted: Fri Feb 06, 2009 7:27 am
by Tomdev
thanks for your reply wintermute, i will wait for the update 8)

Re: sprite palettes, 256 colors?

Posted: Sat Feb 07, 2009 3:02 am
by Sylus101
Looking at that example, doesn't this:

Code: Select all

videoSetMode(MODE_0_2D);
Need to be this?

Code: Select all

videoSetMode(MODE_0_2D | DISPLAY_SPR_EXT_PALETTE);

Re: sprite palettes, 256 colors?

Posted: Sat Feb 07, 2009 3:32 am
by dovoto
Sylus101 wrote:Looking at that example, doesn't this:

Code: Select all

videoSetMode(MODE_0_2D);
Need to be this?

Code: Select all

videoSetMode(MODE_0_2D | DISPLAY_SPR_EXT_PALETTE);
No. The sprite and bg api both handle the setting of the display control registers as needed.