NGL  6.5
The NCCA Graphics Library
ngl::Light Class Reference

Simple class to encapsulate OpenGL Light functions this will fill in the following structure. More...

#include <Light.h>

+ Inheritance diagram for ngl::Light:
+ Collaboration diagram for ngl::Light:

Public Member Functions

void setPosition (const Vec3 &_p) noexcept
 set the light position More...
 
void setColour (const Colour &_c) noexcept
 set the light colour More...
 
void setSpecColour (const Colour &_c) noexcept
 set the specular colour More...
 
 Light () noexcept
 default constructor this set nothing so the light will not illuminate More...
 
 Light (const Light &_l) noexcept
 copy ctor this set nothing so the light will not illuminate More...
 
 Light (const Vec3 &_pos, const Colour &_col, LightModes _lightmode) noexcept
 ctor to create the light More...
 
 Light (const Vec3 &_pos, const Colour &_col, const Colour &_specColour, LightModes _lightmode) noexcept
 ctor to create the light More...
 
virtual ~Light () noexcept
 destructor when light is destroyed we turn it off More...
 
void disable () noexcept
 Disable the light by calling glDisable(GL_LIGHT0+LightNo);. More...
 
virtual void enable () noexcept
 Enables the light and automatically allocates an OpenGL light ID. More...
 
Vec4 getPos () const noexcept
 returns the current light position as a Vector More...
 
Colour getColour () const noexcept
 returns the current light colour More...
 
Colour getSpecColour () const noexcept
 returns the current light Specular colour More...
 
void setAttenuation (Real _constant=1.0, Real _linear=0.0, Real _quadratic=0.0) noexcept
 set the light attenuation More...
 
void loadToShader (std::string _uniformName) const noexcept
 method to load the current light values to the shader that is active at present More...
 
void setTransform (Mat4 &_t) noexcept
 set a transform so that the light position is multiplied by this value (default is identity matrix) More...
 

Protected Attributes

Vec4 m_position
 m_pos is used to store the light position w used for point / dir light values More...
 
Colour m_diffuse
 Colour used to give the light a colour. More...
 
Colour m_specular
 specular highlight colour used for the lights More...
 
Colour m_ambient
 ambient light colour used for the lights More...
 
LightModes m_lightMode
 used to hold the current lights mode More...
 
Real m_constantAtten
 attenuation value for constant falloff More...
 
Real m_linearAtten
 attenuation value for linear falloff More...
 
Real m_quadraticAtten
 attenuation value for Quadratic falloff More...
 
bool m_active
 active if true else off More...
 
Real m_cutoffAngle
 the spot cutoff angle for directional and point lights this is set to 180 by default, and other values are cos(radians(angle)) More...
 
Mat4 m_transform
 the transform applied to the light before loading to the shader this is usually the inverse projection matrix for normal OpenGL style eye-cord calculations but is left for the Application to calculate and pass for easier implementation of different light models More...
 

Detailed Description

Simple class to encapsulate OpenGL Light functions this will fill in the following structure.

struct Lights { vec4 position; vec4 ambient; vec4 diffuse; vec4 specular; };

Author
Jon Macey
Version
5.0
Date
18/08/11 updated to remove deprecated GL stuff and all work with glsl 150 Last Revision 29/10/09 Updated to NCCA coding standard
Todo:
this will need to be changed to work with GLSL lights for GL_VERSION > 3.x

Definition at line 68 of file Light.h.

Constructor & Destructor Documentation

ngl::Light::Light ( )
inlinenoexcept

default constructor this set nothing so the light will not illuminate

Definition at line 103 of file Light.h.

ngl::Light::Light ( const Light _l)
noexcept

copy ctor this set nothing so the light will not illuminate

Definition at line 47 of file Light.cpp.

ngl::Light::Light ( const Vec3 _pos,
const Colour _col,
LightModes  _lightmode 
)
noexcept

ctor to create the light

Parameters
[in]_posthe light position
[in]_colthe light colour
[in]_lightmodethe mode to set the light to either local or remote

Definition at line 29 of file Light.cpp.

ngl::Light::Light ( const Vec3 _pos,
const Colour _col,
const Colour _specColour,
LightModes  _lightmode 
)
noexcept

ctor to create the light

Parameters
[in]_posthe light position
[in]_colthe light colour
[in]_specColourthe specular component of the light
[in]_lightmodethe mode to set the light to either local or remote

Definition at line 65 of file Light.cpp.

virtual ngl::Light::~Light ( )
inlinevirtualnoexcept

destructor when light is destroyed we turn it off

Definition at line 128 of file Light.h.

Member Function Documentation

void ngl::Light::disable ( )
noexcept

