To use texture objects for your texture data, take these steps.
0) Check if you have enough space for all your texture objects.
Any nonzero unsigned integer may be used as a texture name. To avoid accidentally reusing names, consistently use glGenTextures() to provide unused texture names:
void glGenTextures(GLsizei n, GLuint *textureNames);Returns n currently unused names for texture objects in the array textureNames. The names returned in textureNames do not have to be a contiguous set of integers.
Zero is a reserved texture name and is never returned as a texture name by glGenTextures().
glIsTexture() determines if a texture name is actually in use (Returns GL_TRUE).
If a texture name was returned by glGenTextures() but has not yet been bound
(calling glBindTexture() with the name at least once), then
glIsTexture() returns GL_FALSE.
GLboolean glIsTexture(GLuint textureName);
Subsequent calls to glTexImage*(), glTexSubImage*(), glCopyTexImage*(), glCopyTexSubImage*(), glTexParameter*(), and glPrioritizeTextures() store data in the texture object.
The texture object may contain a texture image and associated mipmap images (if any), including associated data such as width, height, border width, internal format, resolution of components, and texture properties. Saved texture properties include minification and magnification filters, wrapping modes, border color, and texture priority.
When a texture object is subsequently bound once again, its data becomes the current texture state. (The state of the previously bound texture is replaced.)
void glBindTexture(GLenum target, GLuinttextureName);target is the dimensionality of the texture: either GL_TEXTURE_1D or GL_TEXTURE_2D.
When binding to a textureName value of zero, OpenGL stops using texture objects and returns to the unnamed default texture.
Whenever a texture object is bound once again, you may edit the contents of the bound texture object, i.e., change the texture image or other properties.
int[] textureId = new int[nbTexture]; ... gl.glGenTextures( nbTexture, textureId, 0 ); ... gl.glBindTexture( GL.GL_TEXTURE_2D, textureId[4] ); // Load Texture // or // Change Texture Paramter // or // Use Texture gl.glDeleteTextures( nbTexture, textureId, 0 );
void glDeleteTextures(GLsizei n, const GLuint*textureNames);Deletes n texture objects, named by elements in the array textureNames. The freed texture names may now be reused.
If a texture that is currently bound is deleted, the binding reverts to the default texture, as if glBindTexture() were called with zero for the value of textureName. Attempts to delete nonexistent texture names or the texture name of zero are ignored without generating an error.