Hi,
I am working on a demo programme and the problem I have been working on for the last week is as follows, I am loasing in a texture which is devided into smaller images as a tga file. I use these images throughout the game and it works fine. I have now come to load a .3ds model into my game and need to put another texture into memory for the skin of the mesh but when I init that texture using the following code, it overwrites the first tex (. The function does not return a pointer to the texture so I can’t increment this for the second image.
Can anyone help me out with this and tell me how I can adapt it to load in multiple textures? Any help or tips would be greatly appreciated, thanks in advance for any advice )
BennUK
int Ctexture::LoadTGAFile(const char* filename)
{
FILE *filePtr;
unsigned char ucharBad;
short int sintBad;
long imageSize;
int colorMode;
long imageIdx;
unsigned char colorSwap;
TGAFILE *tgaFile;filePtr =fopen(filename, “rb”); // open the file for binary reading
if(!filePtr) // if file doesn’t exist, exit
{
cout << "File %s not found
" << filename << endl;return 0; }
fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
fread(&ucharBad, sizeof(unsigned char), 1, filePtr);// create new targa file storage in memory
tgaFile = new TGAFILE;fread(&tgaFile->imageType, sizeof(unsigned char), 1, filePtr);
if((tgaFile->imageType != 2) && (tgaFile->imageType != 3))
{
fclose(filePtr);
return 0;
}fread(&sintBad, sizeof(short int), 1, filePtr);
fread(&sintBad, sizeof(short int), 1, filePtr);fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
fread(&sintBad, sizeof(short int), 1, filePtr);
fread(&sintBad, sizeof(short int), 1, filePtr);fread(&tgaFile->imageWidth, sizeof(short int), 1, filePtr);
fread(&tgaFile->imageHeight, sizeof(short int), 1, filePtr);fread(&tgaFile->bitDepth, sizeof(unsigned char), 1, filePtr);
fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
colorMode = tgaFile->bitDepth / 8;
imageSize = tgaFile->imageWidth * tgaFile->imageHeight * colorMode;tgaFile->imageData = (unsigned char*)malloc(sizeof(unsigned char)*imageSize);
fread(tgaFile->imageData, sizeof(unsigned char), imageSize, filePtr);
for(imageIdx=0; imageIdx < imageSize; imageIdx += colorMode)
{
colorSwap = tgaFile->imageData[imageIdx];
tgaFile->imageData[imageIdx] = tgaFile->imageData[imageIdx + 2];
tgaFile->imageData[imageIdx + 2] = colorSwap;}
cout << “bit depth:” << tgaFile->bitDepth << endl;
glTexImage2D(GL_TEXTURE_2D, 0, 3
, tgaFile->imageWidth, tgaFile->imageHeight, 0,
GL_RGBA, GL_UNSIGNED_BYTE, tgaFile->imageData);fclose(filePtr); // close file
return TRUE;
}
[This message has been edited by dorbie (edited 01-22-2004).]