glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
Also, make doubly sure that texturing is enabled before you draw. I didn't see a glEnable(GL_TEXTURE_2D) call, so I wasn't sure.
Also, every time you draw the object you are creating the texture, using it, and deleting it. This is not the ideal solution. It will get slow really fast, because that means that the texture data has to be sent to gpu memory for every texture, every single frame! If you don't know, these transfers are not quick.
Instead, you should create the textures outside of the drawing code, and only call glTexImage2D(...) once for each texture created. Then, when you want to use a texture, just call glBindTexture(GL_TEXTURE_2D, texID). Once you no longer need the textures (most likely when the program ends, or when you load a different level, for example), then you call glDeleteTextures.
For example:
const unsigned int TexCount = 4;GLuint TextureIDs[TexCount];std::string texFiles[] = { "tex1.bmp", "shelf.bmp", "sky.bmp", "dirt.bmp" };void initGL(){ //initialize viewport, perspective, anything else you need //Load textures glGenTextures(TexCount, TextureIDs); for(int i=0;i<TexCount;++i) { unsigned int width, height; glBindTexture(GL_TEXTURE_2D, TextureIDs); char* texData = MyTextureLoadingFunction(texFiles.c_str(), width, height); glTexEnvi(...); glTexParameteri(...); glTexParameteri(...); glTexParameteri(...); glTexParameteri(...); glTexImage2D(..., width, height, ..., texData); } glEnable(GL_TEXTURE_2D);}void drawStuff(){ //.. drawing code, transforms, whatever glBindTexture(GL_TEXTURE_2D, TextureIDs[0]); drawMyObject(); //more transforms and whatnot glBindTexture(GL_TEXTURE_2D, TextureIDs[1]); drawMyShelf(); //more transforms and whatnot glBindTexture(GL_TEXTURE_2D, TextureIDs[2]); drawMySkyPlane(); // etc, etc...}//Then when you don't need the textures anymorevoid cleanupTextures(){ glDeleteTextures(TexCount, TextureIDs);}
Anyway... make sure texturing is enabled, and make sure you set the parameters you want for each texture (Even if they are the same! You must!). Also, don't forget to call glTexEnvi() and setup that properly for each texture.