Opengl渲染纹理与屏幕坐标

时间:2012-08-21 00:59:29

标签: opengl-es

我想将纹理设置移动到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 );

任何帮助

1 个答案:

答案 0 :(得分:0)

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