Original Post
I'm currently creating routines for loading in TGA files and then copying their image data to openGL textures. However, for some reason I'm only able to load in one texture, or at least view only one texture. I'm thinking I might be missing one line of code, because that always happens to me in openGL. Anyway - here are some lines of code pertaining to my problem: struct imageFile { byte identsize; // size of ID field that follows 18 byte header (0 usually) byte colourmaptype; // type of colour map 0=none, 1=has palette byte imagetype; // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed short colourmapstart; // first colour map entry in palette short colourmaplength; // number of colours in palette byte colourmapbits; // number of bits per palette entry 15,16,24,32 short xstart; // image x origin short ystart; // image y origin short width; // image width in pixels short height; // image height in pixels byte bits; // image bits per pixel 8,16,24,32 byte descriptor; // image descriptor bits (vh flip bits) byte* imageData; //A pointer the image data unsigned int glID; //The openGL id to refrence the texture }; //Loads a TGA file into the imageFile structure //Returns true if everything was successfull, false otherwise bool loadTGAFile(const char* path, imageFile *image) { ifstream tgaFile; char* buffer = new char[2]; //Buffer for shorts tgaFile.open(path, ios::binary); if(!tgaFile.is_open()) return false; tgaFile.read(&image->identsize,sizeof(byte)); tgaFile.read(&image->colourmaptype,sizeof(byte)); tgaFile.read(&image->imagetype,sizeof(byte)); if(image->imagetype != UC_RBG) { tgaFile.close(); return false; } tgaFile.read(&buffer[0],sizeof(byte)); tgaFile.read(&buffer[1],sizeof(byte)); image->colourmapstart = charToShort(buffer); tgaFile.read(&buffer[0],sizeof(byte)); tgaFile.read(&buffer[1],sizeof(byte)); image->colourmaplength = charToShort(buffer); tgaFile.read(&image->colourmapbits,sizeof(byte)); tgaFile.read(&buffer[0],sizeof(byte)); tgaFile.read(&buffer[1],sizeof(byte)); image->xstart = charToShort(buffer); tgaFile.read(&buffer[0],sizeof(byte)); tgaFile.read(&buffer[1],sizeof(byte)); image->ystart = charToShort(buffer); tgaFile.read(&buffer[0],sizeof(byte)); tgaFile.read(&buffer[1],sizeof(byte)); image->width = charToShort(buffer); tgaFile.read(&buffer[0],sizeof(byte)); tgaFile.read(&buffer[1],sizeof(byte)); image->height = charToShort(buffer); tgaFile.read(&image->bits,sizeof(byte)); tgaFile.read(&image->descriptor,sizeof(byte)); image->imageData = new byte[image->width*image->height*(image->bits/8)]; if(image->imageData == NULL) return false; tgaFile.read(image->imageData,image->width*image->height*(image->bits/8)); tgaFile.close(); return true; } //Takes an imageFile, and creates an OpenGL texture void createGLTexture(imageFile* image) { //Create a new texture glGenTextures(1, &image->glID); //Setup the textures traits glBindTexture(GL_TEXTURE_2D, image->glID); //Standard texture enviornment settings glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); //When texture area is small, bilinear filter the closest mipmap glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); //When texture area is large, bilinear filter the original glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); //The texture wraps over at the edges (repeat) glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); //Lastly - store the image data from the image to the GL texture gluBuild2DMipmaps(GL_TEXTURE_2D, (image->bits/8), image->width, image->height, GL_RGB, GL_UNSIGNED_BYTE, image->imageData); } //The display funnction (simply displays a square with a texture) void display(void) { //Clear previous image glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Setup the camera glMatrixMode (GL_MODELVIEW); glLoadIdentity(); gluLookAt(cameraX,cameraY,cameraZ, centerX,centerY,centerZ, 0.0f,1.0f,0.0f); glEnable(GL_TEXTURE_2D); //Draw the scene glBegin(GL_QUADS); glBindTexture( GL_TEXTURE_2D, test.glID ); glNormal3f(0.0,1.0,0.0); glTexCoord2f(0.0,0.0); glVertex3f(-1.0f,0.0f,1.0f); glTexCoord2f(1.0,0.0); glVertex3f(1.0f,0.0f,1.0f); glTexCoord2f(1.0,1.0); glVertex3f(1.0f,0.0f,-1.0f); glTexCoord2f(0.0,1.0); glVertex3f(-1.0f,0.0f,-1.0f); glEnd(); glutSwapBuffers(); }