O'Reilly logo

OpenGL Insights by Christophe Riccio, Patrick Cozzi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

WebGL for OpenGL Developers
Patrick Cozzi and Scott Hunter
3.1 Introduction
Dont get us wrong—we are C++ developers at heart. We’ve battled triple-pointers,
partial template specialization, and vtable layouts under multiple inheritance. Yet,
through a strange series of events, we are now full-time JavaScript developers. This
is our story.
At the SIGGRAPH 2009 OpenGL BOF, we first heard about WebGL, an up-
coming web standard for a graphics API based on OpenGL ES 2.0 available to
JavaScript through the HTML5 canvas element, basically OpenGL for JavaScript.
We had mixed feelings. On the one hand, WebGL brought the promise of devel-
oping zero-footprint, cross-platform, cross-device, hardware-accelerated 3D applica-
tions. On the other, it requires us to develop in JavaScript. Could we do large-scale
software development in JavaScript? Could we write high-performance graphics code
in JavaScript?
After nearly a year of development resulting in over 50,000 lines of JavaScript
and WebGL code, we have answered our own questions: properly written JavaScript
scales well, and WebGL is a very capable API with tremendous momentum. This
chapter shares our experience moving from developing with C++ and OpenGL for
the desktop to developing with JavaScript and WebGL for the web. We focus on
the unique aspects of moving OpenGL to the web, not on porting OpenGL code to
OpenGL ES.
27
3
28 IDiscovering
3.2 The Benefits of WebGL
Loosely speaking, WebGL brings OpenGL ES 2.0 to JavaScript and, therefore, to
the web. From a web developers point of view, this is a natural progression for
web-deliverable media types: first there was text, then images, then video, and n ow
interactive 3D. From an OpenGL developer’s point of view (our point of view), we
have a new way to deliver applications: the web. Compared to traditional desktop
applications, the web has several advantages.
3.2.1 Zero-Footprint
Plugins aside, browsing to a web page does not require an install, nor does it require
the user to have administrator privileges. Users simply browse to a URL and expect
their content. As application developers, having such a low barrier to entry enables us
to reach the widest possible market. In our work at Analytical Graphics, Inc. (AGI),
many of our users do not have administrator privileges and have to go through long
processes to have new software installed. WebGL helps us overcome these barriers.
3.2.2 Cross-Platform
The web provides a convenient way to reach all the major desktop operating systems:
Windows, Linux, and OS X. In fact, part of our motivation for using WebGL at AGI
was to support multiple platforms. We have found very few differences across plat-
forms, with the biggest difference being the presence of ANGLE on Windows, which
translates WebGL (OpenGL ES 2.0) to Direct3D 9, as discussed in Chapter 39.
As of this writing, which comes less than a year a fter the release of the WebGL 1.0
specification, desktop bro wsers supporting WebGL include Chrome, Firefox, Safari,
and the Opera 12 alpha. Internet Explorer ( IE) does not support WebGL; however,
several workarounds exist, with our preferred option being Google Chrome Frame.
1
Chrome Frame is an IE plugin that does not require administrator privileges to install
and that brings Chrome ’s JavaScript engine and open web technologies, including
WebGL, to IE. IE’s networking layer is still used, but pages that include a meta tag
requesting Chrome Frame are presented using Chrome Frame and are able to use
WebGL.
Even with multiple developers actively working in the same code base using dif-
ferent operating systems and browsers, we have found very few differences across
browsers, especially Chrome and Firefox.
3.2.3 Cross-Device
Another advantage of WebGL is that web browsers supporting WebGL are start-
ing to become available on tablets and phones. See Figure 3.1. Currently, Firefox
1
developers.google.com/chrome/chrome-frame/
3. WebGL for OpenGL Developers 29
Figure 3.1. From top to bottom, WebGL running in Safari on OS X, in Chrome on Win-
dows, in Chromium on Linux, and in Firefox Mobile on Android. Over 800 satellites are
propagated server-side, streamed, and interpolated client-side and rendered as billboards. The
globe is rendering with day and night textures; a specular map; a bump map; and a cloud map
with shadows.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required