Android OpenGLES20屏幕坐标到NDC
我想在OpenGL ES20中为我的android应用程序渲染图像。 因为我对opengl非常陌生,所以我使用了 我已经使用NDC系统定义了对象[-1,1] 但在本例中,必须使用屏幕坐标定义顶点。 我现在的问题是: 如何将屏幕坐标系统更改回NDC系统 PS:我认为问题在于这段代码:Android OpenGLES20屏幕坐标到NDC,android,opengl-es,Android,Opengl Es,我想在OpenGL ES20中为我的android应用程序渲染图像。 因为我对opengl非常陌生,所以我使用了 我已经使用NDC系统定义了对象[-1,1] 但在本例中,必须使用屏幕坐标定义顶点。 我现在的问题是: 如何将屏幕坐标系统更改回NDC系统 PS:我认为问题在于这段代码: @Override public void onSurfaceChanged(GL10 gl, int width, int height) { // We need to know the cu
@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);
}
@覆盖
表面上的公共空隙已更改(GL10 gl,整型宽度,整型高度){
//我们需要知道当前的宽度和高度。
mScreenWidth=宽度;
mScreenHeight=高度;
//重做视口,使其全屏显示。
GLES20.glViewport(0,0,宽度,高度);
//清除我们的矩阵
对于(int i=0;i我找到了如何做!
所以对于所有想知道的人:
矩阵正交(MTRX投影,0,-1f,1,-1f,1,-1,1)