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.

DS development > Paletted Textures

#66109 - TomschikSimon - Sun Jan 08, 2006 9:12 am

Is there a possibility to change the palette for textures. I've tried to set the palette before selecting the texture, but it seems, that only the first palette that I write is used. Is there a register to set the location from where the palette is read.

Code:
   
vramSetBankE( VRAM_E_LCD );
dmaCopy( pTexture->pPalette, VRAM_E, 256 * 2 );
vramSetBankE( VRAM_E_TEX_PALETTE );

// Select the Texture
glBindTexture( GL_TEXTURE_2D, pTexture->iTexID );

#66130 - TomschikSimon - Sun Jan 08, 2006 12:40 pm

The problem is if you write for each texture a new palette only the last palette is used, because the palette is read with the glFlush()-command and not by the assignment of the texture.

My solution is now to write the palettes after each other with the glLoadPal()-function and writing the number of the palette to 0x040004AC.
The number of the palett is blocked in 16-Byte steps, so 32 means 255 colours.

Code:
#define PALLETE   (*(vuint32*)0x040004AC)
glTexLoadPal( pTexture->pPalette, 255, g_iPalette );

PALLETE = g_iPalette * 32;
g_iPalette++;

#66132 - duencil - Sun Jan 08, 2006 1:05 pm

I think there will be an example and some new functions added to libnds soon for dealing with paletted textures.