sprite sheet

well I am using opengl and soil and c++. I am trying to use a sprite sheet to animate a 2D sprite. here is the code I am using. I am able to draw a single sprite to the screen, however I am making progress.


int LoadGLTextures()
{
	texture[0] = SOIL_load_OGL_texture
	(
		"planesheet.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_INVERT_Y|SOIL_FLAG_POWER_OF_TWO|SOIL_FLAG_TEXTURE_REPEATS
	);

	if (texture[0] == 0)
		return false;

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	return true;
}

void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);

	glEnable(GL_TEXTURE_2D);

	glGenTextures(8, &texture[1]);
	glBindTexture(GL_TEXTURE_2D,texture[0]);

	glBegin(GL_QUADS);
	glTexCoord2f(0.0f, 0.0f); 
	glVertex3f(-10.0f, -10.0f, 0.0f);
	glTexCoord2f(1.0f, 0.0f); 
	glVertex3f(-10.0f, 10.0f, 0.0f);
	glTexCoord2f(1.0f, 1.0f); 
	glVertex3f(10.0f, 10.0f, 0.0f);
	glTexCoord2f(0.0f, 1.0f); 
	glVertex3f(10.0f, -10.0f, 0.0f);
	glEnd();

	glutSwapBuffers();
}

can I please get some help on using a sprite sheet

What is your question?
You have not asked anything.

how does one use soil to draw a sprite from a sprite sheet, I am adjusting the glTexCoord3f function, but cannot get the sprite to render properly. how does soil read the png files.

Right, but what does SOIL, or whatever image loader you use, have to do with this? I mean yes, you need some way to load an image. But once that image is in a texture, the image loader no longer has anything to do with it.

Are you able to load and display an image? If so, are you able to load and display part of an image? If so, are you able to load and display any part of that image you so desire? And if you can do all of those things… then you already have everything you need to use a sprite sheet.

So which part are you hung up on?

[ATTACH=CONFIG]1851[/ATTACH]I am able to load an image when I am using glTexCoord2f(1.0f,1.0f); I am also able to load part of an image using glTexCoord2f(0.125,0.125); however I am unable to load the part of the image I want. here is a screenshot.

I am able to load an image when I am using glTexCoord2f(1.0f,1.0f);

First, a matter of terminology: glTexCoord2f has nothing to do with “loading an image”. That is part of how you display the image or a portion thereof.

Next, so you know that by manipulating the values you provide to glTexCoord2f, that you can manipulate the portion of the image that gets rendered. Have you tried playing around with those numbers? Do you see any pattern, any relationship between the numbers you provide and what portion of the image gets displayed? And have you tried changing the coordinates that are given 0 values as well?

Take some time to explore the space of what you’re doing here.

well here is code I am using it almost draws what I want it to do. here is a screenshot[ATTACH=CONFIG]1852[/ATTACH]it draws two triangles where the image wraps around itself.

well I finally solved my problem, thanks alfonse

I have also figured out how to animate a 2d plane sprite

well I have figured out how to rotate two plane sprites and move them around the screen, I am able to move a plane up and shoot bullets, I cant get the bullets to move down the screen.