Can You Use Canvas.getContext('3d')? If Yes, How?


Answer :

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


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.

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.


Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable