使用objective-c在iPhone openGL ES中绘制文本 [英] Draw text in iPhone openGL ES using just objective-c
本文介绍了使用objective-c在iPhone openGL ES中绘制文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要在openGL中绘制一些文本,然后对其进行旋转和翻译。需要只使用objective-c。有什么帮助?
A need to draw some text in openGL and then make rotations and translations over it. Need to use just objective-c. Any help?
推荐答案
使用Photoshop或其他东西创建如下的纹理文件。
Use Photoshop or something to create a texture file like below.
|ABCDEFGH|
|IJKLMNOP|
|QRSTU...|
sample.png
计算每个字符的UV位置。
Calculate UV position of each character.
float eachCharHeight = 0.125f;
float eachCharWidth = 0.125f;
char charToDraw = 'a';
int indexOfChar = charToDraw - 65; // 'a' = 65
float uValueForCharA = (float)(indexOfChar / 8) * eachCharHeight;
float vValueForCharA = (float)(indexOfChar % 8) * eachCharWidth;
设置texcoords并绘制。
Set texcoords and draw.
glPushMatrix();
glRotatef(...); // or translate
glEnable(GL_TEXTURE_2D);
glBindTexture(texture);
float vertices[8] = {0.0f, 0.0f, 1.0f, 0.0f, ...};
float texcoords[8] = {uValueForCharA, vValueForCharA,
uValueForCharA + eachCharWidth, ...};
...
glPopMatrix();
这篇关于使用objective-c在iPhone openGL ES中绘制文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文