Adding lights
In this chapter, we will learn how to illuminate a 3D scene using OpenGL lights.
Getting ready
Include the necessary files to use OpenGL lights, materials, and draw. Add the following code to the top of the source file:
#include "cinder/gl/gl.h" #include "cinder/gl/Light.h" #include "cinder/gl/Material.h"
Also add the following using
statements:
using namespace ci; using namespace ci::app; using namespace std;
How to do it…
We will use the default OpenGL light rendering methods to illuminate our scene. We will use the ci::gl::Material
and ci::gl::Light
classes, which are wrappers around the OpenGL functionality.
Declare
ci::gl::Material
to define the material properties of the objects being drawn andci::Vec3f
to define the lights position.gl::Material mMaterial; Vec3f mLightPos;
Let's set the materials
Ambient
,Diffuse
,Specular
,Emission
, andShininess
properties by adding the following code in thesetup
method:mMaterial.setAmbient( Color::black() ); mMaterial.setDiffuse( Color( 1...