目录
1.创建program,其中粘贴有vShader和fShader
a1.glCreateShader(GLenum shaderType)
a2.glShaderSource(GLuint shader,GLsizei count,const GLchar * const *string,const GLint *length)
a3.glCompileShader(GLuint shader)
a5.glAttachShader(program ,vertexShader | fragmentShader)
b1.glGenBuffers(int n, int[] buffers, int offset)
b2.glBindBuffer(int target, int buffer)
b3.glBufferData(int target, int size, Buffer data, int usage)
b4.glVertexAttribPointer(int indx, int size, int type, boolean normalized, int stride, int offset)
c1.glDrawArrays(int mode, int first, int count)
c2.glDrawElements(int mode, int count, int type, int offset)
1.创建program,其中粘贴有vShader和fShader
a1.glCreateShader(GLenum shaderType)
创建一个着色器对象
shaderType
指定要创建的着色器的类型。 只能是GL_VERTEX_SHADER或GL_FRAGMENT_SHADER
a2.glShaderSource(GLuint shader,GLsizei count,const GLchar * const *string,const GLint *length)
它们只是复制vShader| fShader到指定的着色器对象中
shader 要被替换源代码的着色器对象shader。
count 指定字符串和长度数组中的元素数。
string &vShaderStr | & fShaderStr
length 指定字符串长度的数组。
a3.glCompileShader(GLuint shader)
编译着色器对象
shader 要编译的shader
a4.glCreateProgram(void)
创建一个prgram
a5.glAttachShader(program ,vertexShader | fragmentShader)
将着色器代码粘贴到program中
a6.glLinkProgram(program)
连接program,用以处理用户的顶点等数据
2.加载数据到buffer
b1.glGenBuffers(int n, int[] buffers, int offset)
向OpenGL ES申请开辟新的VBO,并通过buffers数组获取VBO handle,handle的类型为整型。
int n 申请的VBO个数(申请几个缓冲区句柄)
int[] buffers 用于存储VBO handle的数组
int offset buffers数组的偏移量,即从buffers的第offset个位置开始存储handle
注意需要满足 n + offset <= buffers.length
b2.glBindBuffer(int target, int buffer)
绑定VertexBufferObjects
通过handle绑定指定的VBO,同一时间只能绑定一个同类型的VBO,只有当前被绑定的VBO才会被用户操作。通过绑定handle为0的VBO,可以取消对所有同类型VBO的绑定。
int target 指定绑定的VBO类型,具体类型有
GL_ARRAY_BUFFER(用于为顶点数组传值)和
GL_ELEMENT_ARRAY_BUFFER(用于为索引数组传值)
int buffer 指定绑定的VBO handle
b3.glBufferData(int target, int size, Buffer data, int usage)
将数据传递给当前绑定的VBO。
int target 指定VBO类型,同上
int size 指定VBO的大小,单位为byte
Buffer data 指定需要传递的数据
int usage 指定VBO的存储方式,例如GL_STATIC_DRAW或GL_DYNAMIC_DRAW
b4.glVertexAttribPointer(int indx, int size, int type, boolean normalized, int stride, int offset)
描述顶点数组属性相关信息。
int indx 指定Shader属性的顶点数组handle,vShader中的输入数组,vbo中的列数
int size 指定该属性的顶点数组大小,(x,y,z...)单位为数组元素的类型
int type 指定该属性的顶点数组元素类型,如GL_FLOAT和GL_UNSIGNED_BYTE
boolean normalize 指定传递给该属性顶点数组的数据是否需要归一化(转化为单位向量)
int stride 指定该属性的顶点数据在VBO中的跃度,即每个顶点所占的数据长度,单位为byte
int offset 指定该属性在VBO中起始位置的偏移量,单位为byte
3.描画
c1.glDrawArrays(int mode, int first, int count)
直接使用顶点数组绘制图元。
int mode 指定绘图的模式,如GL_TRIANGLES和GL_TRIANGLE_STRIP
int first 指定从第几个顶点开始绘制
int count 指定绘制几个顶点
c2.glDrawElements(int mode, int count, int type, int offset)
使用索引数组绘制图元。
int mode 指定绘图的模式,如GL_TRIANGLES和GL_TRIANGLE_STRIP
int count 指定绘制几个顶点
int type 指定索引数组的数据类型,如GL_UNSIGNED_SHORT和GL_UNSIGNED_INT
int offset 指定索引数组起始位置的偏移量,单位为byte