sgMaterial Class Reference

#include <sgMaterial.h>

Inheritance diagram for sgMaterial:
sgBase

List of all members.

Public Member Functions

 sgMaterial ()
 sgMaterial (unsigned int shad)
 sgMaterial (const char *vsname, const char *fsname)
 sgMaterial (const char *texfile, BOOL mipmaps=TRUE, unsigned int shad=1)
 sgMaterial (const char *vsname, const char *fsname, const char *texfile, BOOL mipmaps=TRUE)
 ~sgMaterial ()
bool operator== (const sgMaterial &other)
void setDefault ()
void setShader (const char *vsname, const char *fsname)
void setShader (unsigned int shad)
void setTexture2D (unsigned int tex, const char *texfile, BOOL mipmaps=TRUE)
void getUniforms ()
void addParameter (const char *name, void *ptr, unsigned int datatype=0, unsigned int size=3, unsigned int count=1)

Static Public Member Functions

static sgMaterialgetMaterial ()
static sgMaterialgetMaterial (unsigned int shad)
static sgMaterialgetMaterial (const char *vsname, const char *fsname)
static sgMaterialgetMaterial (const char *texfile, BOOL mipmaps=TRUE, unsigned int shad=1)
static sgMaterialgetMaterial (const char *vsname, const char *fsname, const char *texfile, BOOL mipmaps=TRUE)

Public Attributes

sgShadershader
std::vector< sgTexture * > textures
std::vector< unsigned int > texlocation
std::vector< sgMaterialParameterparameters
BOOL culling
unsigned int cullmode
BOOL blending
unsigned int blendsource
unsigned int blenddestination
BOOL lighting
BOOL colors
sgFColorA ambient
sgFColorA diffuse
sgFColorA specular
float shininess
sgFColorA emissive
BOOL alphatest
float alphatestvalue
BOOL depthtest
unsigned int depthtestmode
sgMatrix4x4 mattex

Detailed Description

Material class. Stores and handles a material.


Constructor & Destructor Documentation

sgMaterial::sgMaterial (  ) 

Constructor. Initializes a default material.

sgMaterial::sgMaterial ( unsigned int  shad  ) 

Constructor. Initializes a default material with a default shader.

Parameters:
shad the default shader to use
sgMaterial::sgMaterial ( const char *  vsname,
const char *  fsname 
)

Constructor. Initializes a default material with a shader loaded from the given files.

Parameters:
vsname the name of the vertex shader file to load
fsname the name of the fragment shader file to load
sgMaterial::sgMaterial ( const char *  texfile,
BOOL  mipmaps = TRUE,
unsigned int  shad = 1 
)

Constructor. Initializes a default material with a texture loaded from the given file.

Parameters:
texfile the name of the texture file to load
mipmaps has to be set to FALSE if you don´t want mipmaps to be created for the texture
shad the default shader to use
sgMaterial::sgMaterial ( const char *  vsname,
const char *  fsname,
const char *  texfile,
BOOL  mipmaps = TRUE 
)

Constructor. Initializes a default material with a texture and a shader loaded from the given files.

Parameters:
vsname the name of the vertex shader file to load
fsname the name of the fragment shader file to load
texfile the name of the texture file to load
mipmaps has to be set to FALSE if you don´t want mipmaps to be created for the texture
sgMaterial::~sgMaterial (  ) 

Destructor. Frees the parameters.


Member Function Documentation

void sgMaterial::addParameter ( const char *  name,
void *  ptr,
unsigned int  datatype = 0,
unsigned int  size = 3,
unsigned int  count = 1 
)

Add parameter. Adds a custom parameter, which will be sent to the shader. The pointer is freed automatically!

Parameters:
name the uniform name within the shader
ptr pointer to the parameter
datatype 0 for float or 1 for int
size 0 to 3 for 1 to 4 elements, 4 to 6 for mat2, 3 or 4
count number of parameters with size, usually 1, but higher if you want it as an array in your shader
sgMaterial * sgMaterial::getMaterial ( const char *  vsname,
const char *  fsname,
const char *  texfile,
BOOL  mipmaps = TRUE 
) [static]

Get material. Creates, initializes and returns a default material with a texture and a shader loaded from the given files.

