PDA

View Full Version : Creating a texture from a color indexed image?


esrix
01-02-2006, 10:01 PM
This is indeed, going to sound very strange and unorthodox. But please know that there is method to my madness :)

I've been doing some R&D and graphical coding for a game with 2D sprites on a 3D environment ( I believe the expression is called "2-and-a-half-D"). Our game designer wants to use high-resolution sprites (512x512 pixels for each frame for each sprite!).

So, after some griping and toiling and posting on this forum, I managed to get the 512x512 sprites working with most memory issues resolved using SDL and some customized functions while running at a pretty decent speed (I'd explain this concept more, but it's too late at night).

The thing is, we've managed to make it as fast as it is now by using PNG images with a color index. Meaning the pixels in the SDL_Surface are referencing the color values from a palette, not really holding real color values in memory. It's much faster doing it this way instead of trying to load a full-on 32 PNG bit image at such a resolution.

However, this has now caused us a major problem. As far as I know, OpenGL uses 24 and 32 bit color and is not very supportive of color indexed textures.

I managed to write a function that gets around this... however, the function is too slow. While our loading and re-loading of sprite images manages a good 2-5 milliseconds each, the conversion from indexed image to 24/32 bit texture is a good 14-16 milliseconds! And we have more than one active sprite on the screen.

I know it sounds crazy, but as of now, this is the one obstacle standing between us and really nice looking sprites. So I was wondering if anyone has encountered a similar problem with OpenGL textures and indexed color images and, if so, how they managed to get around it?

luggage
01-02-2006, 10:28 PM
Haven't got an answer but I do have a question about the 512x512 sprites.

What res are you running in? Say you're using 640x480 then aren't you going to be losing detail if your 512x512 sprite is drawn with a pixel size of 32x32? ie. what's the point in having textures stored at a res greater than the one you're ever going to show?

esrix
01-02-2006, 10:46 PM
The plan is to run at 800x600 with the capability of zooming and out of the action (it's a fighting game). Exactly how close it will get, I don't know yet. Our designer keeps some of those details to himself.

Also, I'd be lying if I was making this whole situation out to be his fault. I'm actually enjoying some of this problem solving, so part of having such a large texture data is because it's a bit of a challenge to me :) I'm such an ass.

Our hope is to get something close to, if not above, the artistic quality of a Playstation 2 game called Guilty Gear, which has some pretty large sprites-256x512 is what I found one sprite ripped from the game to be.

So, really, they don't need to be so big. However, we'd like them to be that size if possible.

mr n00b
01-03-2006, 01:34 AM
There is an OpenGL extension that handles indexed textures:

http://oss.sgi.com/projects/ogl-sample/registry/EXT/paletted_texture.txt

I don't know how well supported it is though. You'd probably be better of using S3TC (known as DXTC in DirectX):

http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_compression_s3tc.txt

DXT1 compression uses 4 bits per pixel and DXT3 and DXT5 uses 8 bits per pixel but gives higher quality alpha.

Using indexed textures is slow (in a relative sense), DXTC textures are _much_ faster to render.

/mr n00b

esrix
01-16-2006, 12:17 AM
Thought I'd give you guys an update on what happened:

I've found a way around the problem using SDL still. I made an 32 surface of the same size of the indexed image and blit the indexed image to the new surface using SDL_BlitSurface. It runs much faster now.

Sorry, didn't mean to bump this