Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

sglMaterial Class Reference

#include <sglMaterial.hpp>

Inheritance diagram for sglMaterial::

sglStatelet sglObject List of all members.

Public Types

enum  SideEnum {
  eFRONT = GL_FRONT,
  eBACK = GL_BACK,
  eFRONT_AND_BACK = GL_FRONT_AND_BACK
}
enum  ColorModeEnum {
  eOFF = 0,
  eAMBIENT = GL_AMBIENT,
  eDIFFUSE = GL_DIFFUSE,
  eSPECULAR = GL_SPECULAR,
  eAMBIENT_AND_DIFFUSE = GL_AMBIENT_AND_DIFFUSE,
  eEMISSION = GL_EMISSION
}

Public Methods

 sglMaterial ()
virtual ~sglMaterial ()
void setAmbient (float r, float g, float b, SideEnum side=eFRONT_AND_BACK)
void getFrontAmbient (float &r, float &g, float &b) const
void getBackAmbient (float &r, float &g, float &b) const
void setDiffuse (float r, float g, float b, SideEnum side=eFRONT_AND_BACK)
void getFrontDiffuse (float &r, float &g, float &b) const
void getBackDiffuse (float &r, float &g, float &b) const
void setSpecular (float r, float g, float b, SideEnum side=eFRONT_AND_BACK)
void getFrontSpecular (float &r, float &g, float &b) const
void getBackSpecular (float &r, float &g, float &b) const
void setEmission (float r, float g, float b, SideEnum side=eFRONT_AND_BACK)
void getFrontEmission (float &r, float &g, float &b) const
void getBackEmission (float &r, float &g, float &b) const
void setAlpha (float alpha, SideEnum side=eFRONT_AND_BACK)
float getFrontAlpha () const
float getBackAlpha () const
void setShininess (float shininess, SideEnum side=eFRONT_AND_BACK)
float getFrontShininess () const
float getBackShininess () const
void setColorMaterial (SideEnum side, ColorModeEnum mode)
void getColorMaterial (SideEnum &side, ColorModeEnum &mode) const
void apply (sglCurrState *curr_state) const
virtual bool getSorted () const
virtual void printInfo (ostream &ostrm, const char *indent_string) const

Detailed Description

This statelet encapsulates the glMaterial*(..) as well as glColorMaterial() and glEnable(GL_COLOR_MATERIAL) functions that specifies material properties of an object for use in lighting calculations (when the sglLighting statelet is enabled). This statelet contains the constant color parameters for both front and back faces including ambient, diffuse, specular and emissive color components. It also manages alpha (for transparency) and shininess parameters.

Using color material enables one of the color components to track the vertex color of the geometry (if present) rather than a constant color specified by the components described above. To do this, the sglMaterial::setColorMaterial(..) member function is called with one of the SideEnum and ColorModeEnum tokens.

The default constructor initializes the object to match the OpenGL defaults for materials as follows (for both front and back):

Note that (1) the alpha value is handled separately in this class and corresponds to the alpha component of the diffuse color component in OpenGL, (2) the color material is disabled by default, and (3) this class does not support the color index modes.

Example:

   sglMaterial *statelet = new sglMaterial;
   statelet->setAmbient(0.f, 0.f, 0.f);                       // FRONT_AND_BACK
   statelet->setAmbient(0.f, 0.f, 0.f, sglMaterial::eBACK);  // BACK only
   statelet->setDiffuse(1.f, 1.f, 1.f);
   statelet->setSpecular(1.f, 1.f, 1.f);
   statelet->setAlpha(1.0f);
   statelet->setShininess(64.0f);

   // overrides the call to setAmbient and setDiffuse for the front side
   statelet->setColorMaterial(sglMaterial::eFRONT,
                              sglMaterial::eAMBIENT_AND_DIFFUSE);

Definition at line 82 of file sglMaterial.hpp.


Member Enumeration Documentation

enum sglMaterial::SideEnum
 

Tokens to define which face a parameter is to be applied to.

