OpenGL-- texture resolve common API

A texture common API functions

1. The data from the color buffer pixel read directly as in FIG.

void glReadPixels(GLint x,GLint y,GLSizei width,GLSizei height, GLenum format, GLenum type,const void * pixels);

// Parameter 1: x, the lower left corner of the rectangular window coordinates
// Parameter 2: y, coordinates of the lower left corner of the window rectangle
// Parameter 3: width, the width of the rectangle, in pixels
// Parameter 4: height, rectangular ADVANCED, in pixels
// parameters 5: format, OpenGL pixel format
// parameter 6: type, parameters pixels interpret the data points, it tells OpenGL what data type Use the buffer area to store of colors in components
// parameter 7: pixels, a pointer to the graphics data

2. FIG pixels read from the file TAG

GLbyte *gltReadTGABits(const char *szFileName, GLint *iWidth, GLint *iHeight, GLint *iComponents, GLenum *eFormat);
  • Parameter 1: Texture file name
  • Parameter 2: File Address Width
  • Parameter 3: File highly address
  • Parameter 4: File component address
  • Parameter 5: File Format Address
  • Return Value: pBits, a pointer to the image data

3. Load Texture

void glTexImage1D(GLenum target,GLint level,GLint internalformat,GLsizei width,GLint border,GLenum format,GLenum type,void *data);

void glTexImage2D(GLenum target,GLint level,GLint internalformat,GLsizei width,GLsizei height,GLint border,GLenum format,GLenum type,void * data);

void glTexImage3D(GLenum target,GLint level,GLint internalformat,GLSizei width,GLsizei height,GLsizei depth,GLint border,GLenum format,GLenum type,void *data);
  • target:GL_TEXTURE_1D、GL_TEXTURE_2D、GL_TEXTURE_3D`。
  • Level: mip map levels specified loaded. Shoots as usual we regard this parameter is set to 0.
  • internalformat: How each color component stored in the texture unit.
  • width, height, depth parameters: refers to the load textures width, height, depth.
    Note: These values must be a power of two (This is because a requirement under the old version of OpenGL left on the course now can not support a power of 2, but developers are still accustomed to using integers times to 2. parties to set these parameters.)
  • border parameter: specifies ⼀ allows a border width of the texture map.
  • format, type, data parameters: glDrawPixels speak with us in the same function for the parameter.

4. Update texture

void glTexSubImage1D(GLenum target,GLint level,GLint xOffset,GLsizei width,GLenum format,GLenum type,const GLvoid *data);

void glTexSubImage2D(GLenum target,GLint level,GLint xOffset,GLint yOffset,GLsizei width,GLsizei height,GLenum format,GLenum type,const GLvoid *data);

void glTexSubImage3D(GLenum target,GLint level,GLint xOffset,GLint yOffset,GLint zOffset,GLsizei width,GLsizei height,GLsizei depth,Glenum type,const GLvoid * data);

5. Insert Alternatively Texture

void glCopyTexSubImage1D(GLenum target,GLint level,GLint xoffset,GLint x,GLint y,GLsizei width);

void glCopyTexSubImage2D(GLenum target,GLint level,GLint xoffset,GLint yOffset,GLint x,GLint y,GLsizei width,GLsizei height);

void glCopyTexSubImage3D(GLenum target,GLint level,GLint xoffset,GLint yOffset,GLint zOffset,GLint x,GLint y,GLsizei width,GLsizei height);

6. Use color buffer load data, construct a new texture

void glCopyTexImage1D(GLenum target,GLint level,GLenum internalformt,GLint x,GLint y,GLsizei width,GLint border);

void glCopyTexImage2D(GLenum target,GLint level,GLenum internalformt,GLint x,GLint y,GLsizei width,GLsizei height,GLint border);

  Parameters x, y specifies the reading start position in the color texture data in the buffer; buffer in the data source buffer provided by glReadBuffer.
  Note: There is no glCopyTextImage3D, because we ⽆ method to obtain data from the 2D volume of colors in the buffer zone.

7. The texture object correlation function

7.1 Related Function
Using a texture object allocation function

void glGenTextures(GLsizei n,GLuint * textTures);
  • The number of texture objects: Parameter 1
  • Parameter 2: Texture object pointers (a pointer to an unsigned integer array, the filling texture object identifier)

Binding texture states

void glBindTexture(GLenum target,GLunit texture);
  • 参数target:GL_TEXTURE_1D、GL_TEXTURE_2D、GL_TEXTURE_3D
  • Parameters texture: the need to bind texture object

Remove the binding texture object

void glDeleteTextures(GLsizei n,GLuint *textures); //测试纹理对象是否有效

Parameter 1: texture object
parameter 2: Texture object pointers (a pointer to an unsigned integer array, the filling texture object identifier)
  If a texture is textured object space has been allocated, then the function returns GL_TRUE, otherwise return GL_FALSE.

Determine whether the texture object

GLboolean glIsTexture(GLuint texture);

Set texture processing parameters

glTexParameterf(GLenum target,GLenum pname,GLFloat param);
glTexParameteri(GLenum target,GLenum pname,GLint param);
glTexParameterfv(GLenum target,GLenum pname,GLFloat *param);
glTexParameteriv(GLenum target,GLenum pname,GLint *param);

Parameter 1: target, specify the parameters to be to apply it on the texture pattern, such as GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D
Parameter 2: pname, texture parameters that specify the required settings
Parameter 3: param, set a specific value of the parameter of texture

7.2 Filter shutter mode is provided
two kinds of filtering: filtering near, linear filtering.
Here Insert Picture DescriptionHere Insert Picture Description

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)纹理缩小时,使用邻近过滤
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)纹理放大时,使⽤线性过滤
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

  Two kinds of filtering effect
Here Insert Picture Description
7.3 surround mode setting
Here Insert Picture Description

glTextParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAR_S,GL_CLAMP_TO_EDGE);

glTextParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAR_T,GL_CLAMP_TO_EDGE);

Parameter 1: GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D
Parameter 2: GL_TEXTURE_WRAP_S, GL_TEXTURE_T, GL_TEXTURE_R, for s, t, r coordinate
parameters. 3: GL_REPEAT, GL_CLAMP, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER;
GL_REPEAT: the OpenGL texture coordinates exceeding 1.0 ⽅ upwardly texture into ⾏ repeat row;
GL_CLAMP: desired texture from the texture processing unit boundary or TEXTURE_BORDER_COLOR.
(GL_CLAMP_TO_EDGE forcibly surround mode texture coordinates outside the range of the end of the last row along a legal unit or the last frame texture columns sampled .GL_CLAMP_TO_BORDER: texture coordinates only at the boundary Using the texture unit out of the range 0.0 to 1.0. boundary unit is a texture as an additional rows and columns around the base image, and with the base texture image loading.)

  Texture here to summarize the correlation function, and then the subsequent texture coordinates summarized.

Guess you like

Origin blog.csdn.net/JeffersonZHabc/article/details/94652995