Render text on canvas using WebGL

倾然丶 夕夏残阳落幕 提交于 2019-12-04 21:29:08

问题


I want to render some text on a canvas using WebGL, which API of WebGL should be used?

Note: "text" can be either plain text or HTML snippet with CSS style


回答1:


Most demos that I've seen that do text of any sort (like a FPS counter) simply create an HTML element with the text they want and position it over the canvas. This would probably be a good approach for most text that you would want to show "in" a canvas (ie: menus).

The only exception would be if you want the text to be an actual part of the 3d scene (like, say, text on a billboard), in which case the methodologies wouldn't be any different than rendering text in standard OpenGL. You can find a very good robust example here: http://dmedia.dprogramming.com/?n=Tutorials.TextRendering1

There's also a WebGL tutorial about text here.




回答2:


For WebGL-rendered text, you can write text to a canvas "2d" context, then create a texture from the canvas. Denny Koch does that in his EnergizeGL framework.



来源:https://stackoverflow.com/questions/2844794/render-text-on-canvas-using-webgl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!