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.

Graphics > sprite palettes

#167667 - moonlightcheese - Sat Mar 21, 2009 5:33 pm

so basically, i've only got 512 bytes of sprite palette memory, right? so if i want more than one 256 color sprite on the screen, i have to use the same color palette, right? what if i don't want to use the same color palette? am i doomed to using several 16 color sprites?

i notice that when wingrit makes 256 color sprites with tile and palette output that the palette doesn't really use 256 colors, so i'm thinking i can make more 256 color sprites in this manner and add the palettes together, placing each palette at some offset and editing the image to contain the correct offset but... as you would guess... editing all those images would be a painstaking process. i could write a script, but is there no way to do this with tools available on the interwebs?

edit: also, is there an easy way to add two hex values? can i just use the regular old '+' operator or will i have to build a hex addition function myself?

#167670 - Kyoufu Kawa - Sat Mar 21, 2009 7:30 pm

moonlightcheese wrote:
edit: also, is there an easy way to add two hex values? can i just use the regular old '+' operator or will i have to build a hex addition function myself?
You mean 0x4 + 0x10 = 0x14? I fail to see how that'd be any different from 4 + 10 = 14, aside from the fact 0x10 and 0x14 are way different values from 4 and 10...

#167671 - moonlightcheese - Sat Mar 21, 2009 7:47 pm

Kyoufu Kawa wrote:
moonlightcheese wrote:
edit: also, is there an easy way to add two hex values? can i just use the regular old '+' operator or will i have to build a hex addition function myself?
You mean 0x4 + 0x10 = 0x14? I fail to see how that'd be any different from 4 + 10 = 14, aside from the fact 0x10 and 0x14 are way different values from 4 and 10...

because 9+9=18 but 0x9+0x9=0x12... check your math...

in any event, i've figured that out... the addition operator works fine for hex. tried 0xA+0xA and got 0x0014 for output, so that's one hurdle i don't have to jump.

edit: not trying to be rude or anything. i just wanted to make sure that i didn't have to overload the '+' operator to make it work for hex addition. didn't know if gbalib could do radix 16 operations all by itself.

#167672 - DiscoStew - Sat Mar 21, 2009 8:21 pm

Yeah, as long as you can interpret the hexadecimal values correctly, there should be no problem working with them like you would with decimal values.

As for palettes, you could try something along the lines of multiple 4-bit palettes for a single sprite. Each 8x8 block of the sprite would still be limited to 15 colors + 1 transparent, but each block would not be using the same 4-bit palette. Each 4-bit palette could have a few similar colors, but the rest are unique to that palette. Gives the overall sprite the illusion of a slightly less detailed 8-bit image without having the limitation of a direct 8-bit palette.
_________________
DS - It's all about DiscoStew

#167682 - Miked0801 - Sun Mar 22, 2009 5:15 am

or hblank swap palettes on scanlines. Usually way more trouble than its worth.

#167686 - Cearn - Sun Mar 22, 2009 10:48 am

moonlightcheese wrote:
Kyoufu Kawa wrote:
moonlightcheese wrote:
edit: also, is there an easy way to add two hex values? can i just use the regular old '+' operator or will i have to build a hex addition function myself?
You mean 0x4 + 0x10 = 0x14? I fail to see how that'd be any different from 4 + 10 = 14, aside from the fact 0x10 and 0x14 are way different values from 4 and 10...

because 9+9=18 but 0x9+0x9=0x12... check your math...

in any event, i've figured that out... the addition operator works fine for hex. tried 0xA+0xA and got 0x0014 for output, so that's one hurdle i don't have to jump.

edit: not trying to be rude or anything. i just wanted to make sure that i didn't have to overload the '+' operator to make it work for hex addition. didn't know if gbalib could do radix 16 operations all by itself.
I think you may be missing the point here. There is no such thing as decimal addition or hex addition, there is just number addition. Decimal and hex are merely different ways of writing down numbers and math is independent of that. 18 and 0x12 are both eighteen :

***** **** + ***** **** = ***** ***** ***** ***
That they look different when written down is a matter of reordering.

Decimal : 10 + 8 = 18
***** *****
***** ***

Hexadecimal: 10h + 2h = 12h
******** ********
**

Octal : 2*10o + 2o = 22o
********
********
**

The rules you learn in school for arithmetic are just shortcuts for this process, with lookup tables for addition and multiplication. Hex works the same way, just with different lookup tables.

This isn't just pedantry here; understanding that the same data can be represented in various different ways can help you immensely when programming. Pointer casting is a good example of this, as is how the meaning of VRAM differs according to the video mode and how a single 256-color palette can also be used as 16 separate 16-color palettes.[/quote]

moonlightcheese wrote:
so basically, i've only got 512 bytes of sprite palette memory, right? so if i want more than one 256 color sprite on the screen, i have to use the same color palette, right? what if i don't want to use the same color palette? am i doomed to using several 16 color sprites?
Remember that sprites are generally quite small. A single 8x8 tile could use at maximum 64 different colors, and in most cases many pixels will share the same color, so having only 16 to choose from isn't as bad as you may think.

moonlightcheese wrote:
i notice that when wingrit makes 256 color sprites with tile and palette output that the palette doesn't really use 256 colors, so i'm thinking i can make more 256 color sprites in this manner and add the palettes together, placing each palette at some offset and editing the image to contain the correct offset but... as you would guess... editing all those images would be a painstaking process. i could write a script, but is there no way to do this with tools available on the interwebs?
256 color sprite is somewhat of a misnomer. What's really going on is that the tiled graphics have either 4 bits per pixel or 8 bits per pixel, which allows for 16 or 256 different values, respectively. These are the maximum number of colors that can be used for each case; it doesn't mean that a sprite actually uses that many colors.

While gfx2gba and grit can merge the colors of different images into a single 256 color palette, it may be better to use the same basic palette for all the images in the first place. That way you'll know when you max out the colors. The safest way to force all the sprites to use the same palette is probably to create all the graphics on a single sprite sheet and then either cut them up later or selectively export different rectangles. I'm unaware of tools that can do this automatically, but they're probably out there somewhere.