Help end child hunger
Jan 242014

teapots The Red Book samples included a short demo on OpenGL materials. The demo is quite old but is still valuable when considering the Phong lighting equation. In the original C source file several materials are defined and the resulting app produces an image such as the icon of this post.

This post contains a WebGL demo where the different materials can be applied to a model.

Your browser does not support the canvas tag.
Material :
Ambient: (0.0215 ,0.1745 ,0.0215)
Diffuse: (0.07568 ,0.61424 ,0.07568)
Specular: (0.633 ,0.727811 ,0.633)
Shininess: 76.8

In order to keep the code simpler I wrote a small lib to deal with materials and models (l3dmodels.js). The source code for the javascript bit can be found in here. It assumes a canvas named “canvas” has been declared in HTML.

The demo also uses two third party libs:

The first library contains two functions which are really useful: WebGLUtils.setupWebGL and window.requestAnimFrame. jsMatrix is a great lib that supports the most common matrix and vector operations, namely in the context of GL, such as setting the projection matrix, placing the camera, and performing geometric transformations.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: