OPENGL ES显示字符串(Windows Mobile)

简介:

当然国外有POWERVR提供基于OPENGL ES的SDK封装的APPPRINT3D类来处理字符串显示和GLFONT for windows ce等。

但是我们这里只整理了一个函数:

 

 
  1. void  glTextShow(WCHAR *fontname, int fontsize, int style, int x, int y, const WCHAR *string)     
  2. {     
  3.       int len, xx = 0, yy = 0, nbpoints = 0, i;     
  4.       GLshort *points;     
  5.       GLushort *indices;     
  6.       HFONT font;     
  7.       LOGFONTW    lf;         
  8.       RECT rect;     
  9.       static HBITMAP bmp;     
  10.       static BYTE *img;     
  11.       static HDC hdc = NULL;     
  12.       static BITMAPINFO bi;     
  13.       SIZE sz;     
  14.       static EGLint width, height;     
  15.        
  16.       if(!fontname || !string)     
  17.           return;     
  18.       if(!string[0])     
  19.           return;     
  20.        
  21.       if(!hdc)     
  22.       {             
  23.           hdc = CreateCompatibleDC(GetDC(hWnd));         
  24.                
  25.           eglQuerySurface(eglDisplay, eglSurface, EGL_WIDTH, &width);     
  26.           eglQuerySurface(eglDisplay, eglSurface, EGL_HEIGHT, &height);     
  27.        
  28.               
  29.           ZeroMemory(&bi, sizeof(BITMAPINFO));     
  30.           bi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);     
  31.           bi.bmiHeader.biWidth = width;     
  32.           bi.bmiHeader.biHeight = height;      
  33.           bi.bmiHeader.biBitCount = 8;     
  34.           bi.bmiHeader.biPlanes = 1;     
  35.           bi.bmiHeader.biCompression = BI_RGB;     
  36.                
  37.           bmp = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, &img, NULL, 0);     
  38.            
  39.           SelectObject(hdc, bmp);     
  40.                
  41.           SelectObject(hdc, GetStockObject(BLACK_BRUSH));     
  42.        
  43.           SetBkMode(hdc, TRANSPARENT);     
  44.           SetTextColor(hdc, RGB(255, 255, 255));                 
  45.       }     
  46.        
  47.       Rectangle(hdc, 0, 0, width, height);     
  48.       ZeroMemory(img, width * height);     
  49.        
  50.       lf.lfCharSet = DEFAULT_CHARSET;     
  51.       lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;     
  52.       lf.lfEscapement = 0;     
  53.       wcscpy(lf.lfFaceName, fontname);     
  54.       lf.lfHeight = -(fontsize * GetDeviceCaps(GetDC(hWnd), LOGPIXELSY) / 72);     
  55.       lf.lfItalic = (style & 1) ? TRUE : FALSE;     
  56.       lf.lfOrientation = 0;     
  57.       lf.lfOutPrecision = OUT_DEFAULT_PRECIS;     
  58.       lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;     
  59.       lf.lfQuality = DEFAULT_QUALITY;     
  60.       lf.lfStrikeOut = FALSE;     
  61.       lf.lfUnderline = (style & 4) ? TRUE : FALSE;     
  62.       lf.lfWidth = 0;     
  63.       lf.lfWeight = (style & 2) ? FW_BOLD : FW_NORMAL;     
  64.            
  65.       font = CreateFontIndirectW(&lf);     
  66.        
  67.       SelectObject(hdc, font);     
  68.        
  69.       len = wcslen(string);     
  70.        
  71.       GetTextExtentPointW(hdc, string, len, &sz);     
  72.        
  73.       rect.left = max(0, min(x, width));     
  74.       rect.top = max(0, min(y, height));     
  75.       rect.right = min(rect.left + sz.cx, width);     
  76.       rect.bottom = min(rect.top + sz.cy, height);     
  77.        
  78.       DrawTextW(hdc, string, len, &rect, DT_LEFT | DT_BOTTOM);     
  79.            
  80.       points = (GLshort*)malloc(sz.cx * sz.cy * 2 * sizeof(short));     
  81.        
  82.       for(yy = rect.top; yy < rect.bottom; yy++)     
  83.       {     
  84.           for(xx = rect.left; xx < rect.right; xx++)     
  85.           {     
  86.               if(img[xx + (height - yy) * width] != 0)     
  87.               {     
  88.                   points[nbpoints * 2 + 0] = xx - x;     
  89.                   points[nbpoints * 2 + 1] = (short)(rect.top + sz.cy - (yy - rect.top)) - y;     
  90.                   nbpoints++;     
  91.               }     
  92.           }     
  93.       }     
  94.       DeleteObject(font);     
  95.            
  96.       indices = (GLushort*)malloc(nbpoints * sizeof(GLushort));     
  97.       for(i = 0; i < nbpoints; i++)     
  98.           indices[i] = i;     
  99.        
  100.       glMatrixMode(GL_PROJECTION);     
  101.       glPushMatrix();     
  102.       glLoadIdentity();      
  103.        
  104.       glOrthox(0, _INT2FIXED(width),      
  105.               0, _INT2FIXED(height),      
  106.               0, _INT2FIXED(1));     
  107.        
  108.        
  109.       glMatrixMode(GL_MODELVIEW);     
  110.       glPushMatrix();     
  111.       glLoadIdentity();      
  112.        
  113.       glDisable(GL_DEPTH_TEST);     
  114.            
  115.       glTranslatex(_INT2FIXED(x), _INT2FIXED(y), 0);         
  116.            
  117.       glEnable(GL_ALPHA_TEST);     
  118.       glAlphaFuncx(GL_NOTEQUAL, 0);     
  119.       glDisableClientState(GL_TEXTURE_COORD_ARRAY);     
  120.       glDisableClientState(GL_COLOR_ARRAY);     
  121.       glDisableClientState(GL_NORMAL_ARRAY);     
  122.       glEnableClientState (GL_VERTEX_ARRAY);     
  123.       glVertexPointer(2, GL_SHORT, 0, points);     
  124.        
  125.       glDrawElements(GL_POINTS,     
  126.                           nbpoints,     
  127.                           GL_UNSIGNED_SHORT,     
  128.                           indices);     
  129.            
  130.       glDisable(GL_ALPHA_TEST);     
  131.        
  132.       glEnable(GL_DEPTH_TEST);     
  133.        
  134.       glPopMatrix();     
  135.       glMatrixMode(GL_PROJECTION);     
  136.       glPopMatrix();     
  137.       glMatrixMode(GL_MODELVIEW);     
  138.        
  139.       free(indices);     
  140.       free(points);     
  141. }   



