Hello Guest

2D Graphics and Palette-swapping

  • 5 Replies
  • 7057 Views
2D Graphics and Palette-swapping
« on: June 01, 2006, 13:58:40 »
I'm trying to make a 2D fighting-game-engine, and need to allow for the colors of sprites to be changed dynamically.  I think that if I directly manipulated the User Space (which I think is a raster) I could have quick palette-shifting.

Long loops, even of simple tasks, are often inefficient; but they seem to be how screen-pixels are updated. If such a method isn't used, what is: hijacking such a low-level aspect of Java should cost me hardware acceleration, so I need to know this?

2D Graphics and Palette-swapping
« Reply #1 on: June 02, 2006, 22:17:49 »
You just want to be able to handle Scorpion, Reptile, Noob Saibot, Smoke, Sub-zero et al :)

Sorry, can't help otherwise.

Bill
the2bears - the indie shmup blog

*

Offline oNyx

  • ***
  • 177
  • 弾幕
2D Graphics and Palette-swapping
« Reply #2 on: June 03, 2006, 04:51:30 »
There is some extension for palette stuff, but it isnt available usually. And well, there are shaders...

But there is actually some low tech solution ;)

What you need are extra sprite sheets, which only contain the areas which you want to tint in different colors (the rest is transparent). Then you simply draw the base sprite, pick the tint color (instead of white) and draw that extra layer on top. Pretty simple and damn fast.

The disadvantage compared to palette voodoo is that you need to create extra spritesheets. The advantage, however, is that antialiasing and/or simple shading (shadows/highlights) are easier to do.

2D Graphics and Palette-swapping
« Reply #3 on: June 06, 2006, 03:05:54 »
Is there any restriction on the size of a texture: like it's size having to be a power of two, or something?

hmmmmmmm...
« Reply #4 on: June 06, 2006, 13:28:28 »
The short answer is Yes. The textures need to be power-of-2 and probably not bigger then 4096 (most cards don't support this high).
You can get the maximum size by calling
Code: [Select]
glGetInteger(GL_MAX_TEXTURE_SIZE, intBuff16);


There is an extension to use non-power-of-2 textures, but I'm not sure how supported it is.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

*

Offline oNyx

  • ***
  • 177
  • 弾幕
2D Graphics and Palette-swapping
« Reply #5 on: June 06, 2006, 19:32:38 »
Oh and power of two means that each dimension on its own should be power of two. So, rectangular textures (128x512 for example) are fine, too.

NPoT textures sorta kinda work with lots of hardware, but the sampling points are often a tad off... resulting in odd glitches (not noticable in 3d tho).

http://kaioa.com/k/badsample.png

PoT on the left and NPoT on the right (zoomed in of course).

For that reason I enlarge textures to the next PoT on the fly (during loading time) and recalculate the texture coords accordingly.