Disable the light by calling glDisable(GL_LIGHT0+LightNo);.

Definition at line 90 of file Light.cpp.

References m_active.

void ngl::Light::enable ( )
virtualnoexcept

Enables the light and automatically allocates an OpenGL light ID.

Returns
true if there is a free openGL light ID available.

Reimplemented in ngl::SpotLight.

Definition at line 84 of file Light.cpp.

References m_active.

Colour ngl::Light::getColour ( ) const
inlinenoexcept

returns the current light colour

Returns
Colour colour

Definition at line 147 of file Light.h.

+ Here is the caller graph for this function:

Vec4 ngl::Light::getPos ( ) const
inlinenoexcept

returns the current light position as a Vector

Returns
Vector pos

Definition at line 142 of file Light.h.

+ Here is the caller graph for this function:

Colour ngl::Light::getSpecColour ( ) const
inlinenoexcept

returns the current light Specular colour

Returns
Colour Spec colour

Definition at line 152 of file Light.h.

+ Here is the caller graph for this function:

void ngl::Light::loadToShader ( std::string  _uniformName) const
noexcept

method to load the current light values to the shader that is active at present

Parameters
[in]_uniformNamename of the uniform to set

Definition at line 105 of file Light.cpp.

References ngl::Singleton< ShaderLib >::instance(), ngl::Colour::m_a, m_active, m_ambient, ngl::Colour::m_b, m_constantAtten, m_cutoffAngle, m_diffuse, ngl::Colour::m_g, m_lightMode, m_linearAtten, m_position, m_quadraticAtten, ngl::Colour::m_r, m_specular, m_transform, ngl::Vec4::m_x, ngl::Vec4::m_y, ngl::Vec4::m_z, ngl::ShaderLib::setShaderParam1f(), and ngl::ShaderLib::setShaderParam4f().

+ Here is the call graph for this function:

void ngl::Light::setAttenuation ( Real  _constant = 1.0,
Real  _linear = 0.0,
Real  _quadratic = 0.0 
)
noexcept

set the light attenuation

Parameters
[in]_constantthe constant attenuation
[in]_linearattenuation
[in]_quadraticattenuation

Definition at line 96 of file Light.cpp.

References m_constantAtten, m_linearAtten, and m_quadraticAtten.

void ngl::Light::setColour ( const Colour _c)
inlinenoexcept

set the light colour

Parameters
[in]_cthe colour to set

Definition at line 85 of file Light.h.

void ngl::Light::setPosition ( const Vec3 _p)
inlinenoexcept

set the light position

Parameters
[in]_pthe new light position

Definition at line 76 of file Light.h.

void ngl::Light::setSpecColour ( const Colour _c)
inlinenoexcept

set the specular colour

Parameters
[in]_cthe colour to set for the specular

Definition at line 94 of file Light.h.

void ngl::Light::setTransform ( Mat4 _t)
noexcept

set a transform so that the light position is multiplied by this value (default is identity matrix)

Parameters
[in]_tthe transform matrix

Definition at line 141 of file Light.cpp.

References m_transform.

Member Data Documentation

bool ngl::Light::m_active
protected

active if true else off

Definition at line 206 of file Light.h.

Colour ngl::Light::m_ambient
protected

ambient light colour used for the lights

Definition at line 186 of file Light.h.

Real ngl::Light::m_constantAtten
protected

attenuation value for constant falloff

Definition at line 194 of file Light.h.

Real ngl::Light::m_cutoffAngle
protected

the spot cutoff angle for directional and point lights this is set to 180 by default, and other values are cos(radians(angle))

Definition at line 211 of file Light.h.

Colour ngl::Light::m_diffuse
protected

Colour used to give the light a colour.

Definition at line 178 of file Light.h.

LightModes ngl::Light::m_lightMode
protected

used to hold the current lights mode

Definition at line 190 of file Light.h.

Real ngl::Light::m_linearAtten
protected

attenuation value for linear falloff

Definition at line 198 of file Light.h.

Vec4 ngl::Light::m_position
protected

m_pos is used to store the light position w used for point / dir light values

Definition at line 174 of file Light.h.

Real ngl::Light::m_quadraticAtten
protected

attenuation value for Quadratic falloff

Definition at line 202 of file Light.h.

Colour ngl::Light::m_specular
protected

specular highlight colour used for the lights

Definition at line 182 of file Light.h.

Mat4 ngl::Light::m_transform
protected

the transform applied to the light before loading to the shader this is usually the inverse projection matrix for normal OpenGL style eye-cord calculations but is left for the Application to calculate and pass for easier implementation of different light models

Definition at line 217 of file Light.h.


The documentation for this class was generated from the following files: