开发者

How to flip an Image in OpenGL?

开发者 https://www.devze.com 2023-04-06 05:43 出处:网络
I hate to ask such a dumb question but I just can\'t firgure out how to flip an image using Android OpenGL.

I hate to ask such a dumb question but I just can't firgure out how to flip an image using Android OpenGL.

I tr开发者_运维技巧y using gl.glScalef(-1,y,z) android gl.glRotatef(180,0,1,0) but when I do this the image flip but it also change the positions which I do not want. I'm sure there a easy way to do this I'm just not getting.

Here is my draw code:

public void draw(GL10 gl){
    gl.glLoadIdentity();
    gl.glTranslatef(position.x, position.y, 0);
    gl.glRotatef(angle, rotX, rotY, rotZ);
    gl.glScalef(scaleX, scaleY, scaleZ);

    gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId[0]);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glEnable(GL10.GL_BLEND);

    gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexsBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);

    gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer);

    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glDisable(GL10.GL_BLEND);

    if(animation == true){
        PlayAnimations();
    }
}


  1. center the object (remember the translation)
  2. perform the flipping by scaling to -1 with respect to the desired axis.
  3. then "reverse translate" the object.

For more information, please grab yourself a copy of Computer Graphics by James D. Foley. http://www.amazon.com/Computer-Graphics-Principles-Practice-2nd/dp/0201848406


You could use a different set of texture coordinates or use a texture matrix.

0

精彩评论

暂无评论...
验证码 换一张
取 消