Creating a texture from a color indexed image?

Discussion in 'Game Development (Technical)' started by esrix, Jan 3, 2006.

  1. esrix

    Original Member

    Joined:
    Aug 11, 2005
    Messages:
    143
    Likes Received:
    0
    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?
     
  2. luggage

    Moderator Original Member Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    2,132
    Likes Received:
    0
    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?
     
  3. esrix

    Original Member

    Joined:
    Aug 11, 2005
    Messages:
    143
    Likes Received:
    0
    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.
     
  4. mr n00b

    Original Member

    Joined:
    Sep 9, 2005
    Messages:
    40
    Likes Received:
    0
    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
     
  5. esrix

    Original Member

    Joined:
    Aug 11, 2005
    Messages:
    143
    Likes Received:
    0
    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
     
    #5 esrix, Jan 16, 2006
    Last edited: Jan 16, 2006

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer