WebGL is the new standard for 3D graphics on the Web. With WebGL, developers can
harness the full power of the computer’s graphics rendering hardware using only Java
Script, a web browser, and a standard web technology stack. Before WebGL, developers
h
ad to rely on plug-ins or native applications and ask their users to download and install
custom software in order to deliver a true 3D experience.
WebGL is part of the HTML5 family of technologies. While not in the official specifi
cation, it is shipped with most browsers that support HTML5. Like Web Workers, Web
S
ockets, and other technologies outside the official W3C recommendations, WebGL is
an essential component in an emerging suite that is transforming the modern browser
into a first-class application platform.
WebGL works on the majority of desktops, as well as a growing number of mobile
browsers. There are millions of WebGL-enabled seats already installed, most likely in
cluding the machines you run at home and in your office. WebGL is at the center of a
v
ibrant and growing ecosystem that is making the web experience more visually rich
and engaging. There are hundreds of sites, applications, and tools being developed, with
applications ranging from games to data visualization, computer-aided design, and
consumer retail.
While the low-level nature of the WebGL API may appear daunting at first, there are
s
everal open source JavaScript toolkits that take the grunt work out of development. I
want to be careful not to oversell this—3D is still hard work—but these tools at least
make it possible for mere mortals with modest web development experience to get into
the WebGL business. So maybe it’s finally time for you to create that hit game you always
wanted to make. Or maybe today is the day when you blow your boss’s mind with a
dazzling intro graphic for your home page.
In this chapter, we will take a quick tour of the low-level underpinnings of WebGL to
g
ive you a foundation. For the majority of the book, we will use a high-level 3D toolkit,
Three.js, which hides many of the messy details. But it is important to know what these
tools are built upon, so let’s start by exploring WebGL’s core concepts and API.
WebGL—A Technical Definition
WebGL is developed and maintained by the Khronos Group, the standards body that
al
so governs OpenGL, COLLADA, and other specifications you may have heard of. Here
is the official description of WebGL, from the Khronos website:
WebGL is a royalty-free, cross-platform API that brings OpenGL ES 2.0 to the web as a
3D drawing context within HTML, exposed as low-level Document Object Model inter
faces. It uses the OpenGL shading language, GLSL ES, and can be cleanly combined with
o
ther web content that is layered on top or underneath the 3D content. It is ideally suited
for dynamic 3D web applications in the JavaScript programming language, and will be
fully integrated in leading web browsers.
2 | Chapter 1: An Introduction to WebGL