|
|

楼主 |
发表于 2005-2-1 19:08:00
|
显示全部楼层
Re:如果把WOW的BLP2作为材质在OpenGL里渲染,请问如何来做?
我是新手。
看了Warcraft 3 Viewer Source、你的blp2convert.exe、linghuye的MyWarCraftStudio.exe,就在想如何把blp、blp2直接贴上去,Warcraft 3 Viewer Source中把blp也转换了一下,我不太懂,可否在指教一二。
我是想做成下面的类似函数,不知如何下手?
unsigned char *LoadTGAFile(char *filename, TGAHEADER *tgaHeader)
{
FILE *filePtr;
unsigned char ucharBad; // garbage data
short int sintBad; // garbage data
long imageSize; // size of TGA image
int colorMode; // 4 for RGBA, 3 for RGB
long imageIdx; // counter variable
unsigned char colorSwap; // swap variable
unsigned char *imageData; // the TGA data
// open the TGA file
filePtr = fopen(filename, "rb");
if (!filePtr)
return NULL;
// read first two bytes of garbage
fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
// read in the image type
fread(&tgaHeader->imageTypeCode, sizeof(unsigned char), 1, filePtr);
// for our purposes, the image type should be either a 2 or a 3
if ((tgaHeader->imageTypeCode != 2) && (tgaHeader->imageTypeCode != 3))
{
fclose(filePtr);
return NULL;
}
// read 13 bytes of garbage data
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);
// read image dimensions
fread(&tgaHeader->imageWidth, sizeof(short int), 1, filePtr);
fread(&tgaHeader->imageHeight, sizeof(short int), 1, filePtr);
// read bit depth
fread(&tgaHeader->bitCount, sizeof(unsigned char), 1, filePtr);
// read garbage
fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
// colormode -> 3 = BGR, 4 = BGRA
colorMode = tgaHeader->bitCount / 8;
imageSize = tgaHeader->imageWidth * tgaHeader->imageHeight * colorMode;
// allocate memory for image data
imageData = (unsigned char*)malloc(sizeof(unsigned char)*imageSize);
// read image data
fread(imageData, sizeof(unsigned char), imageSize, filePtr);
// change BGR to RGB so OpenGL can use the data
for (imageIdx = 0; imageIdx < imageSize; imageIdx += colorMode)
{
colorSwap = imageData[imageIdx];
imageData[imageIdx] = imageData[imageIdx+2];
imageData[imageIdx + 2] = colorSwap;
}
// close the file
fclose(filePtr);
return imageData;
} |
|