OpenGL ES texture fonts
来源:互联网 发布:用java调用weka j48 编辑:程序博客网 时间:2024/04/30 06:22
http://www.allegro.cc/forums/thread/599388
I would like to implement texture fonts in OpenGL ES. Is it possible to use GL_ALPHA textures? They are more space efficient than GL_RGBA. Is it possible to color the text when using GL_ALPHA textures? How? Could you send a sample code?
OpenGL ES support GL_ALPHA. It's then up to the OpenGL ES driver whether the texture you've supplied in GL_ALPHA form remains so, which will depend on whether your GPU supports GL_ALPHA. I believe that the PowerVR in the iPhone does (and can confirm that the example texture class provided by Apple uploads as GL_ALPHA when you load a suitable PNG or supply data tagged as being of that format), otherwise I'm not very certain.
Colour text using GL_ALPHA in OpenGL ES almost exactly as you would with normal OpenGL. So, for example, set the texture environment mode to 'modulate':
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Then subsequently use calls to glColor4f (the number of combinations and permutations of glColor is reduced in OpenGL ES) to set the colour of the next string. Alternatively, supply something to glColorPointer (either directly supply data, or use the connected vertex buffer object (VBO) measures) if you want to specify colour per-vertex.
Just on the off chance that you are targetting the iPhone (my guess is that it is currently the most targetted OpenGL ES platform, but I'm fully aware that there are several other OpenGL ES platforms that are viable), note that the implementation of VBOs means that using them doesn't provide anything even close to the speed boost you'd get for switching on a conventional desktop target. There are some minor throughput increases, but definitely if you're starting out then don't worry about them now. The speed difference isn't very great, and you can worry about them later in the day — they're an extension that is easy to patch on to existing code.
EDIT:
Oh! Sample code! If you'll excuse the higgledy-piggledy blend of C++ and Objective-C:
That code is hardcoded to the particular font bitmap I was using, as shown by the way that it doesn't even use ASCII for its internal table. CVertexArray and CTexCoordArray are my own little classes for storing stuff that will later be passed to glVertexArray and glTexCoordArray (via a VBO, but whatever), these two lines:
TextSheet = [[Texture2D alloc] initWithImage:[UIImage imageNamed:@"font.png"]]; [TextSheet Activate];
Just load and then activate a texture from the file 'font.png' using Apple's example texture class. They're Objective-C, which is why they might look slightly odd.
The text ends up being output in whatever colour was last set with glColor4f. The SetScale function is specific to the projection matrix I have set up elsewhere and the size of the font. You'll notice that each glyph is a very small number of pixels indeed (typically three or four across by five high), so I needed to be very specific about ensuring that texels map exactly to pixels, or things would look really blurry.
- OpenGL ES texture fonts
- openGL ES 2.0 笔记 texture
- Android OpenGL ES->Compressed Texture
- Converting FFmpeg frame to OpenGL ES texture
- opengl es 2.0 Reder to texture iOS
- Unity android Texture Opengl ES 数据通信
- Android ApiDemos示例解析(201):Graphics->OpenGL ES->Compressed Texture
- OpenGL ES 帧缓冲对象(FBO):Render to texture
- IOS 中openGL使用教程3(openGL ES 入门篇 | 纹理贴图(texture)使用)
- Android 中使用OpenGL ES进行2D开发(纹理Texture使用)
- android OpenGL ES实现渲染到透明的纹理 render to transparent texture
- 罗大柚OpenGL ES教程系列LessonFour(Part X):rendering multiple objects with different texture
- OpenGL ES From the Ground Up, Part 6: Textures and Texture Mapping
- Android 中使用OpenGL ES进行2D开发(纹理Texture使用)
- OPENGL ES
- OpenGL ES
- OpenGL ES
- opengl es
- 感觉真好
- 真的
- TCLinearList
- Gnuplot 简单使用
- 如何提高时间的利用效率?
- OpenGL ES texture fonts
- C++中的虚函数(virtual function)
- Ajax无刷新二级联动
- 随笔
- 假如你的职业不是非常完美
- 使用JDBC+POI把Excel中的数据导出到MySQL
- 自己动手实现一个简单的String类
- 谁有VS T人外挂地址说下
- 随机数