|
|
@ -1,6 +1,7 @@ |
|
|
|
#include "misc.h"
|
|
|
|
#include "FreeImage.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include "FreeImage.h"
|
|
|
|
|
|
|
|
#pragma comment(lib,"FreeImage.lib")
|
|
|
|
|
|
|
@ -251,7 +252,36 @@ GLuint CreateTextureFromDds(const char * imagePath) |
|
|
|
glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, width, height, 0, pixelSize, pixelData); |
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0); |
|
|
|
|
|
|
|
delete imgData; |
|
|
|
return texture; |
|
|
|
} |
|
|
|
void SaveImage(const char*imagePath, unsigned char*imgData, int width, int height) |
|
|
|
{ |
|
|
|
FILE*pFile = fopen(imagePath, "wb"); |
|
|
|
if (pFile) |
|
|
|
{ |
|
|
|
BITMAPFILEHEADER bfh; |
|
|
|
memset(&bfh, 0, sizeof(BITMAPFILEHEADER)); |
|
|
|
bfh.bfType = 0x4D42; |
|
|
|
bfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + width*height * 3; |
|
|
|
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); |
|
|
|
fwrite(&bfh, sizeof(BITMAPFILEHEADER), 1, pFile); |
|
|
|
|
|
|
|
BITMAPINFOHEADER bih; |
|
|
|
memset(&bih, 0, sizeof(BITMAPINFOHEADER)); |
|
|
|
bih.biWidth = width; |
|
|
|
bih.biHeight = height; |
|
|
|
bih.biBitCount = 24; |
|
|
|
bih.biSize = sizeof(BITMAPINFOHEADER); |
|
|
|
fwrite(&bih, sizeof(BITMAPINFOHEADER), 1, pFile); |
|
|
|
unsigned char temp = 0; |
|
|
|
for (int i = 0; i<width*height * 3; i += 3) |
|
|
|
{ |
|
|
|
temp = imgData[i + 2]; |
|
|
|
imgData[i + 2] = imgData[i]; |
|
|
|
imgData[i] = temp; |
|
|
|
} |
|
|
|
fwrite(imgData, 1, width*height * 3, pFile); |
|
|
|
fclose(pFile); |
|
|
|
} |
|
|
|
} |