使用2D和3D上下文的画布3D绘图 [英] Canvas 3D drawing using both 2D and 3D context

查看:164
本文介绍了使用2D和3D上下文的画布3D绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于webgl / opengl不支持文本绘制,因此可以使用2D上下文使用3D上下文和文本绘制绘制3D对象?

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规格说,如果您在已经位于不同 getContext /scripting.html#concept-canvas-context-mode\">桌面模式,并且两个上下文不兼容,则返回 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上下文的画布3D绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