1

我正在使用 Open GL ES 在 Android 中工作。我一直在尝试将我们的 UI 从 Android 视图移动到 3D。我看到顶点放置有一些奇怪的行为。

我有两个不同的四边形。一个是 -0.5,-0.5 -> 0.5,0.5,另一个是 0,0 -> 1,1 但是当我渲染它们时,它们都出现在彼此之上。好像它们都是 0,0 -> 1,1(正交投影设置为从 0,0 到 1,1)。它们都是通过同一管道发送的,所以我不确定这是怎么发生的。

另一个奇怪且可能相关的问题。将其中一个四边形平移 0.5 将其完全移动到屏幕上,而不是像我预期的投影 0,0 -> 1,1 的一半。

以下是 Java 中的一些片段...

//固定点类 public static final int FIXED_POINT = 16;

public static final int ONE = (1 << FIXED_POINT);
public static final int HALF = (ONE >> 1);

//顶点设置 mNumVerts = 6;

    ByteBuffer vbb = ByteBuffer.allocateDirect( mNumVerts * 2 * 4 );
    vbb.order( ByteOrder.nativeOrder() );
    mVtxBuf = vbb.asIntBuffer();

    vbb = ByteBuffer.allocateDirect( mNumVerts * 2 * 4 );
    vbb.order( ByteOrder.nativeOrder() );
    mTexBuf = vbb.asIntBuffer();

    mVtxBuf.put( -Fixed32.HALF ); mVtxBuf.put( -Fixed32.HALF ); mTexBuf.put( 0 ); mTexBuf.put( Fixed32.ONE );
    mVtxBuf.put(  Fixed32.HALF ); mVtxBuf.put( -Fixed32.HALF ); mTexBuf.put( Fixed32.ONE ); mTexBuf.put( Fixed32.ONE );
    mVtxBuf.put(  Fixed32.HALF ); mVtxBuf.put(  Fixed32.HALF ); mTexBuf.put( Fixed32.ONE ); mTexBuf.put( 0 );

    mVtxBuf.put( -Fixed32.HALF ); mVtxBuf.put( -Fixed32.HALF ); mTexBuf.put( 0 ); mTexBuf.put( Fixed32.ONE );
    mVtxBuf.put(  Fixed32.HALF ); mVtxBuf.put(  Fixed32.HALF ); mTexBuf.put( Fixed32.ONE ); mTexBuf.put( 0 );        
    mVtxBuf.put( -Fixed32.HALF ); mVtxBuf.put(  Fixed32.HALF ); mTexBuf.put( 0 ); mTexBuf.put( 0 );

    mVtxBuf.position( 0 );        
    mTexBuf.position( 0 );

//和....

    mVtxBuf.put( 0 ); mVtxBuf.put( 0 ); mTexBuf.put( 0 ); mTexBuf.put( Fixed32.ONE );
    mVtxBuf.put( Fixed32.ONE ); mVtxBuf.put( 0 ); mTexBuf.put( Fixed32.ONE ); mTexBuf.put( Fixed32.ONE );
    mVtxBuf.put( Fixed32.ONE ); mVtxBuf.put( Fixed32.ONE ); mTexBuf.put( Fixed32.ONE ); mTexBuf.put( 0 );

    mVtxBuf.put( 0 ); mVtxBuf.put( 0 ); mTexBuf.put( 0 ); mTexBuf.put( Fixed32.ONE );
    mVtxBuf.put( Fixed32.ONE ); mVtxBuf.put( Fixed32.ONE ); mTexBuf.put( Fixed32.ONE ); mTexBuf.put( 0 );        
    mVtxBuf.put( 0 ); mVtxBuf.put( Fixed32.ONE ); mTexBuf.put( 0 ); mTexBuf.put( 0 );

    mVtxBuf.position( 0 );        
    mTexBuf.position( 0 );

//投影设置

                gl.glMatrixMode( GL10.GL_PROJECTION );
                gl.glLoadIdentity();
                gl.glOrthox( 0, Fixed32.ONE, 0, Fixed32.ONE, -Fixed32.ONE, Fixed32.ONE );

//使成为

                {
                    gl.glDisableClientState( GL10.GL_NORMAL_ARRAY );

                    gl.glScalef( thing.getXScale(), thing.getYScale(), thing.getZScale() );
                    gl.glTranslatef( thing.getX(), thing.getY(), thing.getZ() );

                    gl.glFrontFace( GL10.GL_CW );
                    gl.glVertexPointer( 2, GL10.GL_FIXED, 0, mdl.getVtxBuf() );
                }


                gl.glTexCoordPointer( 2, GL10.GL_FIXED, 0, mdl.getTexBuf() );
                // gl.glColorPointer( 4, GL10.GL_FLOAT, 0, mColorBuffer );
                gl.glDrawArrays( GL10.GL_TRIANGLES, 0, mdl.getVtxCount() );    
4

1 回答 1

1

正如你们中的许多人可能已经猜到的那样,我一定错过了什么。在我的对象超类中逐帧编辑顶点,以处理纵横比的老问题。因此,顶点并不是真正的 -.5,-.5 - .5,.5,它们都被重置为 0,0-1,1。谢谢你的时间。

于 2011-03-06T22:54:25.173 回答