OpenGL3.0常用函数详解

来源:互联网 发布:拜占庭算法 编辑:程序博客网 时间:2024/06/06 11:06

OpenGL3.0常用函数详解


void glGenBuffers (GLsizei n, GLuint* buffers);

glGenBuffers — generate buffer object names

OpenGL ES申请开辟新的VBO,并通过buffers数组获取VBO handlehandle的类型为整型

n - Specifies the number of buffer object names to be generated

buffers - Specifies an array in which the generated buffer object names are stored.存储的是数据句柄既数据指针


void glBindBuffer (GLenum target, GLuint buffer);

glBindBuffer — bind a named buffer object

通过handle绑定指定的VBO,只有当前被绑定的VBO才会被用户操作,通过绑定handle0VBO,可以取消对所有同类型VBO的绑定

target

Specifies the target to which the buffer object is bound. The symbolic constant must be GL_ARRAY_BUFFER, GL_COPY_READ_BUFFER,GL_COPY_WRITE_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_PIXEL_PACK_BUFFER, GL_PIXEL_UNPACK_BUFFER,GL_TRANSFORM_FEEDBACK_BUFFER, or GL_UNIFORM_BUFFER.

buffer

Specifies the name of a buffer object.


void glBufferData (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);

glBufferData — creates and initializes a buffer object's data store

data数据复制给当前绑定的VBO

target

Specifies the target buffer object. The symbolic constant must be GL_ARRAY_BUFFER, GL_COPY_READ_BUFFER,GL_COPY_WRITE_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_PIXEL_PACK_BUFFER, GL_PIXEL_UNPACK_BUFFER,GL_TRANSFORM_FEEDBACK_BUFFER, or GL_UNIFORM_BUFFER.

size

Specifies the size in bytes of the buffer object's new data store.

data

Specifies a pointer to data that will be copied into the data store for initialization, or NULL if no data is to be copied.

usage

Specifies the expected usage pattern of the data store. The symbolic constant must be GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY.


void glVertexAttribPointer (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)

glVertexAttribPointer — define an array of generic vertex attribute data

glVertexAttribPointer 指定了渲染时索引值为index的顶点属性数组的数据格式和位置

https://baike.baidu.com/item/glVertexAttribPointer/6483823?fr=aladdin

index

Specifies the index of the generic vertex attribute to be modified.

size

Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4. The initial value is 4.

type

Specifies the data type of each component in the array. The symbolic constants GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT,GL_UNSIGNED_SHORT, GL_INT, and GL_UNSIGNED_INT are accepted by both functions. Additionally GL_HALF_FLOAT, GL_FLOAT,GL_FIXED, GL_INT_2_10_10_10_REV, and GL_UNSIGNED_INT_2_10_10_10_REV are accepted by glVertexAttribPointer. The initial value is GL_FLOAT.

normalized

For glVertexAttribPointer, specifies whether fixed-point data values should be normalized(GL_TRUE) or converted directly as fixed-point values(GL_FALSE) when they are accessed. This parameter is ignored iftype is GL_FIXED.

stride

Specifies the byte offset between consecutive generic vertex attributes. Ifstride is 0, the generic vertex attributes are understood to be tightly packed in the array. The initial value is 0.

pointer

Specifies a pointer to the first generic vertex attribute in the array. If a non-zero buffer is currently bound to the GL_ARRAY_BUFFERtarget,pointer specifies an offset of into the array in the data store of that buffer. The initial value is 0.


void glDrawArrays (GLenum mode, GLint first, GLsizei count);

glDrawArrays — render primitives from array data

提供绘制功能。当采用顶点数组方式绘制图形时,使用该函数。该函数根据顶点数组中的坐标数据和指定的模式,进行绘制

https://baike.baidu.com/item/glDrawArrays

mode

Specifies what kind of primitives to render. Symbolic constants GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES,GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN and GL_TRIANGLES are accepted.

first

Specifies the starting index in the enabled arrays.

count

Specifies the number of indices to be rendered.


void glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices);

glDrawElements — render primitives from array data

glDrawElements是一个OPENGL的图元绘制函数,从数组中获得数据渲染图元。

glDrawElements函数能够通过较少的函数调用绘制多个几何图元,而不是通过OPENGL函数调用来传递每一个顶点,法线,颜色信息。你可以事先准备一系列分离的顶点、法线、颜色数组,并且调用一次glDrawElements把这些数组定义成一个图元序列。当调用glDrawElements函数的时候,它将通过索引使用count个成序列的元素来创建一系列的几何图元。mode指定待创建的图元类型和数组元素如何用来创建这些图元。但是如果GL_VERTEX_ARRAY没有被激活的话,不能生成任何图元。被glDrawElements修改的顶点属性在glDrawElements调用返回后的值具有不确定性,例如,GL_COLOR_ARRAY被激活后,当glDrawElements执行完成时,当前的颜色值是没有指定的。没有被修改的属性值保持不变。

https://baike.baidu.com/item/glDrawElements


mode

Specifies what kind of primitives to render. Symbolic constants GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES,GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN and GL_TRIANGLES are accepted.

count

Specifies the number of elements to be rendered.

type

Specifies the type of the values in indices. Must be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT.

indices

Specifies a byte offset (cast to a pointer type) into the buffer bound to GL_ELEMENT_ARRAY_BUFFER to start reading indices from. If no buffer is bound, specifies a pointer to the location where the indices are stored.



参考链接 https://www.khronos.org/registry/OpenGL-Refpages/es3.0/