Parameters:
vsname the name of the vertex shader file to load
fsname the name of the fragment shader file to load
texfile the name of the texture file to load
mipmaps has to be set to FALSE if you don´t want mipmaps to be created for the texture
sgMaterial * sgMaterial::getMaterial ( const char *  texfile,
BOOL  mipmaps = TRUE,
unsigned int  shad = 1 
) [static]

Get material. Creates, initializes and returns a default material with a texture loaded from the given file.

Parameters:
texfile the name of the texture file to load
mipmaps has to be set to FALSE if you don´t want mipmaps to be created for the texture
shad the default shader to use
sgMaterial * sgMaterial::getMaterial ( const char *  vsname,
const char *  fsname 
) [static]

Get material. Creates, initializes and returns a default material with a shader loaded from the given files.

Parameters:
vsname the name of the vertex shader file to load
fsname the name of the fragment shader file to load
sgMaterial * sgMaterial::getMaterial ( unsigned int  shad  )  [static]

Get material. Creates, initializes and returns a default materialwith a default shader.

Parameters:
shad the default shader to use
sgMaterial * sgMaterial::getMaterial (  )  [static]

Get material. Creates, initializes and returns a default material.

void sgMaterial::getUniforms (  ) 

Set 2D PVRTC texture. Adds or replaces a texture.

Parameters:
tex index of the texture to replace, or -1 to add a new one
name the name of the file to load, without the type
w the width of the image can´t be set automatically
h the height of the image can´t be set automatically
type the type of the texture
mipmaps has to be set to FALSE if you don´t want mipmaps to be created for this texture Get uniforms. Updates the uniform locations handled by this shader. Has for example to be called after adding a new texture.
bool sgMaterial::operator== ( const sgMaterial other  ) 

== operator. Overloaded == operator to compare two instances of this class.

void sgMaterial::setDefault (  ) 

Set to default. Sets all material parameters to the default ones (textures and shader aren´t effected).

void sgMaterial::setShader ( unsigned int  shad  ) 

Set shader. Assigns a default shader to this material.

Parameters:
shad the default shaders id
void sgMaterial::setShader ( const char *  vsname,
const char *  fsname 
)

Set shader. Assigns a new shader to this material.

Parameters:
vsname the name of the vertex shader file to load
fsname the name of the fragment shader file to load
void sgMaterial::setTexture2D ( unsigned int  tex,
const char *  texfile,
BOOL  mipmaps = TRUE 
)

Set 2D texture. Adds or replaces a texture.

Parameters:
tex index of the texture to replace, or -1 to add a new one
texfile the name of the texture file to set
mipmaps activates or deactivates mipmaps for the texture

Member Data Documentation

Alphatest. TRUE to activate alpha testing, FALSE otherwise (default).

Alphatestvalue. Threshold used for the alphatest (all pixels with a lower alpha value are clipped away by default).

Ambient. Color used for the ambient lighting.

Blend destination. Blendmode for the destination.

Blending. TRUE to activate blending, FALSE otherwise (default).

Blend source. Blendmode for the source.

Colors. TRUE to use the material parameters for lighting (default), FALSE otherwise. Ignored if lighting is deactivated and only an opengl version of 1 is supported.

Culling. TRUE to activate culling (default), FALSE otherwise.

unsigned int sgMaterial::cullmode

Cullmode. GL_CW for clockwise culling, GL_CCW for counter clockwise culling (default).

Depthtest. TRUE to activate depth testing (default), FALSE otherwise.

Depthtest mode. Default is GL_LEQUAL, to only draw pixels, not covered by others.

Diffuse. Color used for the diffuse lighting.

Emissive. Color used for the emissive lighting.

Lighting. TRUE to activate lighting (default), FALSE otherwise.

Texture matrix. A matrix transforming the texture coordinates of the mesh the material is assigned to.

Material parameters. An array of custom material parameters which will be sent to the shader.

Shader. The shader used for this material.

Shininess. Specular shininess.

Specular. Color used for the specular lighting.

std::vector<unsigned int> sgMaterial::texlocation

Texture location. An array of the location of each texture within the shader.

Textures. The array of the textures used for this material.


The documentation for this class was generated from the following files:
Generated on Thu Jun 3 13:31:04 2010 for iSDGE by  doxygen 1.6.3