Now I have two custom shader, the position vertex shader and the color fragment shader. And I define two array data, position Array and color Array. This can make the gradient triangel in the iPhone. I didn't call the glBindBuffer() and glBufferData() for the VAO. but in the glVertexAttribPointer(),I send the position array to its last attribute and the color array too. Now, I feel confused,I found most documents explain the last attribute in this function, it is offset in vertex data array. now I send it to the array data and did not call the glBindBuffer() and glBufferData(), but it take effect。
lazy var postions : [GLfloat] = [
-0.5, -0.5, 0.0,
0.5, -0.5, 0.0,
0.0, 0.5, 0.0,
]
lazy var colors : [GLfloat] = [
1, 0, 0,
0, 1, 0,
0, 0, 1,
]
and this is the code about glVertexAttribPointer
let posistionAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "position"))
glVertexAttribPointer(posistionAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), postions)
glEnableVertexAttribArray(posistionAtt)
let ptr = UnsafePointer<Int>.init(bitPattern: 3 * MemoryLayout<GLfloat>.size)
let colorAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "color"))
glVertexAttribPointer(colorAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), colors)
glEnableVertexAttribArray(colorAtt)