GlMaterial.hpp

Go to the documentation of this file.
00001 /* COPYRIGHT
00002  *
00003  * This file is part of the Simple Object Loader and Renderer - SOLAR
00004  *
00005  * Read the file "SOLAR-LICENSE" for the license.
00006  *
00007  * Authors & Copyright:
00008  *
00009  * Tommi Ilmonen, 2001-2003, except LWO-code by RJ, 2001-2003
00010  *
00011  * Tommi's email: firstname.lastname@hut.fi
00012  *
00013  */
00014 
00015 #ifndef SOLAR_GL_MATERIAL_HPP
00016 #define SOLAR_GL_MATERIAL_HPP
00017 
00018 #include <GL/gl.h>
00019 
00020 #include <Solar/Color.hpp>
00021 
00022 #include <map>
00023 #include <string>
00024 
00025 namespace Solar {
00026 
00027   class GlRenderer;
00028 
00031   class GlMaterial
00032   {
00033   public:
00034 
00035     enum {
00037       BLEND = 0x1,
00039       LIGHTING = 0x2,
00041       SMOOTH = 0x4,
00043       TWO_SIDED = 0x8,
00045       WITH_MESH = 0x10
00046     };
00047 
00048     GlMaterial(float shine, 
00049          const Rgba & color,
00050          GLuint textureId = (GLuint) -1,
00051          int flags = LIGHTING | SMOOTH);
00052     GlMaterial();
00053 
00054     virtual ~GlMaterial();
00055 
00056     void set(float shine, const Rgba & color, GLuint textureId = (GLuint) -1)
00057     { m_textureId = textureId; m_shine = shine;  setColor(color); }
00058 
00059     void setShine(float s) { m_shine = s; }
00060     int  flags() const   { return m_flags; }
00061     void setFlags(int f) { m_flags = f; }
00062     void setTextureId(GLuint i) { m_textureId = i; }
00063 
00065     void setColor(const Rgba & c) { m_ambient = m_diffuse = m_specular = c; }
00066     void setAmbient(const Rgba & color)  { m_ambient = color; }
00067     void setDiffuse(const Rgba & color)  { m_diffuse = color; }
00068     void setSpecular(const Rgba & color) { m_specular = color; }
00069 
00070     void applyGl(GlRenderer *) const;
00071 
00072     GLuint   textureId()    const { return m_textureId; }
00073 
00074     const Rgba & ambient()  const { return m_ambient; }
00075     const Rgba & diffuse()  const { return m_diffuse; }
00076     const Rgba & specular() const { return m_specular; }
00077 
00078     float uvScale() const { return m_uvScale; }
00079     void  setUvScale(float uvScale) { m_uvScale = uvScale; }
00080   protected:
00081 
00082     GLuint   m_textureId;
00083     float    m_shine;
00084     Rgba     m_ambient, m_diffuse, m_specular;
00085     float    m_uvScale;
00086 
00087     int      m_flags;
00088   };
00089 
00092 
00095   class GlMaterialBank
00096   {
00097   public:
00098     GlMaterialBank();
00099     virtual ~GlMaterialBank();
00100 
00101     void addMaterial(const std::string &, const GlMaterial &);
00102 
00103     const GlMaterial & getMaterial(const std::string &);
00104   
00105     void addUsualColors();
00106 
00107     void forceMaterial(const std::string & mat) { m_forceMaterial = mat; }
00108     void unforceMaterial() { m_forceMaterial.clear(); }
00109 
00110   protected:
00111 
00112     static GlMaterial m_default;
00113 
00114     std::map<std::string, GlMaterial> m_materials;
00115 
00116     std::string m_forceMaterial;
00117   };
00118 
00119 } // namespace Solar
00120 
00121 #endif

Generated on Mon Mar 12 21:09:00 2007 for VEE - The Visual Effects Engine by  doxygen 1.4.6