Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I flip a sprite/texture in OpenGLES?

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?

like image 370
Mark S. Avatar asked Sep 19 '08 16:09

Mark S.


1 Answers

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 :)

like image 177
Ivan Vučica Avatar answered Sep 22 '22 13:09

Ivan Vučica