【发布时间】:2010-06-19 13:46:27
【问题描述】:
需要在 openGL 中绘制一些文本,然后对其进行旋转和平移。只需要使用objective-c。有什么帮助吗?
【问题讨论】:
标签: iphone objective-c xcode opengl-es
需要在 openGL 中绘制一些文本,然后对其进行旋转和平移。只需要使用objective-c。有什么帮助吗?
【问题讨论】:
标签: iphone objective-c xcode opengl-es
使用 Photoshop 或其他工具创建如下纹理文件。
|ABCDEFGH|
|IJKLMNOP|
|QRSTU...|
sample.png
计算每个字符的UV位置。
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 并绘制。
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();
【讨论】: