25.02.2013 Views

Peter Lubbers - Pro HTML 5 Programming

Pro HTML 5 Programming

Pro HTML 5 Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

260<br />

CHAPTER 11 ■ THE FUTURE OF <strong>HTML</strong>5<br />

will be incremental, with specific features and their specifications evolving individually, rather than as a<br />

consolidated effort. Browsers will take up features as they gain consensus, and the upcoming features<br />

might even be widely available in browsers well before <strong>HTML</strong>5 is set in stone. The community<br />

responsible for driving the Web forward is committed to evolving the platform to meet the needs of users<br />

and developers.<br />

WebGL<br />

WebGL is an API for 3D graphics on the Web. Historically, several browser vendors including Mozilla,<br />

Opera, and Google have worked on separate experimental 3D APIs for JavaScript. Today, WebGL is<br />

progressing along a path toward standardization and wide availability across <strong>HTML</strong>5 browsers. The<br />

standardization process is taking place with browser vendors and The Khronos Group, the body<br />

responsible for OpenGL, a cross-platform 3D drawing standard created in 1992. OpenGL, currently at<br />

specification version 4.0, is widely used in gaming and computer-aided design applications as a<br />

counterpart and competitor to Microsoft’s Direct3D<br />

As you saw in Chapter 2, you get a 2D drawing context from a canvas element by calling<br />

getContext("2d") on the element. Unsurprisingly, this leaves the door open for additional types of<br />

drawing contexts. WebGL also uses the canvas element, but through a 3D context. Current<br />

implementations use experimental vendor prefixes (moz-webgl, webkit-3d, etc.) as the arguments to the<br />

getContext() call. In a WebGL-enabled build of Firefox, for example, you can get a 3D context by calling<br />

getContext("moz-webgl") on a canvas element. The API of the object returned by such a call to<br />

getContext() is different from the 2D canvas equivalent, as this one provides OpenGL bindings instead<br />

of drawing operations. Rather than making calls to draw lines and fill shapes, the WebGL version of the<br />

canvas context manages textures and vertex buffers.<br />

<strong>HTML</strong> in Three Dimensions<br />

WebGL, like the rest of <strong>HTML</strong>5, will be an integral part of the web platform. Because WebGL renders to a<br />

canvas element, it is part of the document. You can position and transform 3D canvas elements, just as<br />

you can place images or 2D canvases on a page. In fact, you can do anything you can do with any other<br />

canvas element, including overlaying text and video and performing animations. Combining other<br />

document elements and a 3D canvas will make heads-up displays (HUDs) and mixed 2D and 3D<br />

interfaces much simpler to develop when compared to pure 3D display technologies. Imagine taking a<br />

3D scene and using <strong>HTML</strong> markup to overlay a simple web user interface on it. Quite unlike the<br />

nonnative menus and controls found in many OpenGL applications, WebGL software will incorporate<br />

nicely styled <strong>HTML</strong>5 form elements with ease.<br />

The existing network architecture of the Web will also complement WebGL. WebGL applications<br />

will be able to fetch resources such as textures and models from URLs. Multiplayer games can<br />

communicate with WebSockets. For example, Figure 11-1 shows an example of this in action. Google<br />

recently ported the classic 3D game Quake II to the Web using <strong>HTML</strong>5 WebSocket, Audio, and WebGL,<br />

complete with multiplayer competition. Game logic and graphics were implemented in JavaScript,<br />

making calls to a WebGL canvas for rendering. Communication to the server to coordinate player<br />

movement was achieved using a persistent WebSocket connection.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!