I'm working on a project using the C SDK which has several spites rendered across several different backgrounds. I'm having some trouble working with convpng, and would appreciate any help.

The project has a variety of foreground sprites rendered in front of a background. The sprites share many colors, so what I want to do is give the sprites a palette of 100 colors, and then have each background use the last 156 palette slots for their own colors. All of this is loaded from AppVars, and I plan on having 1-2 AppVars for the foreground sprites, and an AppVar for each individual background. How can I do this? I've read through the convpng README, but I haven't been able to find out how to do what I want.

So, each background's palette would look something like:
[[100-color-palette for sprites]------156-color-palette for individual background------]

How can I create "sub-palettes" that can be included in other palettes?
How can I make convpng exclude the palette from certain AppVars (in my case, leaving it out of the foreground sprites AppVar, as the palette is loaded from the background AppVar)?
I'm a little confused, but maybe this?


Code:
#GroupC : background0
#PaletteMaxSize : 156
#PNGImages :
 background_0

#GroupC : background1
#PaletteMaxSize : 156
#PNGImages :
 background_1

#GroupC : foreground
#PaletteMaxSize : 100
#PNGImages :
 foreground_sprites

#AppvarC : fgspr
#OutputPalettes : foreground
#PNGImages :
 foreground_sprites

#AppvarC : bg0
#OutputPalettes : background0
#PNGImages :
 background_0

#AppvarC : bg1
#OutputPalettes : background1
#PNGImages :
 background_1


Then when you load your palettes, just:


Code:
    // load foreground palette
    // * 2 is needed because each entry is 16 bits
    gfx_SetPalette(foreground_pal, 100 * 2, 0);

    // load background palette
    gfx_SetPalette(background0_pal, 156 * 2, 100 * 2);
That seems to work just fine! Thanks for the help, and sorry for the confusing wording of the post. Is there a way I can include the 100-color foreground palette inside the background AppVar (before the background palette) so it can be read like a single 256-color palette? I tried adding the sprite palette to the "OutputPalettes" line, and while the output said that the AppVar included both palettes, reading the palette as if it was a single 256-color palette didn't work.
Well, it probably didn't work because PaletteMaxSize sets the maximum size of the palette... I never added a #PaletteFixedSize option Razz Looks like you've found a use case for it though! I'll add that shortly.
Maybe I'm doing this in the wrong way. I'm loading the palette directly by opening the AppVar, seeking to the offset of the palette (around 35k bytes), and then calling ti_Read(gfx_palette, 512, 1, appvar) to read the palette directly from the file. This functions identically to calling gfx_SetPalette twice (once for each palette) with two different offsets and palette sizes, right? Isn't the palette just an array of 16-bit colors? And, if the two palettes are right after each other in the file, shouldn't reading them like I'm doing treat them like one full palette?
Hm I think I know why it doesn't work. There's no option to specify the offset for the palette conversion either. I'll try to get this working at some point.
I think I understand. So for both the background and the foreground, the images assume that color index 0 is the first index in their palette. So, the sprites would use indexes 0-99, while the background would use 0-155, while I want the background to use 100-155. That would explain why the background is using the colors for the foreground sprites. I made a (very slow) workaround that loops through every pixel in the background and adds 100 to it, and that makes it work OK.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement