android GLES20 color

 

android GLES20 color

画框的颜色: r g b alpha透明度,0-1之间

    private String fragmentShader =
            "void main() {\n" +
            "    gl_FragColor = vec4(0.0,1.0,0.0,1.0);\n" +
            "}";
    private  String vertexShader = "attribute vec2 aPosition;\n" +
            "void main() {\n" +
            "    gl_Position = vec4(aPosition,0.0,1.0);\n" +
            "    gl_PointSize = 10.0;\n"+
            "}";

画矩形框:

    //float类型的字节数
    private static final int BYTES_PER_FLOAT = 4;
    private FloatBuffer rectBuffer;

    public void drawRect(float[] points) {

        rectBuffer = ByteBuffer
                .allocateDirect(points.length * BYTES_PER_FLOAT)
                .order(ByteOrder.nativeOrder())
                .asFloatBuffer();
        // 把坐标们加入FloatBuffer中
        rectBuffer.put(points);
        // 设置buffer,从第一个坐标开始读
        rectBuffer.position(0);
        GLES20.glBlendColor(0.0f,1.0f,0.0f,1.0f);
        GLES20.glLineWidth( 3f );
        GLES20.glUseProgram(programId);
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vertexBuffers[0]);
        GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER,0,points.length*4,rectBuffer);
        GLES20.glEnableVertexAttribArray(aPositionHandle);
        GLES20.glVertexAttribPointer(aPositionHandle, 2, GLES20.GL_FLOAT, false,
                0, 0);
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
        GLES20.glDrawArrays(GLES20.GL_LINE_LOOP, 0, 4);
    }

 

你可能感兴趣的:(android开发)