#145874 - melw - Sat Nov 24, 2007 12:45 pm
Last night I played around with some alpha-blended particles in MODE_0_3D. Using RGB8_A5 texture format is otherwise ok, but the 8 color palette doesn't give much freedom while I wanted to pick the particle color freely from all the 32k possible values. In the end I came up with one solution (which some of you may consider a dirty hack): Filling the entire VRAM bank E with all the colors, create 8 otherwise identical particle textures, only each of them using different color from the "8 color palette" and set palette pointer manually when drawing to get the right color.
If you know how to do this better or otherwise, feel free to comment. Wasting half of the VRAM bank E for oversized palette data feels stupid, but at least it works. :)
test src + nds
Code: |
#define NUM_TEXTURES 8
int textureIds[NUM_TEXTURES]; u8 *textureData[NUM_TEXTURES]; // particle texture loading etc. for(int i=0;i<NUM_TEXTURES;i++) { glBindTexture(0, textureIds[i]); glTexImage2D(0, 0, GL_RGB8_A5, TEXTURE_SIZE_32, TEXTURE_SIZE_32, 0, TEXGEN_TEXCOORD, (u8*)textureData[i]); } u16 *palData = (u16*)malloc(32*32*32); for(r=0;r<32;r++) // generate all 15bit colors into one large palette { for(g=0;g<32;g++) { for(b=0;b<32;b++) { palData[r*1024+g*32+b] = RGB15(r,g,b); } } } glTexLoadPal(palData, 32768, 0); // when drawing a particle - color is integer between 0...32768 glBindTexture(0, textureIds[textureId+(color&7)]); GFX_PAL_FORMAT = color>>4; glBegin(GL_QUAD); // ... rest of the draw code |
If you know how to do this better or otherwise, feel free to comment. Wasting half of the VRAM bank E for oversized palette data feels stupid, but at least it works. :)
test src + nds