I am learning how to use a sprite sheet to animate a sprite, are there any good tutorials that would help me or do you have any suggestions for me. I am using SOIL and opengl and c++.
sprite sheet
Hey phil67rpg!
I believe you can just do it the regular way and change it so that rendering is handled by OpenGL. Here's an example done with SFML.
https://github.com/SFML/SFML/wiki/Source:-AnimatedSprite
25 Things Game Developers Should Stop Doing (Free PDF)
31 minutes ago, phil67rpg said:hey retrometron do you have any suggestions
Did the example code @Ianuarius provided not give you enough of an idea to write your own? In total it looks to be about 200-300 lines of code. Should be quite easy to follow and port to your own needs.
"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin
On 9/3/2018 at 5:54 PM, phil67rpg said:I am learning how to use a sprite sheet to animate a sprite, are there any good tutorials that would help me or do you have any suggestions for me. I am using SOIL and opengl and c++.
In Photoshop, GIMP, ect... or whatever you use make a document size that follows the power of 2 rule then put your animation strip in the document. Once you have an object that represents your player or whatever it is you'll need to track the current draw area based on the frame you're on, and each "frame" will be a section of the texture file.
Frames usually alternate based on a timer. For example when you move right you run a timer that swaps frames every (x) milliseconds.
Is there something in the link above which @Ianuarius posted that you're having trouble with specifically?
Programmer and 3D Artist
well I am able to draw a single sprite using SOIL and opengl and c++ I am trying to draw sprites using a sprite sheet. I am however able to draw the entire sprite sheet to the screen. I have been doing a lot of research on google. here is some of my code
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(-1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glEnd();
glutSwapBuffers();
}
I've read it over. You don't actually ask a question and instead merely write that you're having problems, but that seems to be your writing style. Do you have a question about that code?
Assuming you have a question about the code and simply forgot to ask it, look at the lines GlTexCoord2f(). Explain what those coordinates are for, what they do, and how they work. That will answer the questions you are probably facing next.