OpenTK使用 FreeType2渲染字母范例
来源:互联网 发布:淘宝刷评给礼品微信号 编辑:程序博客网 时间:2024/05/16 11:26
OpenTK库的.Net Wrapping见http://www.codeproject.com/Articles/13296/Rendering-FreeType-2-with-OpenGL
public class FTText { //public static extern int FT_Init_FreeType(out System.IntPtr lib); //public Bitmap bitmap; public byte[] expanded; public int width; public int height; public FTText() { //初始化库 IntPtr libptr; if (Library.FT_Init_FreeType(out libptr)!=0) return; int size = 50; IntPtr faceptr; if (Face.FT_New_Face(libptr, "J:\\GameProject\\GameProject\\Fonts\\Anonymous.ttf", 0, out faceptr)!=0) return; Face face = (Face)Marshal.PtrToStructure(faceptr, typeof(Face)); Face.FT_Set_Char_Size(faceptr, size << 6, size << 6, 96, 96); Face.FT_Set_Pixel_Sizes(faceptr, size, size); int index = Face.FT_Get_Char_Index(faceptr, ' '); if (Face.FT_Load_Glyph(faceptr, index, FT_LOAD_TYPES.FT_LOAD_DEFAULT)!=0) return; //Convert the glyph to a bitmap System.IntPtr glyph; if (Glyph.FT_Get_Glyph(face.glyphrec, out glyph)!=0) return; Glyph.FT_Glyph_To_Bitmap(out glyph, FT_RENDER_MODES.FT_RENDER_MODE_NORMAL, 0, 1); BitmapGlyph glyph_bmp = (BitmapGlyph)Marshal.PtrToStructure(glyph, typeof(BitmapGlyph)); byte[] bmp = new byte[glyph_bmp.bitmap.width * glyph_bmp.bitmap.rows]; Marshal.Copy(glyph_bmp.bitmap.buffer, bmp, 0, bmp.Length); //Next we expand the bitmap into an opengl texture width = next_po2(glyph_bmp.bitmap.width); height = next_po2(glyph_bmp.bitmap.rows); //expanded = bmp; expanded = new byte[2 * width * height]; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { expanded[2 * (i + j * width)] = expanded[2 * (i + j * width) + 1] = (i >= glyph_bmp.bitmap.width || j >= glyph_bmp.bitmap.rows) ? (byte)0 : bmp[i + glyph_bmp.bitmap.width * j]; } } //expanded = null; bmp = null; //// Dispose of these as we don't need Face.FT_Done_Face(faceptr); Library.FT_Done_FreeType(libptr); } internal int next_po2(int a) { int rval = 1; while (rval < a) rval <<= 1; return rval; } }
0 0
- OpenTK使用 FreeType2渲染字母范例
- Qt 中使用freeType2实现简单的文本渲染
- Freetype2渲染Unicode初步
- FreeType2 使用心得
- FreeType2的简单使用
- FreeType2的简单使用
- FreeType2的简单使用
- freetype2使用基础程序
- FreeType2使用总结
- FreeType2使用总结
- freetype2
- FreeType2
- freetype2
- freetype2
- VS2013环境下使用FreeType2
- freetype渲染字体范例
- openTK学习
- 使用FreeImage写Freetype2字体图片
- UVA10099 - The Tourist Guide(floyd + 最小值的最大化)
- Windows 平台下局域网劫持测试工具 – EvilFoca
- C++ 多线程编程总结
- 条件表达式注意的问题
- Git原理杂谈之pull/push命令
- OpenTK使用 FreeType2渲染字母范例
- 【数据结构】顺序栈的实现(c++)
- java内部类的一些细节
- java方法重载和重写
- hdu2588GCD
- hdu-2196 Computer
- 2015-5-28碎碎念
- Linux 驱动之 EXPORT_SYMBOL 函数以及 2.6 内核 Unknown symbol bug 解决办法
- HDU 5242 Game 上海大都会赛 G题