0

我想移动一个设置屏幕坐标的纹理,如 270,320 。现在我像这样渲染纹理设置opengl坐标(0到1):

private final float[] mVerticesData =
        { 
            -1f, 1f, 0.0f, // Position 0
            0.0f, 1.0f, // TexCoord 0
            -1f, -1f, 0.0f, // Position 1
            0.0f, 0.0f, // TexCoord 1
            1f, -1f, 0.0f, // Position 2
            1.0f, 0.0f, // TexCoord 2
            1f, 1f, 0.0f, // Position 3
            1.0f, 1.0f // TexCoord 3
        };
mVertices = ByteBuffer.allocateDirect(mVerticesData.length * 4)
                    .order(ByteOrder.nativeOrder()).asFloatBuffer();
            mVertices.put(mVerticesData).position(0);

并使用以下代码进行渲染。我没有设置任何矩阵或任何东西......

// Set the viewport
        GLES20.glViewport(0, 0, SimpleTexture2D.screenSize.x, finalHeight);


    //GLES20.glViewport(0, 0, mWidth, mHeight);


    // Clear the color buffer
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    if(useProgram2 == true)
    // Use the program object
    GLES20.glUseProgram(mProgramObject2);
    else
        GLES20.glUseProgram(currentFilter.mProgramObject);

    // Load the vertex position
    mVertices.position(0);
    GLES20.glVertexAttribPointer ( mPositionLoc, 3, GLES20.GL_FLOAT, 
                                   false, 
                                   5 * 4, mVertices );

    // Load the texture coordinate
    mVertices.position(3);
    GLES20.glVertexAttribPointer ( mTexCoordLoc, 2, GLES20.GL_FLOAT,
                                   false, 
                                   5 * 4, 
                                   mVertices );

 // Load the texture coordinate
//        mVertices.position(3);
//        GLES20.glVertexAttribPointer ( mTexCoordLoc2, 2, GLES20.GL_FLOAT,
//                                       false, 
//                                       5 * 4, 
//                                       mVertices );

        GLES20.glEnableVertexAttribArray ( mPositionLoc );
        GLES20.glEnableVertexAttribArray ( mTexCoordLoc );


    // Bind the texture
    //GLES20.glActiveTexture ( GLES20.GL_TEXTURE0 );


    //if(drawOld == true)

        GLES20.glActiveTexture ( GLES20.GL_TEXTURE0 );
        GLES20.glBindTexture ( GLES20.GL_TEXTURE_2D, mTextureId);

        GLES20.glUniform1i ( mTextureIdLoc, 0 );




    currentFilter.onDrawFrame();

    // Set the color matrix uniform unit to 1

    GLES20.glDrawElements ( GLES20.GL_TRIANGLES, 6, GLES20.GL_UNSIGNED_SHORT, mIndices );

任何帮助

4

1 回答 1

0

您可能正在寻找 glOrthof(.0, .0, screenWidt, screenHeight...) 而不是视口。视口通常设置为绘制整个缓冲区,并设置为从 0 到缓冲区尺寸。另一方面,“Ortho”将告诉您要渲染到的视图边界的坐标。

于 2012-08-21T11:11:55.477 回答