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.
Animating a texture in OpenGL
Moderator: Coders of Rage
-
- 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
What do you call a cow with no legs?
Ground beef.
Ground beef.
Re: Animating a texture in OpenGL
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].
Edit: for newer OpenGL versions use your own varying instead of gl_TexCoord[0].
-
- 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
I'm not using shaders though. I'm learning OpenGL first. GLSL comes later.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.
What do you call a cow with no legs?
Ground beef.
Ground beef.
Re: Animating a texture in OpenGL
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.