既然 webgl/opengl 不支持文本绘制,那么可以使用 3D context 绘制 3D 对象,使用 2D context 绘制文本吗?
最佳答案
不,不幸的是不是。
HTML 5 spec表示如果您在已经位于不同 context mode 中的 Canvas 元素上调用 getContext
并且两个上下文不兼容则返回null
。
不幸的是,“webgl”和“2d” Canvas 不兼容,因此您将得到 null
:
var canvas = document.getElementById('my-canvas');
var webgl = canvas.getContext("webgl"); // Get a 3D webgl context, returns a context
var twod = canvas.getContext("2d"); // Get a 2D context, returns null
关于html - 使用 2D 和 3D 上下文的 Canvas 3D 绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2928558/