OpenGL函数理解

函数解析

Texture procedures

- glGenTexture

glGenTextures: generate texture names and returns n​ texture names in textures​.

void glGenTextures(GLsizei n​, GLuint * textures​);

Parameters:

n: Specifies the number of texture names to be generated.
textures: Specifies an array in which the generated texture names are stored.

- glBindTexture

glBindTexture: bind a named texture to a texturing target, lets you create or use a named texture. When a texture is bound to a target, the previous binding for that target is automatically broken.

void glBindTexture(GLenum target​, GLuint texture​);

Parameters:

target: Specifies the target to which the texture is bound.
texture: Specifies the name of a texture.

- glTexParameteri

glTexParameteri sets texture parameters

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

- glTexImage2D

glTexImage2D: specify a two-dimensional texture image, to define texture images.

void glTexImage2D(GLenum target​, GLint level​, GLint internalFormat​, GLsizei width​, GLsizei height​, GLint border​, GLenum format​, GLenum type​, const GLvoid * data​);

Parameters:

// too much parameters.

For more details please refer to GLAPI.

- glGenerateMipmap

glGenerateMipmap: generate mipmaps for a specified texture target.

void glGenerateMipmap(GLenum target​);

- glUniform

Specify the value of a uniform variable for the current program object. Give some examples:

void glUniform1f( GLint location, GLfloat v0);
void glUniform2f( GLint location, GLfloat v0, GLfloat v1);
void glUniform4fv( GLint location, GLsizei count, const GLfloat *value);
void glUniform4iv( GLint location, GLsizei count, const GLint *value);
void glUniformMatrix4fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
void glUniformMatrix2x3fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);

Parameters:

location: Specifies the location of the uniform variable to be modified.
count: 
    - For the vector (glUniform*v) commands, specifies the number of elements that are to be modified. This should be 1 if the targeted uniform variable is not an array, and 1 or more if it is an array.
    - For the matrix (glUniformMatrix*) commands, specifies the number of matrices that are to be modified. This should be 1 if the targeted uniform variable is not an array of matrices, and 1 or more if it is an array of matrices.
transpose: For the matrix commands, specifies whether to transpose the matrix as the values are loaded into the uniform variable.
v0, v1, v2, v3: For the scalar commands, specifies the new values to be used for the specified uniform variable.
value: For the vector and matrix commands, specifies a pointer to an array of count values that will be used to update the specified uniform variable.

Understanding

glUniform1i(unf_texture, 0); 
// Why do we pass a Zero value to unf_texture in glUniform1i?

The sampler2D is bound to a texture unit. The glUniform call binds it to texture unit zero.

- glActiveTexture

glActiveTexture: select active texture unit.

glActiveTexture(GL_TEXTURE0);
// Is glActiveTexture call really need?

The glActiveTexture call is only needed if you are going to use multiple texture units (because GL_TEXTURE0 is the default anyway).

VBO procedures

- glGenBuffers

glGenBuffers: generate buffer object names.

void glGenBuffers(GLsizei n​, GLuint * buffers​);

Parameters:

n: Specifies the number of buffer object names to be generated.
buffers: Specifies an array in which the generated buffer object names are stored.

- glBindBuffer

glBindBuffer binds a buffer object to the specified buffer binding point.

void glBindBuffer(GLenum target​, GLuint buffer​);

Parameters:

target: Specifies the target buffer object. 
buffer: Specifies the name of a buffer object.

- glBufferData

glBufferData: creates and initializes a buffer object’s data store.

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

Parameters:

target: Specifies the target buffer object. 
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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值