Structure of a WebGL application
As in any 3D graphics library, in WebGL, you need certain components to be present to create a 3D scene. These fundamental elements will be covered in the first four chapters of the book. Starting from Chapter 5, Action, we will cover elements that are not required to have a working 3D scene such as colors and textures and then later on we will move to more advanced topics.
The components we are referring to are as follows:
Canvas: It is the placeholder where the scene will be rendered. It is a standard HTML5 element and as such, it can be accessed using the Document Object Model (DOM) through JavaScript.
Objects: These are the 3D entities that make up part of the scene. These entities are composed of triangles. In Chapter 2, Rendering Geometry, we will see how WebGL handles geometry. We will use WebGL buffers to store polygonal data and we will see how WebGL uses these buffers to render the objects in the scene.
Lights: Nothing in a 3D world can be seen if there are no lights. This element of any WebGL application will be explored in Chapter 3, Lights!. We will learn that WebGL uses shaders to model lights in the scene. We will see how 3D objects reflect or absorb light according to the laws of physics and we will also discuss different light models that we can create in WebGL to visualize our objects.
Camera: The canvas acts as the viewport to the 3D world. We see and explore a 3D scene through it. In Chapter 4, Camera, we will understand the different matrix operations that are required to produce a view perspective. We will also understand how these operations can be modeled as a camera.
This chapter will cover the first element of our list—the canvas. We will see in the coming sections how to create a canvas and how to set up a WebGL context.