So. glGenTextures takes two parameters. A int and a GLuint* . int tells GL how many textures to generate, and GLuint* is the GLuint array (for generating textures). The reason you do the following ...
GLuint m_TextureID glGenTextures(1, &m_TextureID)
- this is because you have only one texture. If you have more than one, you would do this:
// Substitute 'n' for some const number GLuint *textures = new GLuint[n]; glGenTextures(n, textures);
So you say GL, I want to generate n textures, but here is an array with allocated space, at least in order to have a lot of textures.
Suppose you want to use both of them in your drawing cycle, you would do it like this:
void draw() { glBindTexture(GL_TEXTURE_2D, textures[0]);
Make sure delete textures; at the end of your program it will clean up correctly after allocating this space.
There are also ways not to snap individual textures. You can use the so-called texture atlas. Basically, this is a single bitmap containing multiple sub-images. Thus, you simply create and link one raster image and use its separate parts.
To handle multiple bitmaps, do the following:
Bitmap image[2]; image[0].loadBMP("myTexture.bmp"); image[1].loadBMP("myOtherTexture.bmp");
Then follow the process to create one bitmap for both bitmaps.
Everything below this line answers your updated question.
This will pretty much do what you are trying to do.
// Global variable GLuint textures[2]; // init function void init() { textures = new GLuint[2]; glGenTextures(2, textures); loadTexture(textures[0], "texture1.bmp"); loadTexture(textures[1], "texture2.bmp"); } void loadTexture(GLuint texture, const char* filename) { Bitmap image; image.loadBMP(filename); glBindTexture(GL_TEXTURE_2D, texture); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_MODULATE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image.width, image.height, GL_RGB, GL_UNSIGNED_BYTE, image.data); } // draw function void draw() { glBegin(GL_QUADS); //TOP glBindTexture(GL_TEXTURE_2D, textures[0]); glNormal3f(0,1,0); glColor4f(1,1,1,0); glTexCoord2f(0.0f,0.0f); glVertex3f(-4.5, 0.3, 2); //bottom left glTexCoord2f(1.0f,0.0f); glVertex3f(-4.5, 0.3, 2.5); //bottom right glTexCoord2f(1.0f,1.0f); glVertex3f(4.5, 0.3, 2.5); //top right glTexCoord2f(0.0f,1.0f); glVertex3f(4.5, 0.3, 2); //top left glEnd(); } // cleanup function void cleanup() { delete textures; }
Some of the problems you point out are not entirely related to OpenGL, they are more related to C / C ++. I know this is not the answer you are looking for, but it will probably help you learn a lot about C functions, pointers, arrays, etc. And spend a whole month working closely with functions / pointers / arrays before moving on to something like OpenGL, which requires a fairly moderate understanding of C.