Enumeration values:
eFRONT   the front face (as defined by the sglFrontFace statelet).
eBACK   the back face.
eFRONT_AND_BACK   both sides.

Definition at line 86 of file sglMaterial.hpp.

enum sglMaterial::ColorModeEnum
 

Color component tokens used for color material specification.

Enumeration values:
eOFF   disable color material.
eAMBIENT   map color vertices to the ambient color component.
eDIFFUSE   map color vertices to the diffuse color component.
eSPECULAR   map color vertices to the specular color component.
eAMBIENT_AND_DIFFUSE   map color vertices to the ambient and diffuse color components.
eEMISSION   map color vertices to the emissive color component.

Definition at line 99 of file sglMaterial.hpp.


Constructor & Destructor Documentation

sglMaterial::sglMaterial ( )
 

Default constructor. Initializes to the default OpenGL material parameters.

sglMaterial::~sglMaterial ( ) [virtual]
 

virtual destructor.


Member Function Documentation

void sglMaterial::setAmbient ( float r,
float g,
float b,
SideEnum side = eFRONT_AND_BACK )
 

Set the ambient color components

Parameters:
r   The red color component.
g   The green color component.
b   The blue color component.
side   One of eFRONT, eBACK, eFRONT_AND_BACK. The default is eFRONT_AND_BACK

void sglMaterial::getFrontAmbient ( float & r,
float & g,
float & b ) const
 

Query the ambient color components for the front face.

Parameters:
r   On return, contains the red color component.
g   On return, contains the green color component.
b   On return, contains the blue color component.

void sglMaterial::getBackAmbient ( float & r,
float & g,
float & b ) const
 

Query the ambient color components for the back face.

Parameters:
r   On return, contains the red color component.
g   On return, contains the green color component.
b   On return, contains the blue color component.

void sglMaterial::setDiffuse ( float r,
float g,
float b,
SideEnum side = eFRONT_AND_BACK )
 

Set the diffuse color components

Parameters:
r   The red color component.
g   The green color component.
b   The blue color component.
side   One of eFRONT, eBACK, eFRONT_AND_BACK. The default is eFRONT_AND_BACK

void sglMaterial::getFrontDiffuse ( float & r,
float & g,
float & b ) const
 

Query the diffuse color components for the front face.

Parameters:
r   On return, contains the red color component.
g   On return, contains the green color component.
b   On return, contains the blue color component.

void sglMaterial::getBackDiffuse ( float & r,
float & g,
float & b ) const
 

Query the diffuse color components for the back face.

Parameters:
r   On return, contains the red color component.
g   On return, contains the green color component.
b   On return, contains the blue color component.

void sglMaterial::setSpecular ( float r,
float g,
float b,
SideEnum side = eFRONT_AND_BACK )
 

Set the specular color components

Parameters:
r   The red color component.
g   The green color component.
b   The blue color component.
side   One of eFRONT, eBACK, eFRONT_AND_BACK. The default is eFRONT_AND_BACK

void sglMaterial::getFrontSpecular ( float & r,
float & g,
float & b ) const
 

Query the specular color components for the front face.

Parameters:
r   On return, contains the red color component.
g   On return, contains the green color component.
b   On return, contains the blue color component.

void sglMaterial::getBackSpecular ( float & r,
float & g,
float & b ) const
 

Query the specular color components for the back face.

Parameters:
r   On return, contains the red color component.
g   On return, contains the green color component.
b   On return, contains the blue color component.

void sglMaterial::setEmission ( float r,
float g,
float b,
SideEnum side = eFRONT_AND_BACK )
 

Set the emissive color components

Parameters:
r   The red color component.
g   The green color component.
b   The blue color component.
side   One of eFRONT, eBACK, eFRONT_AND_BACK. The default is eFRONT_AND_BACK

void sglMaterial::getFrontEmission ( float & r,
float & g,
float & b ) const
 

Query the emissive color components for the front face.

Parameters:
r   On return, contains the red color component.
g   On return, contains the green color component.
b   On return, contains the blue color component.

