OpenGLES20屏幕坐标到NDC

时间:2015-12-30 20:29:17

标签: android opengl-es

我想在OpenGL ES20中为我的Android应用程序渲染图像。 因为我对opengl很陌生,所以我使用了enter link description here

中的一个例子

我已经使用NDC系统定义了对象[-1,1] 但在此示例中,您必须使用屏幕坐标定义顶点。 我现在的问题是: 如何将屏幕坐标系统更改回NDC系统?

PS:我认为问题在于这段代码:

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {      
    // We need to know the current width and height.
    mScreenWidth = width;
    mScreenHeight = height;

    // Redo the Viewport, making it fullscreen.
    GLES20.glViewport(0, 0, width, height);

    // Clear our matrices
    for(int i=0;i<16;i++)
    {
        mtrxProjection[i] = 0.0f;
        mtrxView[i] = 0.0f;
        mtrxProjectionAndView[i] = 0.0f;
    }

    // Setup our screen width and height for normal sprite translation.
    Matrix.orthoM(mtrxProjection, 0, 0f, width, 0.0f, height, 0, 50);

    // Set the camera position (View matrix)
    Matrix.setLookAtM(mtrxView, 0, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    // Calculate the projection and view transformation
    Matrix.multiplyMM(mtrxProjectionAndView, 0, mtrxProjection, 0, mtrxView, 0);
}

感谢所有回答!!

1 个答案:

答案 0 :(得分:0)

我发现了怎么做! 所以谁想知道它:

Matrix.orthoM(mtrxProjection,0,-1f,1,-1f,1,-1,1);

相关问题