【发布时间】:2018-11-12 17:05:33
【问题描述】:
现在我有两个自定义着色器,位置顶点着色器和颜色片段着色器。我定义了两个数组数据,位置数组和颜色数组。这可以使 iPhone 中的渐变三角形。 我没有为 VAO 调用 glBindBuffer() 和 glBufferData()。但是在 glVertexAttribPointer() 中,我将位置数组发送到它的最后一个属性和颜色数组。现在,我感到很困惑,我发现大多数文档都解释了这个函数中的最后一个属性,它是顶点数据数组中的偏移量。现在我把它发送到数组数据并没有调用glBindBuffer()和glBufferData(),但是它生效了。
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,
]
这是关于 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)
【问题讨论】:
标签: swift opengl-es opengl-es-2.0