在OpenGL ES 2.0中渲染点

时间:2014-02-13 14:40:59

标签: android opengl-es opengl-es-2.0

我开始学习OpenGL ES 2.0 for android。就我的理解而言,我只能渲染那些x和y坐标在-1和1之间归一化的值。但突然我的代码行为不同,并且在-4到4的范围内呈现值。我的理解是正确的还是你认为我的代码有问题?

透视矩阵的MatrixHelper类:

public class MatrixHelper {
    public static void perspectiveM(float[] m, float yFovInDegrees, float aspect,
        float n, float f) {
        final float angleInRadians = (float) (yFovInDegrees * Math.PI / 180.0);

        final float a = (float) (1.0 / Math.tan(angleInRadians / 2.0));
        m[0] = a / aspect;
        m[1] = 0f;
        m[2] = 0f;
        m[3] = 0f;

        m[4] = 0f;
        m[5] = a;
        m[6] = 0f;
        m[7] = 0f;

        m[8] = 0f;
        m[9] = 0f;
        m[10] = -((f + n) / (f - n));
        m[11] = -1f;

        m[12] = 0f;
        m[13] = 0f;
        m[14] = -((2f * f * n) / (f - n));
        m[15] = 0f;        
    }
}

这是我的课程画线:

public class Well {
    private static final int POSITION_COMPONENT_COUNT = 2;
    private static final int COLOR_COMPONENT_COUNT = 3;
    private static final int STRIDE = 
            (POSITION_COMPONENT_COUNT + COLOR_COMPONENT_COUNT) * BYTES_PER_FLOAT;
    private static final float[] VERTEX_DATA = {

        2.57088082911189f,2.70649737162497f, 1f, 0f, 0f,
        2.57088082911189f,2.70649737162497f, 1f, 0f, 0f,            
    };
    private final VertexArray vertexArray;

    public Well() {
        vertexArray = new VertexArray(VERTEX_DATA);
    }

    public void bindData(ColorShaderProgram colorProgram) {
        vertexArray.setVertexAttribPointer(0, colorProgram.getPositionAttributeLocation(), POSITION_COMPONENT_COUNT, STRIDE);

        vertexArray.setVertexAttribPointer(POSITION_COMPONENT_COUNT, colorProgram.getColorAttributeLocation(), COLOR_COMPONENT_COUNT, STRIDE);
    }

    public void draw() {
        glDrawArrays(GL_LINE_STRIP, 0, 2);
    }
}

1 个答案:

答案 0 :(得分:0)

检查你的viewMatrix

计算右视图 看看这个

http://pastebin.com/xnNTNc0v