Game Development Reference
In-Depth Information
WebGL Origins
Version 1.0 of the WebGL specification was completed in March 2011 by the Khronos Group. WebGL is
based on OpenGL Embedded Systems (ES) 2.0, which, in turn, is derived from OpenGL.
In 1992, version 1.0 of OpenGL was released as a non-proprietary alternative to Silicon Graphics' Iris GL.
The GL Shading Language (GLSL) was introduced in 2004 when version 2.0 of OpenGL was released.
GLSL is a C-like language that lets you control the vertex and fragment shaders of the imaging pipeline.
This pipeline will be discussed later in the chapter. As of this writing, the current version of OpenGL is 4.2.
OpenGL ES is a subset of OpenGL and is built for use in embedded devices like mobile phones, which
have lower processing power and fewer capabilities than a desktop computer. OpenGL sometimes has
multiple ways of performing the same task; for example, to draw vertices, you can use both a
glBegin…glEnd section or vertex buffer objects (VBOs). OpenGL ES only uses VBOs, which are the most
performance-friendly option. While more restrictive, having a cleaner API path can provide a more
straightforward development direction to follow. Most things that can be done in OpenGL can be done in
OpenGL ES (a notable exception is that there is no 3D texture support).
OpenGL ES 1.0 is based on OpenGL 1.5. OpenGL ES 2.0 is based on OpenGL 2.0 and so supports
GLSL. In following with being a trimmed language, OpenGL ES 2.0 no longer offers fixed functionality.
Having to use the GLSL does increase the learning curve of WebGL; however, you can set minimal
shaders, which can then be incrementally enhanced.
How does WebGL work?
WebGL is a JavaScript API binding to the GPU of a computer's graphics card. WebGL is rendered within
the HTML 5 <canvas> element and requires no browser plug-in. C style shaders (GLSL) are compiled at
run time.
To use WebGL you need a browser that supports WebGL and a graphics card and operating system
(OS) that are new enough to support OpenGL. We will discuss these requirements in more depth later on
in the chapter.
Uses and limitations
Unlike some other HTML graphics APIs, obtaining a WebGL rendering environment does require quite a
bit of work. This is because we have to set up the WebGL context, view matrices, and shaders. The payoff
is the ability to draw rich 3D environs. As your skill level improves, you will find that moving more
functionality to the shader can improve performance and offer a wide range of cool effects and realism.
If you are developing a 2D game with no textures or lighting, then WebGL is probably overkill, and using
the "2D" canvas context could be better.
 
Search WWH ::




Custom Search