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

Preface

This book is your foray into building in-browser 3D games. The book starts with an introduction to the basics of the low-level 3D rendering API, WebGL. We then transform the low-level API to an implementation of a sample 3D rendering library. We use this library to build components of a concept game, "5000 AD". We walk you step by step from using 3D assets to the implementation of techniques that are used to build a complete in-browser massive multiplayer online role-playing game.

What this book covers

Chapter 1, Getting Started with WebGL Game Development, covers basic terminologies of 3D and the basics of WebGL, 3D mathematics, and 3D graphics. It also gives a walkthrough of the WebGL API and discusses the structuring of a WebGL application.

Chapter 2, Colors and Shading Languages, explains how to add colors, light, and material to objects in a scene. It discusses how to export 3D objects using tools such as Blender and also explains the basic Wavefront OBJ file format and the JSON file format. Also, we will learn about directional lights in this chapter.

Chapter 3, Loading the Game Scene, teaches us how to handle loading and rendering of multiple objects through coding. This chapter also teaches you to add point lights to your scene.

Chapter 4, Applying Textures, covers all of the topics on how to create, load, and apply textures to 3D objects. It also teaches advanced techniques such as filtering and cubemaps.

Chapter 5, Camera and User Interaction, focuses on evolving our own camera class for our game scene. We will also empower our users to view the game scene from different angles and positions by adding the mouse and keyboard interactivity.

Chapter 6, Applying Textures and Simple Animations to Our Scene, starts by simulating a first-person camera and takes it forward by giving weapons to our character. We also dive deep into different animations techniques used in game engines.

Chapter 7, Physics and Terrains, explains physics simulation and discusses how physics engines control component trajectories as well as work with collision detection in a game.

Chapter 8, Skinning and Animations, covers our study of character animation by understanding the skeleton, which is the base of the character, upon which the body and its motion are built. Then, we learn about skinning and how the bones of the skeleton are attached to the vertices.

Chapter 9, Ray Casting and Filters, unveils a very powerful concept in game development called ray casting, which is used to cover cases that cannot be handled by collision detection. This also covers framebuffers, another very important concept used in game development.

Chapter 10, 2D Canvas and Multiplayer Games, covers the use of 2D rendering in 3D games through canvas 2D, a very powerful 2D drawing API. We also discuss the technology behind HTML-based multiplayer games.

What you need for this book

To learn game development in WebGL, all you need is your favorite text editor and any of the following browsers:

Who this book is for

If you are a programmer who wants to transform the skill of blending imagination and thought in games, this is the book for you. You need to have a good understanding of object-oriented programming, JavaScript, and vector and matrix operations.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Open the SquareGeomtery.js file from client/primitive."

A block of code is set as follows:

<html>
<canvas id="canvasElement"></canvas>
</html>
<script>
this.canvas = document.getElementById("canvasElement");
this.ctx = this.canvas.getContext('2d');
</script>

Any command-line input or output is written as follows:

#node server.js
#npm install socket.io

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes, for example, appear in the text like this: "We can enable the extension in the Settings menu in Google Chrome."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/ support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.