Animating a texture in OpenGL

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
corey__cakes
ES Beta Backer
ES Beta Backer
Posts: 23
Joined: Mon Dec 23, 2013 7:56 pm
Current Project: Canadian Simulator 2017
Favorite Gaming Platforms: GBA, DC, iOS, SNES, WS, 360, N64
Programming Language of Choice: C++, Lua
Location: Your VCR.

Animating a texture in OpenGL

Post by corey__cakes »

Hello,

I have a question. What is the best way to animate a sprite from a sprite sheet loaded in as an OpenGL texture? The only ways I could think of were to change the values used in glTexCoord*() or to switch the matrix mode to GL_TEXTURE and then use glTranslate*(). What other ways are there?

Right now I am learning OpenGL by reading through the "red book." I'm using SDL to create my context, as well as for event handling, and texture loading. I mostly want to learn 2D graphics and engine development with OpenGL before I step into the 3rd dimension.

I would also appreciate any good books/websites you may know of that can teach me more about graphics programming and engine development. The OpenGL Red Book is only helpful to learning about OpenGL and not computer graphics in depth.

Thank you.
What do you call a cow with no legs?

Ground beef.
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Animating a texture in OpenGL

Post by K-Bal »

You can give your shader some uniforms that define which part of the texture to use and use them to calculate the value of gl_TexCoord[0] in your shader. Manipulating the texture matrix is also possible but I find the uniform approach more straight-forward.

Edit: for newer OpenGL versions use your own varying instead of gl_TexCoord[0].
corey__cakes
ES Beta Backer
ES Beta Backer
Posts: 23
Joined: Mon Dec 23, 2013 7:56 pm
Current Project: Canadian Simulator 2017
Favorite Gaming Platforms: GBA, DC, iOS, SNES, WS, 360, N64
Programming Language of Choice: C++, Lua
Location: Your VCR.

Re: Animating a texture in OpenGL

Post by corey__cakes »

K-Bal wrote:You can give your shader some uniforms that define which part of the texture to use and use them to calculate the value of gl_TexCoord[0] in your shader. Manipulating the texture matrix is also possible but I find the uniform approach more straight-forward.
I'm not using shaders though. I'm learning OpenGL first. GLSL comes later.
What do you call a cow with no legs?

Ground beef.
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Animating a texture in OpenGL

Post by K-Bal »

The two ways you describe should work, just use one of them. I don't know of more options off the top of my head.
Post Reply