#include
#include
#include
#include "gl/gl.h"
#include "PVRShell.h"
#include "PVRShellAPI.h"
#pragma warning(disable:4244)
using namespace Gdiplus;
#pragma comment(lib,"gdiplus.lib")
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
free(pImageCodecInfo);
return -1; // Failure
}
UINT32* GL_TEXTURE_DATA = NULL;
UINT32 GL_TEXTURE_W = 0;
UINT32 GL_TEXTURE_H = 0;
void MyLoadTexture(wchar_t* textureFile)
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
CLSID encoderClsid;
EncoderParameters encoderParameters;
ULONG transformation;
UINT width;
UINT height;
Status stat;
// Get a JPEG image from the disk.
Image* image = new Image(textureFile);
Bitmap* pbitMap = (Bitmap*) image;
UINT w= pbitMap->GetWidth();
UINT h = pbitMap->GetHeight();
// UINT size = image->GetPaletteSize();
// printf("The size of the palette is %d bytes.\n", size);
// ColorPalette* palette = (ColorPalette*)malloc(size);
// image->GetPalette(palette, size);
Rect rect(0,0,w,h);
BitmapData* pBitmapData = new BitmapData;
pbitMap->LockBits(&rect,ImageLockModeRead,PixelFormat32bppARGB,pBitmapData);
int offset = pBitmapData->Stride - w *4 ;
BYTE* pByte = (BYTE*)pBitmapData->Scan0;
GL_TEXTURE_DATA = new UINT32[h*w];
int iCount = 0;
for (int i = 0; i
{
for (int j = 0;j
{
GL_TEXTURE_DATA[iCount++] = (pByte[3]<<24) + (pByte[0]<<16) + (pByte[1]<<8) + (pByte[2]);;
//memcpy(GL_TEXTURE_DATA+iCount,pByte,4);
//iCount++;
pByte += 4;
}
pByte += offset;
}
GL_TEXTURE_W = w;
GL_TEXTURE_H = h;
pbitMap->UnlockBits(pBitmapData);
delete image;
delete pBitmapData;
GdiplusShutdown(gdiplusToken);
//LoadBitmap(,"c:\\img\\5.bmp");
}
SIZE size;
HDC hdc;
HDC hMemDC;
bool CreateText(HWND hWnd,HFONT hFont ,LPCTSTR lpszText, unsigned int &tex)
{
hdc = ::GetDC(hWnd);;
HFONT hOldFont = (HFONT)SelectObject(hdc,hFont);
int nTexWidth,nTexHeight;
HBITMAP _hBmp = NULL;
#if 0 // 这种方法得到的位图尺寸变形很大????
::GetTextExtentPoint32(hdc, lpszText, len, &size);
HDC hMemDC = ::CreateCompatibleDC(hdc);
nTexWidth = size.cx;
nTexHeight = size.cy;
BITMAPINFO bmi;
ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = nTexWidth;
bmi.bmiHeader.biHeight = nTexHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
//(这里需要定义一个指针指向位图的数据:
BYTE * _pBmpBits; // 位图的数据指针)
_hBmp = CreateDIBSection( hMemDC, &bmi, DIB_RGB_COLORS,
(void **) &pBmpBits, NULL, 0 );
if ( NULL == _hBmp || NULL == pBmpBits)
{
return false;
}
// 将hBmp和hFont加入到hDc
SelectObject( hMemDC, _hBmp );
SetBkColor(hMemDC, RGB(0, 0, 0));
SetTextColor(hMemDC, RGB(255, 255, 255));
SetBkMode(hMemDC, OPAQUE);
TextOut(hMemDC, 0, 0, lpszText, len);
int nBitBytes = bmi.bmiHeader.biBitCount / 8;
for (int index = 0; index
{
pBmpBits[index+3] = (pBmpBits[index] > 0) ? 0xff : 0x00;
}
#else // 这种算法得到的图象是经过字符反走样后的结果,显示效果佳(推荐)
UCHAR *pBmpBits = NULL;
::GetTextExtentPoint32(hdc, lpszText, strlen(lpszText), &size);
HBITMAP hbitmap = CreateBitmap(size.cx, size.cy,1,32, NULL);
if(!hbitmap)
return false;
hMemDC = ::CreateCompatibleDC(hdc);
if(hMemDC)
{
HBITMAP hPrevBmp = (HBITMAP)SelectObject(hMemDC,hbitmap);
HFONT hPrevFont = (HFONT)SelectObject(hMemDC, hFont);
SetBkColor(hMemDC, RGB(255, 255, 255));
::SetTextColor(hMemDC, RGB(0, 0, 0));
SetBkMode(hMemDC, OPAQUE);
TextOut(hMemDC, 0, 0, lpszText, strlen(lpszText));
// copy GDI bitmap to DIB
BITMAP bm;
SelectObject(hdc,hbitmap);
GetObject(hbitmap, sizeof(bm), &bm);
size.cx = bm.bmWidth; /*(bm.bmWidth + 31) & (~31); */
size.cy = bm.bmHeight;
nTexWidth = size.cx;
nTexHeight = size.cy;
int bufsize = size.cy * /*(((bm.bmWidth + 31) & (~31)) /8)*/size.cx *4;
pBmpBits = new UCHAR[bufsize];
memset(pBmpBits, 0, sizeof(UCHAR)*bufsize);
struct {
BITMAPINFOHEADER bih;
RGBQUAD col[2];
}bic;
BITMAPINFO *binf = (BITMAPINFO *)&bic;
binf->bmiHeader.biSize = sizeof(binf->bmiHeader);
binf->bmiHeader.biWidth = bm.bmWidth;
binf->bmiHeader.biHeight = bm.bmHeight;
binf->bmiHeader.biPlanes = 1;
binf->bmiHeader.biBitCount = 32;
binf->bmiHeader.biCompression = BI_RGB;
binf->bmiHeader.biSizeImage = bufsize;
binf->bmiHeader.biXPelsPerMeter = 1;
binf->bmiHeader.biYPelsPerMeter = 1;
binf->bmiHeader.biClrUsed = 0;
binf->bmiHeader.biClrImportant = 0;
::GetDIBits(hdc, hbitmap, 0, bm.bmHeight, pBmpBits, binf,DIB_RGB_COLORS);
SelectObject(hMemDC,hPrevBmp);
int nBitBytes = binf->bmiHeader.biBitCount / 8;
for (int index = 0; index
{
pBmpBits[index+3] = (pBmpBits[index] > 0) ? 0xff : 0x00;
}
}
#endif
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nTexWidth, nTexHeight, 0