|
No, WebGL is not a 2D API. Neither is its predecessor, OpenGL. This comment from the article is particularly misleading. > OpenGL is at its essence a 2D API. The vertex shader accepts something as input and it produces 2D vertices in device coordinates (-1 to 1) as output. This, and some of the comments in this thread, perhaps stem from a misunderstanding of the projection matrices. The projection that you do yourself is a projection from a large, arbitrary, 3D space to a small 3D space where x, y, and z are restricted to [-1, 1]. These are the device coordinates (http://www.vizitsolutions.com/portfolio/webgl/normalizedDevi...). The hardware is very good at projecting this small 3D space onto the screen. Indeed, it is possible to write a 3D program entirely within the device coordinates. This example draws two triangles, without any projection, where one is clearly behind the other.
http://www.vizitsolutions.com/portfolio/webgl/translationMat...
Drag the slider to see one triangle move behind the other. Even this is a simplified explanation. There are a lot more details here, including all the math: http://www.songho.ca/opengl/gl_projectionmatrix.html
This shows why the output from a vertex shader, gl_position, is a vec4. It is definitely not a 2D value. That said, yes, WebGL is great :) |