void sglMaterial::getBackEmission ( float & r,
float & g,
float & b ) const
 

Query the emissive color components for the back face.

Parameters:
r   On return, contains the red color component.
g   On return, contains the green color component.
b   On return, contains the blue color component.

void sglMaterial::setAlpha ( float alpha,
SideEnum side = eFRONT_AND_BACK )
 

Set the alpha component (opacity) of the material.

Parameters:
alpha   Opacity in the range from zero (transparent) to one (opaque). The default is 1.0
side   One of eFRONT, eBACK, eFRONT_AND_BACK. The default is eFRONT_AND_BACK

float sglMaterial::getFrontAlpha ( ) const [inline]
 

Query the alpha value for the front face.

Returns:
The front face alpha value.

Definition at line 236 of file sglMaterial.hpp.

float sglMaterial::getBackAlpha ( ) const [inline]
 

Query the alpha value for the back face.

Returns:
The back face alpha value.

Definition at line 241 of file sglMaterial.hpp.

void sglMaterial::setShininess ( float shininess,
SideEnum side = eFRONT_AND_BACK )
 

Set the shininess factor, the specular exponent (used with specular color component to define the specular highlights), for either side.

Parameters:
shininess   A value from 0 (matte) to 128 (mirror). Values out side this range will be clamped. The default is zero.
side   One of eFRONT, eBACK, eFRONT_AND_BACK. The default is eFRONT_AND_BACK

float sglMaterial::getFrontShininess ( ) const [inline]
 

Query the shininess (specular exponent) of the front face material.

Returns:
The shininess factor of the front face.

Definition at line 255 of file sglMaterial.hpp.

float sglMaterial::getBackShininess ( ) const [inline]
 

Query the shininess (specular exponent) of the back face material.

Returns:
The shininess factor of the back face.

Definition at line 260 of file sglMaterial.hpp.

void sglMaterial::setColorMaterial ( SideEnum side,
ColorModeEnum mode )
 

Specify the color material mode for a given side.

Parameters:
side   One of eFRONT, eBACK, eFRONT_AND_BACK. The default is eFRONT_AND_BACK
mode   One of ColorModeEnum tokens. If mode is eOFF this is disabled; otherwise, the color value of the material property set by the mode parameter is specified via the color values in the geometry and not by the parameters in this instance. Note, it is not possible to specify a different color mode for front and back sides. default: eFRONT_AND_BACK and eOFF

void sglMaterial::getColorMaterial ( SideEnum & side,
ColorModeEnum & mode ) const [inline]
 

Query the current color material state.

Parameters:
side   On return, contains the current side that the color material will be applied to.
mode   On return, contains the current color material color mode. This value is only valid if side is not eOFF.

Definition at line 281 of file sglMaterial.hpp.

void sglMaterial::apply ( sglCurrState * curr_state ) const [virtual]
 

Apply this state change to the current rendering state.

Parameters:
curr_state   Required for statelets that affect one another. For example the sglTransparency sets up depth mask and blending modes which interact with the sglBlending and sglDepthMask statelets, and the curr_state object is used to resolve these internal issues.

Reimplemented from sglStatelet.

bool sglMaterial::getSorted ( ) const [inline, virtual]
 

Query the sorting mode for this statelet.

Returns:
true if this type of statelet should be sorted by pointer rather than using m_index to index into an array. The defualt implementation is the latter, but if a statelet can take on an inordinate number of states (e.g. a floating point parameter) then true should be returned.

Reimplemented from sglStatelet.

Definition at line 288 of file sglMaterial.hpp.

virtual void sglMaterial::printInfo ( ostream & ostrm,
const char * indent_string ) const [virtual]
 

Output the state of this node to the specified ostream.

Parameters:
ostrm   the ostream to which the output is sent
indent_string   the string (usually spaces) that is output at the beginning of every line of output

Reimplemented from sglStatelet.


The documentation for this class was generated from the following file:
Generated at Mon Jul 1 18:00:08 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001