sprite palettes, 256 colors[solved]?

Post Reply
Tomdev
Posts: 82
Joined: Thu Jan 08, 2009 9:15 pm

sprite palettes, 256 colors[solved]?

Post by Tomdev » Mon Feb 02, 2009 8:11 pm

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?
Last edited by Tomdev on Wed Feb 11, 2009 8:43 pm, edited 2 times in total.

Sylus101
Posts: 179
Joined: Wed Dec 24, 2008 5:08 am

Re: sprite palettes, 256 colors?

Post by Sylus101 » Wed Feb 04, 2009 5:09 am

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
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

Tomdev
Posts: 82
Joined: Thu Jan 08, 2009 9:15 pm

Re: sprite palettes, 256 colors?

Post by Tomdev » Wed Feb 04, 2009 7:23 am

ok, i have heard about that vram bank h or something was used for extended palletes

dovoto
Developer
Posts: 43
Joined: Fri Aug 12, 2005 10:01 pm
Contact:

Re: sprite palettes, 256 colors?

Post by dovoto » Thu Feb 05, 2009 5:06 pm

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;
}

Tomdev
Posts: 82
Joined: Thu Jan 08, 2009 9:15 pm

Re: sprite palettes, 256 colors?

Post by Tomdev » Thu Feb 05, 2009 5:18 pm

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?

WinterMute
Site Admin
Posts: 2003
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: sprite palettes, 256 colors?

Post by WinterMute » Fri Feb 06, 2009 5:10 am

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.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Tomdev
Posts: 82
Joined: Thu Jan 08, 2009 9:15 pm

Re: sprite palettes, 256 colors?

Post by Tomdev » Fri Feb 06, 2009 7:27 am

thanks for your reply wintermute, i will wait for the update 8)

Sylus101
Posts: 179
Joined: Wed Dec 24, 2008 5:08 am

Re: sprite palettes, 256 colors?

Post by Sylus101 » Sat Feb 07, 2009 3:02 am

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);
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

dovoto
Developer
Posts: 43
Joined: Fri Aug 12, 2005 10:01 pm
Contact:

Re: sprite palettes, 256 colors?

Post by dovoto » Sat Feb 07, 2009 3:32 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests