Question

I have a sprite loaded as a texture and I need to animate it, allowing it to "face" left or right -- essentially sometimes I need to "flip" it. I know that OpenGL has a gltranslate which repositions an object, and glrotate which rotates it. Is there a method that simply flips it across one axis? If not, how would you accomplish this?

Was it helpful?

Solution

I haven't messed around with point sprites, but I believe that they are textures. Textures have texture matrices, which means you can use glTranslatef(), glScalef() and glRotatef() on them.

I would try out something along the lines of glScalef(-1,1,1); which would flip the texture coordinate by the X axis.

As I said, I haven't played with point sprites, but I didn't mess with texture matrices either. They do seem quite useful, though.

Update: I have played with texture matrices in the meantime. In the same way that you switch between modelview and projection matrices, you can switch to texture matrix; approximately: glMatrixMode(GL_TEXTURE); after which you can do the aforementioned operations.

You could also just paint a quad/two triangles and be done with it :)

OTHER TIPS

You can't do this with OpenGL point-sprites; although you can move the center of the sprite around, the shape of it is always oriented the same way.

What you can do is draw your sprites as quads, which lets you flip, rotate and mess with them any way you want. There are tutorials on manually drawing sprites (aka billboards) on NeHe

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top