Sprite Sheets

I don’t get how you could use one image of a bunch of different sprites with a black background, and use that one image of all the sprites to incorporate each sprite into a game individually. How does that work?

You load you image with your sprites into openGL as a texture.

Then with texture mapping, you can tell openGL what part of an texture(image) to map to a quads surface.

Look at nehe.gamedev.net on textured mapped font’s, this should give you an idea on the loading and also his example of creating sprite type objects.

Originally posted by Krak:
I don’t get how you could use one image of a bunch of different sprites with a black background, and use that one image of all the sprites to incorporate each sprite into a game individually. How does that work?

Originally posted by nexusone:
[b]You load you image with your sprites into openGL as a texture.

Then with texture mapping, you can tell openGL what part of an texture(image) to map to a quads surface.[/b]

Any particular functions you’d use to do this?

Originally posted by Krak:
[b] Any particular functions you’d use to do this?

[/b]

There is a good number of functions used in setting up an texture and then mapping it out. You will be best served to do as I suggested and go to the nehe.gamedev.net website and go through his tutors on loading a texture and then texture mapped fonts.

Here is an example code of how I read the diffrent sprites from the texture.

I have the sprites setup in equal square spaces, on the texture. pose is image position along the column and frame is row position. One texture holds a 8 colunms x 8 rows of sprites, you can adjust the maping to any column/row configuration.

void draw_badguy(int pose, int frame)
{

float ex = pose * 0.125f;
float ey = frame * 0.125f;

glBindTexture(GL_TEXTURE_2D, texture_id[0]);
glBegin(GL_QUADS);
glTexCoord2f(ex+0.125f,1.0f-(ey +0.125f ) ); glVertex3f(-1.0f,-1.0f,0.0f);
glTexCoord2f(ex,1.0f-(ey+0.125f )); glVertex3f( 1.0f,-1.0f,0.0f);
glTexCoord2f(ex,1.0f-(ey)); glVertex3f( 1.0f, 1.0f,0.0f);
glTexCoord2f(ex +0.125f,1.0f-(ey )); glVertex3f(-1.0f, 1.0f,0.0f);
glEnd();

}