Over a million developers have joined DZone.

Why WebGL is a 2D, Rather than a 3D, API

DZone's Guide to

Why WebGL is a 2D, Rather than a 3D, API

· Web Dev Zone ·
Free Resource

A true open source, API-first CMS — giving you the power to think outside the webpage. Try it for free.

For those of you wanting to develop browser-based 3D graphics, WebGL may be the answer to your prayers.  WebGL enables developers to produce cool 3D images in a Web browser using Javascript, which can result in some pretty nifty effects.  In a recent blog post, Gregg Tavares explains what many people do not realize about WebGL: it is not a 3D API.  

WebGL is an API that extends Javascript to allow for the creation of 3D graphics in a web browser using Canvas.  In order to produce a 3D image, WebGL requires a programmer to provide inputs for image coordinates and image colors.  Tavares's blog details some simple examples of the results of inputting various shaders into WebGL.  He reveals that, no matter how you spin it, WebGL only accepts 2D position and color data.  In order to convert the image to 3D, it is up to the programmer to input the proper 3D shaders due to the 2D nature of WebGL.

In his follow-up post, Tavares delves into image processing by showing readers how to manipulate image colors and detail in WebGL.  He concludes on a positive note highlighting the user-friendliness of this API . . .

 I hope you can see that WebGL is actually a pretty simple API. While it can get more complicated to do 3D that complication is added by you, the programmer, in the form of more complex shaders. --Gregg Tavares

For some more resources on WebGL development, check out the Mozilla Developers Network

Source: http://games.greggman.com/game/webgl-fundamentals/

The New Standard for a Hybrid CMS: GraphQL Support, Scripting as a Service, SPA Support. Watch on-demand now.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}