Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

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/

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}