Search code examples
c++animationopenglsdlglew

How to handle texture animation in OpenGL?


I started using OpenGL with SDL2 and GLEW not so long ago, and I got two questions:

  • How to pass a texture to GLSL's uniform sampler2D ? It seems to do it automatically when binded, but it confuses me.

And the main question here:

  • What's the best way to handle texture animation? Should I do it by GL_TEXTURE_3D? By loading all frames into multiple GL_TEXTURE_2D? Is there a built-in way for animation?

Solution

  • glActiveTexture and glBindTexture calls in this order will bind a texture to the given sampler slot.

    Use a spritesheet as a TEXTURE_2D, and change the texture coordinates for swapping the animation frames.