当然国外有POWERVR提供基于OPENGL ES的SDK封装的APPPRINT3D类来处理字符串显示和GLFONT for windows ce等。
但是我们这里只整理了一个函数:
void glTextShow(WCHAR *fontname, int fontsize, int style, int x, int y, const WCHAR *string)
{
int len, xx = 0, yy = 0, nbpoints = 0, i;
GLshort *points;
GLushort *indices;
HFONT font;
LOGFONTW lf;
RECT rect;
static HBITMAP bmp;
static BYTE *img;
static HDC hdc = NULL;
static BITMAPINFO bi;
SIZE sz;
static EGLint width, height;
if(!fontname || !string)
return;
if(!string[0])
return;
if(!hdc)
{
hdc = CreateCompatibleDC(GetDC(hWnd));
eglQuerySurface(eglDisplay, eglSurface, EGL_WIDTH, &width);
eglQuerySurface(eglDisplay, eglSurface, EGL_HEIGHT, &height);
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;
bi.bmiHeader.biCompression = BI_RGB;
bmp = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, &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, fontname);
lf.lfHeight = -(fontsize * GetDeviceCaps(GetDC(hWnd), LOGPIXELSY) / 72);
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);
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);
points = (GLshort*)malloc(sz.cx * sz.cy * 2 * sizeof(short));
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] = (short)(rect.top + sz.cy - (yy - rect.top)) - y;
nbpoints++;
}
}
}
DeleteObject(font);
indices = (GLushort*)malloc(nbpoints * sizeof(GLushort));
for(i = 0; i < nbpoints; i++)
indices[i] = i;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrthox(0, _INT2FIXED(width),
0, _INT2FIXED(height),
0, _INT2FIXED(1));
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glTranslatex(_INT2FIXED(x), _INT2FIXED(y), 0);
glEnable(GL_ALPHA_TEST);
glAlphaFuncx(GL_NOTEQUAL, 0);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glEnableClientState (GL_VERTEX_ARRAY);
glVertexPointer(2, GL_SHORT, 0, points);
glDrawElements(GL_POINTS,
nbpoints,
GL_UNSIGNED_SHORT,
indices);
glDisable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
free(indices);
free(points);
}
谢谢支持!
分享到:
相关推荐
NULL 博文链接:https://yarin.iteye.com/blog/626025
基于opengl es 的显示gif的例子
Android平台采集Camera的YUV原始数据后使用OpenGLES2.0显示,内置YV12格式的YUV分量分离。 附件为完整例子,感谢“李狗蛋52635”提供的GLProgram类。
Android上使用OpenGlEs显示纹理例子程序
2017-10-27 在以前的代码中加入了opengl ES2.0显示点云的功能,代码毫无保留的分享给大家,下载完了不会用的联系我。
自己做过精简,适合做动画,视频播放,纹理加载方式可以根据自己的需求改动。
WinCE mobile openGL ES WinCE mobile openGL ES WinCE mobile openGL ES WinCE mobile openGL ES
使用OpenGL ES对YUV图片进行显示,流程为先提取YUV数据中的Y,U,V分量,在通过纹理贴图的方式,这样就可以达到显示图片的效果
本规范是本人根据《OpenGL ES Profile Specification 2.0.24 (Difference Specification) (April 1, 2009) (Annotated)》进行学习时翻译的,我今天把它提取出来,仅供大家学习使用,帮助想学习OpenGL ES 2.0这一国内...
几本openglES的书打包下载: OpenGL ES Game Development.2004.pdf Mobile 3D Graphics with OpenGL ES and M3G Nov.2007.pdf OpenGL_ES_Programming_Guide_v1.0.2.zip OpenGL ES 2.0 Programming Guide.pdf ...
Windows下基于OpenGLES依据给定的窗口句柄渲染YUV序列,内附实例可以直接运行。 可以渲染YUV420P和YUV444P。支持窗口尺寸变化。
opengl 2.0 to opengl es 2.0
OPENGL ES 3.0编程指南
opengles 3.0游戏开发上 的所有案例 opengles 3.0游戏开发上 的所有案例 opengles 3.0游戏开发上 的所有案例
超棒的Android的OpenGL ES入门教程!由 Per-Erik Bergman写的6个教程,并附带一份OpenGL ES 1.1 Reference Pages。 内容介绍: OpenGL ES Tutorial for Android – Part I – Setting up the view OpenGL ES ...
ES2.x针对可编程管线硬件.OpenGL ES1.0是以OpenGL1.3规范为基础的,OpenGL ES1.1是以OpenGL1.5为基础 的,他们分别又支持common和common lite两种profile.OpenGL ES2.0是参照OpenGL2.0规范定义的”
opengl es 全景显示模式示例demo 分球内显示和球外显示的触屏操作
OpenGL ES Extension Header File this header is defined to contain all defined extension interfaces for OpenGL ES 2 0 and all later versions since later versions are backwards compatible with OpenGL ...
OpenGL ES 3.0 Programming Guide
在Windows平台上使用libpng解码PNG图片,而后用OpenGLES进行显示,有透明度