【发布时间】:2011-06-07 14:44:30
【问题描述】:
我目前正在处理一个 OPENGL ES 2.0 项目。我正在制作一个条形图应用程序。我在制作图表方面取得了成功。我正在尝试在图表上插入文本。我发现没有直接的解决方案可以实现相同的目标。
我遇到了一个 OPENGL ES 1.1 代码,其中包含以下几行。
文件:在 GLViewController.m 中(来自 drawView 函数)
Texture2D *textTex = [[Texture2D alloc] initWithString:@"Text"
dimensions:CGSizeMake(100., 40.0)
alignment:UITextAlignmentCenter
font:[UIFont boldSystemFontOfSize:10.0]];
[textTex drawAtPoint:CGPointMake(160.0, 100.0) depth:-1];
在 Texture2D.m 文件中,
- (void) drawAtPoint:(CGPoint)point depth:(CGFloat)depth
{
GLfloat coordinates[] = {
0, _maxT,
_maxS, _maxT,
0, 0,
_maxS, 0
};
GLfloat width = (GLfloat)_width * _maxS,
height = (GLfloat)_height * _maxT;
GLfloat vertices[] = {
-width / 2 + point.x, -height / 2 + point.y, depth,
width / 2 + point.x, -height / 2 + point.y, depth,
-width / 2 + point.x, height / 2 + point.y, depth,
width / 2 + point.x, height / 2 + point.y, depth
};
glBindTexture(GL_TEXTURE_2D, texture.name);
glVertexPointer(3, GL_FLOAT, 0, vertices); //1
glTexCoordPointer(2, GL_FLOAT, 0, coordinates); //2
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
当我尝试将此代码转换为 OPENGL ES 2.0 代码时,我无法为标记为 1 和 2 的行找到合适的转换。有人可以帮我将此代码转换为 OPENGL ES 2.0 代码吗?
或者如果有人知道在屏幕上写文字的更简单方法,请告诉我。
【问题讨论】:
-
你有没有做到这一点?如果能分享代码就太好了
标签: iphone ios text opengl-es opengl-es-2.0