Skip to content

Instantly share code, notes, and snippets.

@Shaptic
Created February 10, 2013 22:31
Show Gist options
  • Save Shaptic/4751336 to your computer and use it in GitHub Desktop.
Save Shaptic/4751336 to your computer and use it in GitHub Desktop.
Swap out sprite sheets on the fly.
void CAnimation::SwapSpriteSheet(const AnimationHeader& Header)
{
// New texture for the renderer and new dimensions for the shader.
m_Mesh.GetSurfaces()[0]->pMaterial->pTexture = Header.pTexture;
m_TexcDim = math::vector2_t(1.f / Header.columns, 1.f / Header.rows);
m_SheetDetails = Header;
m_loops_done = 0;
// Adjust shader for new texture dimensions.
gfx::CShaderPair* pShader = m_Mesh.GetSurfaces()[0]->pMaterial->pShader;
pShader->Bind();
glUniform2f(m_tc_loc, m_TexcDim.x, m_TexcDim.y);
pShader->Unbind();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment