If you read my article on loading textures, you know the function glTexImage2D() creates a texture out of an image. There’s a little more work to do to create an OpenGL texture map. I’m going to cover that material in this section.
Texture objects store texture data so you don’t have to call glTexImage2D() every time you want to draw a texture map. Call the function glGenTextures() to create a texture object for the texture map. This function takes two arguments: the number of texture objects to create and either a texture name or a list of names, depending on the number of texture objects created. You normally create one texture object at a time.
GLuint textureName; glGenTextures(1, &textureName);
Because OpenGL works on multiple screen resolutions, a texture is not going to be drawn exactly the same on all computers. Depending on the player’s screen resolution, OpenGL may have to scale a texture to make it look right on the player’s screen. You have to tell OpenGL what to do when it has to magnify or minify a texture. Call the function glTexParameteri(), which sets the values of various OpenGL texture parameters. This function takes three arguments.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Next (Drawing a Tile)
Previous (Setting Up the Viewing Volume)