是的,我知道有 2 个。诀窍是,您必须使用 Quartz(CGContext* 函数)渲染到纹理,然后渲染该纹理以供用户查看。
如果您关心性能,也可以使用 Quartz 生成纹理图集。
创建一个纹理生成工具(在 xCode 中)once you know the basics of rendering a font 相当容易。
您所要做的就是拥有一个有效的 CGContext。您可以在 texture loader 中找到一些非常棒的示例代码。
基本上代码如下:
// Create the cgcontext as shown by links above
// Now to render text into the cg context,
// the drop the raw data behind the cgcontext
// to opengl. 2 ways to do this:
// 1) CG* way: (advantage: easy to use color)
CGContextSelectFont(cgContext, "Arial", 24, kCGEncodingMacRoman);
// set color to yellow text
CGContextSetRGBFillColor(cgContext, 1, 1, 0, 1) ; // Be sure to use FILL not stroke!
// draw it in there
CGContextShowTextAtPoint(cgContext, 20, 20, "HI THERE", strlen("HI THERE") ) ;
/*
// WAY #2: this way it's always black and white
// DRAW SOME TEXT IN IT
// that works ok but let's try cg to control color
UIGraphicsPushContext(cgContext);
UIFont *helv = [UIFont fontWithName:@"Helvetica" size:[UIFont systemFontSize]];
NSString* msg = @"Hi hello" ;
[msg drawInRect:CGRectMake(0,0,pow2Width,pow2Height) withFont:helv] ;
UIGraphicsPopContext();
*/
// put imData into OpenGL's memory
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pow2Width, pow2Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imData);
CHECK_GL ;
它看起来非常好并且抗锯齿,
ios 字体列表是available here,和prerenders here