typedef struct TGAImage { GLubyte *imageData; // 图像数据 GLuint bpp; // 像素颜色深度 GLuint width; // 图像宽度 GLuint height; // 图像高度 GLuint texID; // 纹理ID } TGAImage; bool LoadTGA(TGAImage *texture, char *filename) { GLubyte TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0}; // Uncompressed TGA Header 不压缩的TGA头 GLubyte TGAcompare[12]; // Used To Compare TGA Header 压缩的 GLubyte header[6]; // First 6 Useful Bytes From The Header TGA头的前6个有用的字节 GLuint bytesPerPixel; // Holds Number Of Bytes Per Pixel Used In The TGA File TGA文件每个像素使用的字节 GLuint imageSize; // Used To Store The Image Size When Setting Aside Ram GLuint temp; // Temporary Variable 临时变量 GLuint type=GL_RGBA; // Set The Default GL Mode To RBGA (32 BPP) 默认的GL模式 FILE *file = fopen(filename, "rb"); // Open The TGA File printf("TGA_file=%d/n",file); if( file==NULL || // Does File Even Exist? fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) || // Are There 12 Bytes To Read? 是否读到12字节数据 memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0 || // Does The Header Match What We Want? 是否是压缩的,压缩的就读取失败,关闭file fread(header,1,sizeof(header),file)!=sizeof(header)) // If So Read Next 6 Header Bytes 再读6个字节 { if (file == NULL) // Did The File Even Exist? *Added Jim Strong* return false; // Return False else