Opengl es 使用屏幕坐标的Opengl渲染纹理

Opengl es 使用屏幕坐标的Opengl渲染纹理,opengl-es,Opengl Es,我想移动一个纹理设置屏幕坐标像270320。 现在我正在渲染纹理设置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, //

我想移动一个纹理设置屏幕坐标像270320。 现在我正在渲染纹理设置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 );

任何帮助

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

es 2.0Ah中没有glOrthf,对不起。。。不过,您可以在几行中创建它。。也许我要求的太多了,但假设我有一个接触点=120200。我如何通过矩阵将其转换为opengl坐标?。示例代码将非常感谢我不能给你示例代码,因为我没有办法。。如果您只是使用2D,其中触摸坐标为rect(.0.0,screenWidth,screenHeight)和GLRect(-1.0,-1.0,1.0,1.0,1.0),则转换为GLPoint.x=(touch.x/screenWidth*2-1.0)GLPoint.y=(1.0-touch.y/screenHeight*2)如果您使用3d,则需要获取投影矩阵并将其反转,然后使用一些“光线”系统可能会更复杂一些。。