æ ¹æ®è¿ä¸ªhttp://yarin.blog.51cto.com/blog/1130898/381955 修æ¹çã
Â
åçæ¯ï¼ å¨å åDCä¸åå符串ï¼ç¶åè·åDCåç´ æ°æ®ï¼å¤ææ°æ®ä¸ä¸º0çï¼å°±æ¯ååçåç´ ï¼è·ååç´ æå¨ä½ç½®ã
å¨OpenGLESæ ¹æ®ä½ç½®ç»ç¹ã
Â
å¼å§ç´æ¥æ¬é£ä¸ªå½æ°ä¸ç¥éæä¹æ¾ç¤ºä¸äºï¼å°±ä¹±æ¹ä¸éï¼ä¼°è®¡é£ä¸ªè®¾ç½®ä¸å¯¹å§ã
对GLESä¸æï¼å 天没çï¼å½æ°é½å¿å å ã
Â
void COpenGLES::glTextShow(int fontsize, int style, int x, int y, const WCHAR *string)
{ //æ¾ç¤ºä¸æ£ç¡®
int len, xx = 0, yy = 0, nbpoints = 0, i;
GLfloat *points;
HFONT font;
LOGFONTW lf;
RECT rect;
static HBITMAP bmp;
static BYTE *img;
static HDC hdc = NULL;
static BITMAPINFO bi;
SIZE sz;
static EGLint width = 800, height = 480;
if(!string)
return;
if(!string[0])
return;
if(!hdc)
{
hdc = CreateCompatibleDC(GetDC(NULL));
ZeroMemory(&bi, sizeof(BITMAPINFO));
bi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = width;
bi.bmiHeader.biHeight = height;
bi.bmiHeader.biBitCount = 8;
bi.bmiHeader.biPlanes = 1;
bmp = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, (void**)&img, NULL, 0);
SelectObject(hdc, bmp);
SelectObject(hdc, GetStockObject(BLACK_BRUSH));
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(255, 255, 255));
}
Rectangle(hdc, 0, 0, width, height);
ZeroMemory(img, width * height);
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfEscapement = 0;
wcscpy(lf.lfFaceName, L"GLES");
lf.lfHeight = fontsize;
lf.lfItalic = (style & 1) ? TRUE : FALSE;
lf.lfOrientation = 0;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfStrikeOut = FALSE;
lf.lfUnderline = (style & 4) ? TRUE : FALSE;
lf.lfWidth = 0;
lf.lfWeight = (style & 2) ? FW_BOLD : FW_NORMAL;
font = CreateFontIndirectW(&lf);
SelectObject(hdc, font);
len = wcslen(string);
GetTextExtentPointW(hdc, string, len, &sz);
y = 480 - y - sz.cy;
rect.left = max(0, min(x, width));
rect.top = max(0, min(y, height));
rect.right = min(rect.left + sz.cx, width);
rect.bottom = min(rect.top + sz.cy, height);
DrawTextW(hdc, string, len, &rect, DT_LEFT | DT_BOTTOM);
HDC dc= GetDC(NULL);
points = (GLfloat*)malloc(sz.cx * sz.cy * 2 * sizeof(GLfloat));
for(yy = rect.top; yy < rect.bottom; yy++)
{
for(xx = rect.left; xx < rect.right; xx++)
{
if(img[xx + (height - yy) * width] != 0)
{
points[nbpoints * 2 + 0] = xx - x;
points[nbpoints * 2 + 1] = (float)(rect.top + sz.cy - (yy - rect.top)) - y;
nbpoints++;
}
}
}
DeleteObject(font);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, (800.0f),0, (480.0f), -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
glColor4f(1.0f,0,0,1.0f);
glDisable(GL_BLEND);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);//ç¦ç¨é¢è²æ°ç»ã
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2,GL_FLOAT,0,points);
glPushMatrix();
glTranslatef(x,y,-0.010001f);
glPointSize(1.0f);
glDrawArrays(GL_POINTS,0,nbpoints);
glPopMatrix();
glFinish();
EGLFlush();
free(points);
} Â
ä¸ç®¡æä¹åï¼ç»äºåä¸åäºï¼è²ä¼¼é度æºæ ¢çã
æçå±å¹800*480çï¼ç´æ¥åæ»äºï¼åä½ååä¹æ¹çåæ»äº
Â
åæ¥å主ç顶ç¹åæ é½æ¯ç¨GL_SHORTåçï¼æé½æ¹æfloatçäº
ç»ç¹ä¹æ¹æäºglDrawArraysï¼
设置æå½±ç©éµçæ¶åä¹ç¨æµ®ç¹åå½æ°glOrthof
æå®é¡¶ç¹æ°ç»ä¹å°±ç¨äºæµ®ç¹åï¼glVertexPointer(2,GL_FLOAT,0,points);
Â
å纯ç»ç¹ä¹åæï¼çº¹çç©éµãé¢è²ç©éµãALPHAãBLENDé½ç¦æ¢æï¼ä¸ç¶å¯è½çä¸è§ã
Â
è²ä¼¼æå½±ç©éµæå®çæ¶åç¨çå½æ°ç±»åä¸é¡¶ç¹ä¸ä¸æ ·ä¼ç»ä¸ä¸å»
æ以设置模åçæ¶åç¨æµ®ç¹åå½æ°ï¼ç»å¾çæ¶åæ好ä¹ç¨æµ®ç¹çåæ
ï¼è¦ç¨xåçé½ç¨xåï¼åå ä¸ç¥ï¼ä½è¿æ¯å ä¸è¾çäºã
glFrustumf对åºGL_FLOAT
glFrustumx对åºGL_FIX
Â
ç¨çæ¶å
ç´æ¥è°ç¨
gl.glTextShow(25,NULL,0,480,L"OpenGLç¼ç¨æå");
å°±å¯ä»¥æ¾ç¤º
è¿ä¸ä¸ªå½æ°å°±ä¼å·æ´ä¸ªå±å¹ï¼å ·ä½ä½¿ç¨ï¼è¿å¾ä¿®æ¹ã估计就æ¹æåæ¥å主é£ç§åæ³äºãããã
Â
Â
Â
Â
å¥½ä¹ æ²¡çï¼ç«ç¶å¯¹ä»¥åççä¸è¥¿åæçäºï¼æåååç°ä»¥åæ¯å¯¹çããã
Â
æå½±ç©éµå½æ°è®¾ç½®ä¸ä¸ªæå½±ç©éµ
Â
å¨æ¨¡åè§å¾ç©éµä¸ç»ä¸è¥¿çæ¶åï¼glLoadIdentity();ä¹åï¼æ¨¡åè§å¾ç©éµé»è®¤çzåç¹å¨å±å¹ä¸
è¦çè§ç»çç©ä½ï¼è¦å°æ¨¡åè§å¾ç©éµç§»å¨å°æå½±ç©éµä¸ã
éè¿å½æ°ï¼glTranslatef(x,y,-0.010001f);移å¨ã
Â
åå¦å°æ´å¤ä¹åï¼æå½±ç©éµè®¾ç½®ç¨fåå½æ°ï¼é½ç¨æµ®ç¹å
顶ç¹ä¹ç¨æµ®ç¹åçæ°æ®è¡¨ç¤º Â
设置æå½±ç©éµçæ¶åï¼å°±è®¾ç½®æå±å¹å¤§å°çï¼æ¹ä¾¿åæ 使ç¨ã
glOrthof(0, (800.0f),0, (480.0f), -1.0f, 1.0f);  平è¡æå½±
glFrustumf(-0.0f, 800.0f, -0.0f, 480.0f, 0.01f,1000.0f); éè§æå½±
Â
Â
å纯ç»ç¹ä¹åæï¼çº¹çç©éµãé¢è²ç©éµãALPHAãBLENDé½ç¦æ¢æï¼ä¸ç¶å¯è½çä¸è§ã
Â
Â