使用 2D 和 3D 上下文的 Canvas 3D 绘图 [英] Canvas 3D drawing using both 2D and 3D context
本文介绍了使用 2D 和 3D 上下文的 Canvas 3D 绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于 webgl/opengl 不支持文本绘制,所以可以使用 3D 上下文绘制 3D 对象,使用 2D 上下文绘制文本吗?
Since the webgl/opengl doesn't support text drawing, so it possible to draw 3D object using 3D context and text drawing using 2D context ?
推荐答案
不,不幸的是不是.
HTML 5 规范 说,如果您在已经位于不同 getContextrel="noreferrer">上下文模式 且两个上下文不兼容则返回null
.
The HTML 5 spec says that if you call getContext
on a canvas element that is already in a different context mode and the two contexts are not compatible then return null
.
不幸的是webgl"和2d"画布不兼容,因此你会得到null
:
Unfortunately "webgl" and "2d" canvases are not compatible and thus you will get 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
这篇关于使用 2D 和 3D 上下文的 Canvas 3D 绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文