本文转自 yarin 51CTO博客,原文链接: http://blog.51cto.com/yarin/381955 ,如需转载请自行联系原作者
相关文章
|
消息中间件 Kafka API
番外篇:使用nssm工具将ES、Kibana、Logstash或者其他.bat文件部署为Windows后台服务的方法
使用NSSM工具安装bat文件为Windows服务 nssm是一个可以把bat批处理文件部署为Windows服务的小工具。例如很多.net项目可能还是在Windows服务器上面跑的,但是很多组件只提供了.bat文件,例如elk三件套、或者后面会用到的kafka等等。
306 0
番外篇:使用nssm工具将ES、Kibana、Logstash或者其他.bat文件部署为Windows后台服务的方法
|
5月前
|
XML 小程序 Java
【Android App】三维投影OpenGL ES的讲解及着色器实现(附源码和演示 超详细)
【Android App】三维投影OpenGL ES的讲解及着色器实现(附源码和演示 超详细)
55 0
|
6月前
|
存储 API Windows
2.4 Windows驱动开发:内核字符串拷贝与比较
在上一篇文章`《内核字符串转换方法》`中简单介绍了内核是如何使用字符串以及字符串之间的转换方法,本章将继续探索字符串的拷贝与比较,与应用层不同内核字符串拷贝与比较也需要使用内核专用的API函数,字符串的拷贝往往伴随有内核内存分配,我们将首先简单介绍内核如何分配堆空间,然后再以此为契机简介字符串的拷贝与比较。
42 0
2.4 Windows驱动开发:内核字符串拷贝与比较
|
11月前
|
存储 资源调度 索引
【windows批处理batch】.bat文件 字符串处理相关操作(字符串定义、分割、拼接、替换、切片、查找)
【windows批处理batch】.bat文件 字符串处理相关操作(字符串定义、分割、拼接、替换、切片、查找)
726 0
|
存储 编解码 算法
Opengl ES之LUT滤镜(上)
Opengl ES之连载系列
343 0
|
数据安全/隐私保护 开发者
OpenGL ES 多目标渲染(MRT)
Opengl ES连载系列
221 0
|
数据安全/隐私保护 索引
Opengl ES之纹理数组
Opengl ES连载系列
180 0
|
数据安全/隐私保护
Opengl ES之水印贴图
Opengl ES之连载系列
88 0
|
Java 数据安全/隐私保护 Android开发
Opengl ES之矩阵变换(下)
Opengl ES连载系列
84 0
|
Java API 数据安全/隐私保护
Opengl ES之矩阵变换(上)
Opengl ES连载系列
87 0