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

Material.h

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id: Material.h,v 1.5 2002/01/17 18:57:37 tksuoran Exp $
00022 */
00023 
00024 
00025 #ifndef TEDDY__MATERIALS__MATERIAL__H
00026 #define TEDDY__MATERIALS__MATERIAL__H
00027 
00028 
00029 #include "Teddy/Graphics/Color.h"
00030 #include "Teddy/Graphics/View.h"
00031 #include "Teddy/MixIn/Named.h"
00032 #include "Teddy/MixIn/Options.h"
00033 #include "SDL_types.h"
00034 
00035 
00036 //  Forward declarations
00037 namespace Teddy {
00038     namespace Graphics { class Texture; };
00039 };
00040 using namespace Teddy::Graphics;
00041 using namespace Teddy::MixIn;
00042 
00043 
00044 namespace Teddy     {
00045 namespace Materials {
00046 
00047 
00057 class Material : public Named, public Options {
00058 public:
00059     static const unsigned long RENDER_MODE_POINT                   ;
00060     static const unsigned long RENDER_MODE_LINE                    ;
00061     static const unsigned long RENDER_MODE_FILL                    ;
00062     static const unsigned long RENDER_MODE_FILL_OUTLINE            ;
00063 
00064     static const unsigned long RENDER_LIGHTING_COLOR               ;
00065     static const unsigned long RENDER_LIGHTING_CUSTOM              ;
00066     static const unsigned long RENDER_LIGHTING_PRIMARY_LIGHT_ONLY  ;
00067     static const unsigned long RENDER_LIGHTING_SIMPLE              ;
00068     static const unsigned long RENDER_LIGHTING_FULL                ;
00069 
00070     static const unsigned long RENDER_OPTION_RESERVED              ;
00071     static const unsigned long RENDER_OPTION_SMOOTH                ;
00072     static const unsigned long RENDER_OPTION_CULL_FACE             ;
00073     static const unsigned long RENDER_OPTION_BLEND                 ;
00074     static const unsigned long RENDER_OPTION_FOG                   ;
00075     static const unsigned long RENDER_OPTION_NORMALIZE             ;
00076     static const unsigned long RENDER_OPTION_ALPHA_TEST            ;
00077     static const unsigned long RENDER_OPTION_DEPTH_TEST            ;
00078     static const unsigned long RENDER_OPTION_STENCIL_TEST          ;
00079     static const unsigned long RENDER_OPTION_SCISSOR_TEST          ;
00080     static const unsigned long RENDER_OPTION_TEXTURE_1D            ;
00081     static const unsigned long RENDER_OPTION_TEXTURE_2D            ;
00082     static const unsigned long RENDER_OPTION_TEXTURE_3D            ;
00083     static const unsigned long RENDER_OPTION_POINT_SMOOTH          ;
00084     static const unsigned long RENDER_OPTION_LINE_SMOOTH           ;
00085     static const unsigned long RENDER_OPTION_POLYGON_SMOOTH        ;
00086     static const unsigned long RENDER_OPTION_AMBIENT               ;
00087     static const unsigned long RENDER_OPTION_DIFFUSE               ;
00088     static const unsigned long RENDER_OPTION_SPECULAR              ;
00089     static const unsigned long RENDER_OPTION_EMISSION              ;
00090     static const unsigned long RENDER_OPTION_SHINYNESS             ;
00091     static const unsigned long RENDER_OPTION_BORDER                ;
00092     static const unsigned long RENDER_OPTION_REMOVE_HIDDEN         ;
00093     static const unsigned long RENDER_OPTION_FRUSTUM_CULL          ;
00094     static const unsigned long RENDER_OPTION_SORT_OBJECTS          ;
00095     static const unsigned long RENDER_OPTION_SORT_ELEMENTS         ;
00096     static const unsigned long RENDER_OPTION_COLOR_MATERIAL        ;
00097     static const unsigned long RENDER_OPTION_MASTER_LIGHTING_ONLY  ;
00098 
00099     static const unsigned long RENDER_OPTION_RESERVED_M            ;
00100     static const unsigned long RENDER_OPTION_SMOOTH_M              ;
00101     static const unsigned long RENDER_OPTION_CULL_FACE_M           ;
00102     static const unsigned long RENDER_OPTION_BLEND_M               ;
00103     static const unsigned long RENDER_OPTION_FOG_M                 ;
00104     static const unsigned long RENDER_OPTION_NORMALIZE_M           ;
00105     static const unsigned long RENDER_OPTION_ALPHA_TEST_M          ;
00106     static const unsigned long RENDER_OPTION_DEPTH_TEST_M          ;
00107     static const unsigned long RENDER_OPTION_STENCIL_TEST_M        ;
00108     static const unsigned long RENDER_OPTION_SCISSOR_TEST_M        ;
00109     static const unsigned long RENDER_OPTION_TEXTURE_1D_M          ;
00110     static const unsigned long RENDER_OPTION_TEXTURE_2D_M          ;
00111     static const unsigned long RENDER_OPTION_TEXTURE_3D_M          ;
00112     static const unsigned long RENDER_OPTION_POINT_SMOOTH_M        ;
00113     static const unsigned long RENDER_OPTION_LINE_SMOOTH_M         ;
00114     static const unsigned long RENDER_OPTION_POLYGON_SMOOTH_M      ;
00115     static const unsigned long RENDER_OPTION_AMBIENT_M             ;
00116     static const unsigned long RENDER_OPTION_DIFFUSE_M             ;
00117     static const unsigned long RENDER_OPTION_SPECULAR_M            ;
00118     static const unsigned long RENDER_OPTION_EMISSION_M            ;
00119     static const unsigned long RENDER_OPTION_SHINYNESS_M           ;
00120     static const unsigned long RENDER_OPTION_BORDER_M              ;
00121     static const unsigned long RENDER_OPTION_REMOVE_HIDDEN_M       ;
00122     static const unsigned long RENDER_OPTION_FRUSTUM_CULL_M        ;
00123     static const unsigned long RENDER_OPTION_SORT_OBJECTS_M        ;
00124     static const unsigned long RENDER_OPTION_SORT_ELEMENTS_M       ;
00125     static const unsigned long RENDER_OPTION_COLOR_MATERIAL_M      ;
00126     static const unsigned long RENDER_OPTION_MASTER_LIGHTING_ONLY_M;
00127     
00128     static const unsigned long RENDER_MODE_DEFAULT    ;
00129     static const unsigned long RENDER_LIGHTING_DEFAULT;
00130     static const unsigned long RENDER_OPTION_DEFAULT_M;
00131     static const unsigned long RENDER_OPTION_ALL_M    ;
00132 
00133     static char *render_option_to_str( int a );
00134     static void  init                ();
00135     static int   getFeature          ( int a );
00136 
00137 private:
00138     static int   mode_to_feature[32];
00139 
00140 public:
00141     Material( const Material &material );
00142     Material( const Material &material, Uint8 lighting );
00143     Material( const std::string &name );
00144     Material( const std::string &name, Uint8 mode, Uint8 lighting, unsigned long options );
00145     Material( const std::string &name, Color color );
00146     Material( Color color );
00147     Material( const std::string &name, const unsigned long options );
00148     virtual ~Material();
00149 
00150     void             copy( const Material &from );
00151     
00152     void             applyAmbient        ( Uint8 lighting );
00153     void             applyDiffuse        ( Uint8 lighting );
00154     void             applySpecular       ( Uint8 lighting );
00155     void             applyEmission       ( Uint8 lighting );
00156     void             applyShinyness      ( Uint8 lighting );
00157     void             applyBorder         ( Uint8 lighting );
00158 
00159     virtual void     setMode             ( Uint8  mode );
00160     virtual Uint8    getMode             () const;
00161     virtual void     setLighting         ( Uint8  lighting );
00162     virtual Uint8    getLighting         () const;
00163 
00164     virtual void     setEmission         ( const Color &e );
00165     virtual Color    getEmission         () const;
00166     virtual void     setAmbient          ( const Color &a );
00167     virtual Color    getAmbient          () const;
00168     virtual void     setDiffuse          ( const Color &d );
00169     virtual Color    getDiffuse          () const;
00170     virtual void     setSpecular         ( const Color &s );
00171     virtual Color    getSpecular         () const;
00172     virtual void     setShininess        ( float s );
00173     virtual float    getShininess        () const;
00174     virtual void     setBorder           ( const Color &s );
00175     virtual Color    getBorder           () const;
00176     virtual void     setPolygonOffset    ( const int offset );
00177     virtual int      getPolygonOffset    () const;
00178     virtual void     setMaxSmoothingAngle( const float angle );
00179     virtual float    getMaxSmoothingAngle() const;
00180     virtual Texture *getTexture          ();
00181     virtual void     setTexture          ( Texture *t, bool enable=false );
00182 
00183 protected:
00184     Texture *texture;   
00185     Uint8    render_mode;
00186     Uint8    render_lighting;
00187     float    shininess;
00188     Color    ambient;
00189     Color    diffuse;
00190     Color    specular;
00191     Color    emission;
00192     Color    border;
00193     int      polygon_offset;
00194     float    max_smoothing_angle;
00195 
00196 public:
00197     static Material BLACK;
00198     static Material GRAY_25;
00199     static Material GRAY_50;
00200     static Material GRAY_75;
00201     static Material WHITE;
00202     static Material RED;
00203     static Material YELLOW;
00204     static Material ORANGE;
00205     static Material GREEN;
00206     static Material CYAN;
00207     static Material BLUE;
00208     static Material MAGENTA;
00209     static Material DARK_ORANGE;
00210     static Material DARK_RED;
00211     static Material DARK_YELLOW;
00212     static Material DARK_GREEN;
00213     static Material DARK_CYAN;
00214     static Material DARK_BLUE;
00215     static Material DARK_MAGENTA;
00216     static Material LIGHT_ORANGE;
00217     static Material LIGHT_RED;
00218     static Material LIGHT_YELLOW;
00219     static Material LIGHT_GREEN;
00220     static Material LIGHT_CYAN;
00221     static Material LIGHT_BLUE;
00222     static Material LIGHT_MAGENTA;
00223 };
00224 
00225 
00226 };  //  namespace Materials
00227 };  //  namespace Teddy
00228 
00229 
00230 #endif  //  TEDDY__MATERIALS__MATERIAL_H
00231