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

Texture wrapping


As seen in the previous example in the Applying a texture to the square section, let's first take a quick look at the texture mapping coordinates.

var textureCoordinates = [
  1.0,  1.0,
  0.0,  1.0,
  1.0,  0.0,
  0.0,  0.0
];

The texture coordinates lie in the range 0.0 to 1.0. However, imagine if we use values like -1 to 2.0 or 1.5 to 2.0. Now, these values lie outside the previous range. Which texel from the texture should WebGL pick? Let's think for a second and evaluate our options. If the s value goes outside the range, we could say that if s > 1.0, then s = 1.0 and if s < 0.0, then s = 0. Here, we are clamping, which means that we are always picking the border values if the value goes outside the range. Or, if we say the texture is cylindrical and s = 1.2, then the integer value is dropped and we get the value 0.2. So, texture wrapping describes which texel to pick if the values lie outside the range [0.0, 1.0]. The wrapping mode is specified separately for both...