Html 你可以使用 canvas.getContext('3d') 吗?如果是,如何?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9812237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:17:23  来源:igfitidea点击:

Can you use canvas.getContext('3d')? If yes, how?

htmlcanvashtml5-canvas

提问by 11684

I read about the canvas tag in HTML5, and always saw getContext('2d').
The parameter is '2d', so isn't there another possibility like '3d'?
And, how could you use that? I tried 3D before, but didn't really understand (due to a non-explaining tutorial). Any Tutorials?

我读过 HTML5 中的 canvas 标签,并且总是看到getContext('2d').
参数是'2d',那么不是还有'3d'这样的可能性吗?
而且,你怎么能用它?我之前尝试过 3D,但并没有真正理解(由于没有解释性的教程)。任何教程?

回答by Denis Washington

There is a 3D context for canvas, but it is not called "3d", but WebGL("webgl").

画布有一个 3D 上下文,但它不称为“3d”,而是WebGL(“webgl”)。

回答by Steve

WebGL should be available in the most up-to-date versions of all browsers. Use:

WebGL 应该在所有浏览器的最新版本中可用。用:

<!DOCTYPE html>
<html>
 <body>
 <canvas id='c'></canvas>
  <script>
    var c = document.getElementById('c');
    var gl = c.getContext('webgl') || c.getContext("experimental-webgl");
    gl.clearColor(0,0,0.8,1);
    gl.clear(gl.COLOR_BUFFER_BIT);
</script>
</body>
</html>

how could you use that? I tried 3D before, but didn't really understand

你怎么能用它?我之前尝试过3D,但不是很懂

  • if you think "real" languages are difficult, you will have a lot of trouble with WebGL. In some respects it is quite high level, in other respects it is quite low level. You should brush up on your maths(geometry) and prepare for some hard work.
  • three.js is a very appreciated library that allows you to do yet a lot of 3d without dealing with webgl directly, check it out.
  • 如果您认为“真正的”语言很难,那么您在使用 WebGL 时就会遇到很多麻烦。在某些方面是相当高的水平,在其他方面是相当低的水平。你应该复习你的数学(几何)并为一些艰苦的工作做好准备。
  • Three.js 是一个非常受欢迎的库,它允许你在不直接处理 webgl 的情况下做很多 3d,看看吧。

回答by Peter

It's possible to get a WebGL context, which would give you access to that API, allowing for OpenGL ES 2.0-like 3D rendering.

可以获取WebGL 上下文,它可以让您访问该 API,从而允许进行类似 OpenGL ES 2.0 的 3D 渲染。

回答by Ed S.

The 3d context is not yet implemented in most browsers. I believe that there is an experimental version of Opera that supplies one, and an addon for FF that does the same, but none of them are ready for primetime. You'll have to wait for wide adoption and implementation.

大多数浏览器尚未实现 3d 上下文。我相信有一个实验版的 Opera 可以提供一个,还有一个 FF 的插件可以做同样的事情,但它们都没有准备好迎接黄金时段。您将不得不等待广泛采用和实施。

and I think JavaScript is more easy than a real programming language

我认为 JavaScript 比真正的编程语言更容易

Javascript is a 'real' programming language. Being a high level language does not make it a toy or fake (and this is coming from a systems guy who, in your opinion, writes code in "real" programming languages every day).

Javascript 是一种“真正的”编程语言。成为一种高级语言并不会使它成为玩具或假货(这来自一个系统人员,在您看来,他每天都用“真正的”编程语言编写代码)。