OpenGL2.0的Android动画 - 概念性问题

时间:2013-10-28 22:57:27

标签: opengl-es-2.0

我在Android上学习OpenGLES20并有一些问题。希望你们能帮助我。

  1. 专门针对Android开发者网站“... OpenGL ES允许您使用三维空间中的坐标定义绘制的对象。”这是唯一的,或者它们是“隐藏”de“w”坐标?普通空间有3个坐标,但Clip Space有4个(x,y,z,w),对吗?

  2. 如果我的三角形是在float数组中定义的,为什么只为int值定义GLES20.glBindBuffer(arg0, arg1)函数?

  3. 即使我没有输入代码glBindBuffer(GL_ARRAY_BUFFER, myPositionBufferObject);,我的程序也能运行。如果我没有将我的缓冲区绑定到OpenGL目标GL_ARRAY_BUFFER?

  4. 这是我的Triangle的代码。它只是渲染最简单的三角形所必需的超简化代码。

    public class Triangle {
    
        ByteBuffer myByteBuffer;
        FloatBuffer positionBufferObject;    
    
        int mProgram;
    
        public Triangle() {
    
            float vertexPositions[] = { 
    
                     0.75f,  0.75f, 0.0f, 1.0f,
                     0.75f, -0.75f, 0.0f, 1.0f,
                    -0.75f, -0.75f, 0.0f, 1.0f
    
            };
    
            myByteBuffer = ByteBuffer.allocateDirect(vertexPositions.length * 4);
            myByteBuffer.order(ByteOrder.nativeOrder());
    
            positionBufferObject = myByteBuffer.asFloatBuffer();
            positionBufferObject.put(vertexPositions);
            positionBufferObject.position(0);
    
            String vertexShaderCode =
                    "attribute vec4 vPosition;" +
                    "void main() {" +
                    "  gl_Position = vPosition;" +
                    "}";
    
            String fragmentShaderCode =
                    "precision mediump float;" +
                    "uniform vec4 vColor;" +
                    "void main() {" +
                    "  gl_FragColor = vColor;" +
                    "}";
    
            int myVertexShader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
            GLES20.glShaderSource(myVertexShader, vertexShaderCode);
            GLES20.glCompileShader(myVertexShader);
    
            int myFragmentShader = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
            GLES20.glShaderSource(myFragmentShader, fragmentShaderCode);
            GLES20.glCompileShader(myFragmentShader);
    
            mProgram = GLES20.glCreateProgram();
    
            GLES20.glAttachShader(mProgram, myVertexShader);        
            GLES20.glAttachShader(mProgram, myFragmentShader); 
    
            GLES20.glLinkProgram(mProgram);        
    
        }
    
        public void draw() {
    
            GLES20.glUseProgram(mProgram);
    
            GLES20.glEnableVertexAttribArray(0);
            GLES20.glVertexAttribPointer(0, 4, GLES20.GL_FLOAT, false, 0, positionBufferObject);
    
            GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3);
    
        }
    
    }
    

0 个答案:

没有答案