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

HtmlCanvasHtml5 Canvas

Html Problem Overview


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?

Html Solutions


Solution 1 - Html

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

Solution 2 - Html

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

<!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

  • 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.

Solution 3 - Html

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.

Solution 4 - Html

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.

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

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).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Question11684View Question on Stackoverflow
Solution 1 - HtmlDenis WashingtonView Answer on Stackoverflow
Solution 2 - HtmlSteveView Answer on Stackoverflow
Solution 3 - HtmlPeterView Answer on Stackoverflow
Solution 4 - HtmlEd S.View Answer on Stackoverflow