Book Image

WebGL Game Development

By : Sumeet Arora
Book Image

WebGL Game Development

By: Sumeet Arora

Overview of this book

<p>WebGL, the web implementation of Open GL, is a JavaScript API used to render interactive 3D graphics within any compatible web browser, without the need for plugins. It helps you create detailed, high-quality graphical 3D objects easily. WebGL elements can be mixed with other HTML elements and composites to create high-quality, interactive, creative, innovative graphical 3D objects.</p> <p>This book begins with collecting coins in Super Mario, killing soldiers in Contra, and then quickly evolves to working out strategies in World of Warcraft. You will be guided through creating animated characters, image processing, and adding effects as part of the web page canvas to the 2D/3D graphics. Pour life into your gaming characters and learn how to create special effects seen in the most powerful 3D games. Each chapter begins by showing you the underlying mathematics and its programmatic implementation, ending with the creation of a complete game scene to build a wonderful virtual world.</p>
Table of Contents (17 chapters)
WebGL Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Understanding request animation frames


Most HTML5-enabled browsers have implemented a new function window.requestAnimationFrame(). This function is a better alternative to the setTimeout and setInterval functions. The function is designed to invoke rendering functions in your gaming application, such as the drawScene function in our case. It executes in a safe way. It executes the target function only when the browser/tab has focus, which saves precious GPU resources. Using this function, we can obtain a rendering cycle that goes as fast as the browsers allow.

To use this function, we included a new file in our code, webgl-utils.js (https://code.google.com/p/webglsamples/source/browse/book/extension/webgl-utils.js). This small library has many useful functions but we will use only one function from it. We like this library since it has implemented this function in a cross-browser fashion. If a browser does not support it, then it invokes the setTimeout function. The following is the code...