html乱码 es,opengl es 显示中文 (利用TextOut)

#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

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trademarks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com. The Android robot is reproduced from work created and shared by Google and is used according to terms described in the Creative Commons 3.0 Attribution License (http://creativecommons.org/licenses/by/3.0/us/legalcode). The unit circle image in Figure 43, from http://en.wikipedia.org/wiki/File:Unit_circle.svg, is used according to the terms described in the Creative Commons Attribution-ShareAlike license, located at http://creativecommons.org/licenses/by-sa/3.0/legalcode. Day skybox and night skybox courtesy of Jockum Skoglund, also known as hipshot, hipshot@zfight.com,http://www.zfight.com. The image of the trace capture button is created and shared by the Android Open Source Project and is used according to terms described in the Creative Commons 2.5 Attribution License.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值