I moved the glBindTexture() inside the DrawCrate functions and it will still only show the last of the loaded textures put in the InitGL(). The DrawCrate functions are simply just coordinates for how the boxes should be drawn. Here is one of the functions (these are in header files by the way).
EDIT: if this helps any, i changed the texture[] array number from 0 and 1 to 1 and 2 where it gets binded to the box i want, and the second box shows up white without texture. I think it has something to do with the way the bitmap is loaded in the loading function.
Code:
bool DrawCrateNear(void){
glBindTexture(GL_TEXTURE_2D,texture[0]);
glBegin(GL_QUADS);
//-----FRONT------------
//glColor3f(1.0f,0.0f,0.0f);
glTexCoord2f(1.0f,1.0f); glVertex3f(1.0,1.0,0.0);
//glColor3f(0.0f,1.0f,0.0f);
glTexCoord2f(1.0f,0.0f); glVertex3f(1.0,-1.0,0.0);
//glColor3f(1.0f,0.0f,0.0f);
glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0,-1.0,0.0);
//glColor3f(0.0f,1.0f,0.0f);
glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0,1.0,0.0);
//..... after a ton of coords....
//-----BOTTOM-----------------
glTexCoord2f(1.0f,1.0f); glVertex3f(-1.0,-1.0,-2.0);
//glColor3f(0.0f,1.0f,0.0f);
glTexCoord2f(1.0f,0.0f); glVertex3f(-1.0,-1.0,0.0);
//glColor3f(1.0f,0.0f,0.0f);
glTexCoord2f(0.0f,0.0f); glVertex3f(1.0,-1.0,0.0);
//glColor3f(0.0f,1.0f,0.0f);
glTexCoord2f(0.0f,1.0f); glVertex3f(1.0,-1.0,-2.0);
glEnd();
return true;
}
EDIT 2: I figured it out! The CustomLoadBitmap() was not generating the textures with glGenTextures() like it should have. The final loader for the bitmaps is the following code.
Code:
bool CustomLoadBitmap(char *filename, GLuint &num_texture)
{
int i, j=0,count=0; //Index variables
FILE *l_file; //File pointer
unsigned char *l_texture; //The pointer to the memory zone in which we will load the texture
// windows.h gives us these types to work with the Bitmap files
BITMAPFILEHEADER fileheader;
BITMAPINFOHEADER infoheader;
RGBTRIPLE rgb;
if((l_file = fopen(filename, "rb"))==NULL) return (-1); // Open the file for reading
fread(&fileheader, sizeof(fileheader), 1, l_file); // Read the fileheader
fseek(l_file, sizeof(fileheader), SEEK_SET); // Jump the fileheader
fread(&infoheader, sizeof(infoheader), 1, l_file); // and read the infoheader
num_texture++; // The counter of the current texture is increased
// Now we need to allocate the memory for our image (width * height * color deep)
l_texture = (byte *) malloc(infoheader.biWidth * infoheader.biHeight * 4);
// And fill it with zeros
memset(l_texture, 0, infoheader.biWidth * infoheader.biHeight * 4);
// At this point we can read every pixel of the image
for (i=0; i < infoheader.biWidth*infoheader.biHeight; i++)
{
// We load an RGB value from the file
fread(&rgb, sizeof(rgb), 1, l_file);
// And store it
l_texture[j+0] = rgb.rgbtRed; // Red component
l_texture[j+1] = rgb.rgbtGreen; // Green component
l_texture[j+2] = rgb.rgbtBlue; // Blue component
l_texture[j+3] = 255; // Alpha value
j += 4; // Go to the next position
}
fclose(l_file); // Closes the file stream
glGenTextures(1, &num_texture);
glBindTexture(GL_TEXTURE_2D, num_texture); // Bind the ID texture specified by the 2nd parameter
// The next commands sets the texture parameters
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // If the u,v coordinates overflow the range 0,1 the image is repeated
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // The magnification function ("linear" produces better results)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); //The minifying function
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // We don't combine the color with the original surface color, use only the texture map.
// Finally we define the 2d texture
glTexImage2D(GL_TEXTURE_2D, 0, 4, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);
// And create 2d mipmaps for the minifying function
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, infoheader.biWidth, infoheader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);
free(l_texture); // Free the memory we used to load the texture
count++;
return (num_texture); // Returns the current texture OpenGL ID
}