如何从方法“drawAtPoint:withFont:”生成的文本创建opengl纹理
我正在尝试在我的 opengl 应用程序中动态渲染纹理。
基本上我尝试使用 (CGSize)drawAtPoint:(CGPoint)point withFont:(UIFont *)font
并将其捕获到纹理。但我无法弄清楚如何将 CGContext 内容转换为纹理。
I am trying to render texture dynamically in my opengl application.
Basically I am tring to use (CGSize)drawAtPoint:(CGPoint)point withFont:(UIFont *)font
and capture it to a texture. But I am not able to figure out how to convert CGContext stuff to texture.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否是您正在寻找的答案,但也许(也许)您可以使用 CGBitmapContextGetData 捕获当前视图的位图,将其插入到 NSImage 中并编写代码来识别/裁剪它。我不知道如何在
OpenGL
中加载纹理(还没有查过),但我确信可以从NSImage
转到OpenGL
纹理以一种或另一种方式。如果您不介意粗略的解决方案,您可以将其写入磁盘并以这种方式加载。苹果可能在他们的 API 中添加了一些东西来避免这种情况,但我不确定。这主要是一个概念性的答案。I'm not sure this is the answer you are looking for, but maybe (maybe) you can capture a bitmap of your current view with
CGBitmapContextGetData
, plug it into aNSImage
and write the code to recognize/crop it. I don't know how you load textures inOpenGL
(haven't looked that up yet) but I know for certain it is possible to go fromNSImage
toOpenGL
texture one way or another. If you don't mind a crude solution you could write it to the disk and load it that way. Apple probably put something in their API's to avoid this but I'm not sure. This was mostly a conceptual answer.