欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

OpenGL函数理解

程序员文章站 2024-03-15 08:47:53
...

函数解析

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.