In the "OpenGL texture map (2): Basic, we learned about the basics of texture map. In the subsequent learning, I realized that this problem: How to switch between different textures, how to map different textures to different objects. New features introduced in OpenGL 1.1 Texture Objects can solve this problem very well. The main idea is to use Texture Object Texture Object state to maintain some texture in the Texture Object rendering phase and a Texture Target (OpenGL maintains three Texture Target: GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D) binding, this process is equivalent to This texture Object maintenance texture is selected in the OpenGL state machine so that this texture Object maintenance will work. Some texture status of Texture Object include: Texture Image (s); // Texture pattern Texture Parameter; // Parameters controlled by GLTEXPARAMETER * () Function Note: Other textures related states, such as Texture Environment and Texture Coordinate Generation Mode is not included in Texture Objects. The identifier of each Texture Object is represented by a unsigned int value, in order to ensure that the "name" of each Texture Object is unique, OpenGL provides the GLGENTEXTURE () function.
Each Texture Object when it is created, you need to call glBindTexture () to connect the Texture Object and Texture Target (GL_TEXTURE_1D, GL_TEXTURE_2D), using the Texture Object stage, still need to call glBindTexture () to "activate" this Texture Object. With the following code demonstrates how to use the texture Object: 1 create a texture Object:. GLuint uiTextureID; glGenTexture (1, & uiTextureID); // get the first parameter specifies how many consecutive show texture identifier glBindTexture (GL_TEXTURE_2D, uiTextureID); // 2 setting this state texture texture Object maintenance: LoadBMPff ( "Texture.bmp"); // actually calls glTexImage2D (), specify the texture Image glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) .; glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 3 repeat the above steps can be created in multiple texture Object.4 rendering phase, specified texture identifier, activating a specific texture Object: glClear. (GL_COLOR_BUFFER_BIT); glEnable (GL_TEXTURE_2D); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glPushMatrix (); glBegin (GL_QUADS); glBindTexture (GL_TEXTURE_2D, uiTextureID); glTexCoord2f (0.0,0.0); glVertex2f (-1.0 , -1.0); gltexcoord2f (0.0, 1.0); GlvertEX2F (-1.0, 1.0); GLTEXCOORD2F (1.0, 1.0); Glvertex2f (1.0, 1.0); GLTEXCOORD2F (1.0, 0.0); GLvendEx2f (1.0, -1.0); glend (); 5. When you don't need it, remove texture object: GLDeleteTextures (1, & UITEXTUREID); 6. Use it. Reference: 1.Http://www.opengl.org/documentation/specs/Version1.1/glspec1. 1 / Node87.html2.http://www.opengl.org/resources/tutorials/sig99/advanced99/notes/node59.html --------------------- -------- Committed to multimedia technology, becoming ideological software engineers ------------------------ This article is my original creation, To reprint, please contact your own or indicate. Welcome everyone to make valuable comments on the content of the article, and I hope that everyone will point out the mistakes in the text, so I can correct it in time.