Created by Yu-Chi Lai at 2006
Tutorial 10 tells us how to load in textures and to use textures in OpenGL environment. However, the graphic card has very limited resource for the allowable number of textures inside its memory. We do not want to load in the same texture several times. Thus, we must have a good way to keep track of the textures used inside a program. Here, we have provided a Texture Manager that can help you with much of the aspects of loading and building textures, finding texture objects, ... It allows you to refer to textures by name, and will load them from several image file formats as needed. There is a primitive mechanism provided for searching a list of directories - you should use this to make sure your program will run both in the CSL lab, and on any other machine you might want to hack on. The following are the source file and header file for the texture manager
Here is a list of format supported by this texture managers
Since we use the jpeg, bmp, gif, png image format, we'll need to add fltkjpegd.lib fltkpngd.lib fltkimagesd.lib fltkzd.lib as a dependency to our project. Open the Solution Explorer window, right click our project (CS559-Texturing), and choose Properties. Select Linker -> Input from the left hand pane and add fltkjpegd.lib fltkpngd.lib fltkimagesd.lib fltkzd.lib to the Additional Dependencies. Make sure to separate the libraries with some whitespace.
Here is a list of things you must pay attention to when you use this texture manager
The texture manager use the elements inside the texturePaths variable as searching path when it tries to locate the texture file. It will look over all the listed directoried one by one until it finds the texture file. And you can specify the path by absolute path or relative path to the project solution directory.
char* texturePaths[] = { ".", "..", "Textures/signs", "../Textures/signs", "Textures/Textures", "../Textures/Textures", "Textures/Objects", "../Textures/Objects", "c:/src/GraphicsTown/Textures/signs", "c:/src/GraphicsTown/Textures/Textures", 0 };
GLuint fetchTexture(char* name, bool wrapS, bool wrapT)
fetchTexture function is the main fuctions to interact with GL program when the program needs to grap a texture. There are three parameters for this function.
When using it, it is like a black box. Every time when you need a texture, you just call this function, it will give you the reference number generated by OpenGL.
You do not need to understand it when you just try to use it. However, we suggest that you should understand how it works because in the future, you may need to develop your own texture manager. The following is how it works. When it is called, it will check whether it has loaded in this texture already. If the texture exists in the list, the manager will give back the OpenGL reference nubmer generated when the texture has been created. If it cannot find the texture in the list, it will go through all the searching directories one by one to find the image file and load the image file in to create the texture. Then, it will set up the proper parameters and store the texture in the list. It will return the OpenGL reference back to the calling function. If the file does not exist, it will return 0 and you need to handle this situation.
Here are a list of things that often go wrong and cause your textures not to appear (whether or not you use my code):
Many of the things that the OpenGL book programs do are optional. Often, you can use the defaults for things like filtering.