在OpenGL中围绕其中心旋转纹理的问题

时间:2011-11-10 06:42:53

标签: android opengl-es

我正在尝试围绕其中心旋转纹理,并且我已经通过此代码实现了但是在旋转时图像也​​以某个角度显示(因此图像在某些角度看不到正确),如附图所示帮我解决这个问题

这是我的代码

    public void onSurfaceChanged(GL10 gl, int width, int height) {
    gl.glViewport(0, 0, width, height);
    gl.glOrthof(0, 320, 0, 480, 0, 1);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glEnable(GL10.GL_TEXTURE_2D);

}

正方形的顶点是

float vertices[] = {

                -.25f,.25f,0,
                -.25f,-.25f,0,
                .25f,.25f,0,
                .25f,-.25f,0
        };

这是我的绘制方法

public void draw(GL10 gl) {
        gl.glPushMatrix();



        gl.glTranslatef(-.125f, -.125f, 0f);
        gl.glRotatef(r,0, 0,-1 );
        gl.glTranslatef(.125f, .125f, 0);

        // Point to our buffers 
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        // Set the face rotation
        gl.glFrontFace(GL10.GL_CW);

        // Point to our vertex buffer
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexbuffer);
        gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texturebuffer);
        // Draw the vertices as triangle strip
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

        //Disable the client state before leaving
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        r = r+1;
        gl.glPopMatrix();

    }

enter image description here

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

看起来你的纹理坐标可能只是引用太多的纹理 - 如果你的代码的某些部分填充非二次幂图像到两个纹理的大小,但是不会传递相关知识。因此,您可以围绕纹理的中心旋转,但实际图像仅使用纹理角落的一部分。

我无法在示例代码中看到任何内容,以显示您是如何加载图片的,或者是将值放入texturebuffer的人,但这些是明智的区域。

相关问题