Loading sprites from a large image.

Started by
3 comments, last by CodeZero 18 years, 9 months ago
What would be the easiest way to go about accessing the individual 32 X 32 sprites that are contained in a single, large BMP?
Advertisement
What API are you using? It pretty much differs per API. On DirectX you can supply a RECT from where the texture will be blit.

Toolmaker

OpenGL is what I'm using. In the past I've loaded all my images in RAW format. The fact that it's a BMP shouldn't matter though, since I can convert it into RAW. I'm guessing that there are OpenGL specific routines that will access certain areas of the data once it's loaded in.
LOAD INTO MEMORY
Load the bitmap into memory using auxDIBImageLoad (found in glaux.h). Note that you may be restricted to only using bitmap files whose dimensions are powers of 2. This depends on your machine and the version of OpenGL you are using.

GENERATE TEXTURE
You can generate a texture which provides access to the whole bitmap using glGenTextures and glTexImage2D. glIsTexture is a useful function if you would like to see if texture generation was successful.

BIND TEXTURE COORDINATES TO VERTICES
You can then bind regions of your bitmap to a vertex using glTexCoord. (NOTE: I find it better to use glTexCoord3f because the integer version will differ depending on filesize whereas floats always range from 0 to 1 and don't depend on file-size)

Mark
I guess I hadn't thought of just adjusting the texture coordinates. Thanks for the suggestion.

Jake

This topic is closed to new replies.

Advertisement