MaterialNode.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 8548 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2010-02-12 14:40:13 +0100 (Fr, 12. Feb 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS MaterialNode
00049 //
00050 //=============================================================================
00051 
00052 #ifndef ACG_MATERIAL_NODE_HH
00053 #define ACG_MATERIAL_NODE_HH
00054 
00055 
00056 //== INCLUDES =================================================================
00057 
00058 #include "BaseNode.hh"
00059 #include <string>
00060 
00061 //== NAMESPACES ===============================================================
00062 
00063 namespace ACG {
00064 namespace SceneGraph {
00065 
00066 
00067 //== CLASS DEFINITION =========================================================
00068 
00069 
00078 class ACGDLLEXPORT MaterialNode : public BaseNode
00079 {
00080 public:
00081 
00083   enum ApplyProperties
00084   {
00086     None=0,
00088     All=0xffff,
00090     BaseColor=1,
00092     Material=2,
00094     PointSize=4,
00096     LineWidth=8,
00098     RoundPoints=16,
00100     LineSmooth=32,
00102     AlphaTest=64,
00104     Blending=128,
00106     BackFaceCulling=256,
00108     ColorMaterial=512,
00110     MultiSampling=1024
00111   };
00112 
00113 
00114 
00116   MaterialNode( BaseNode*           _parent = 0,
00117                           const std::string&  _name = "<MaterialNode>",
00118                           unsigned int        _applyProperties = (All & ~BackFaceCulling));
00119 
00121   virtual ~MaterialNode() {};
00122 
00124   void read( std::istream & _is);
00125 
00126   //===========================================================================
00129   //===========================================================================
00130 
00131     ACG_CLASSNAME(MaterialNode);
00132 
00134     void enter(GLState& _state, DrawModes::DrawMode _drawmode);
00136     void leave(GLState& _state, DrawModes::DrawMode _drawmode);
00137 
00138 
00140     void enterPick(GLState& _state, PickTarget _target, DrawModes::DrawMode _drawMode );
00141 
00143     void leavePick(GLState& _state, PickTarget _target, DrawModes::DrawMode _drawMode );
00144 
00147   //===========================================================================
00150   //===========================================================================
00151 
00153     void set_color(const Vec4f& _c) {
00154       Vec4f c;
00155       set_base_color(_c);
00156       c = _c * 0.2f;  c[3]=_c[3];  set_ambient_color(c);
00157       c = _c * 0.6f;  c[3]=_c[3];  set_diffuse_color(c);
00158       c = _c * 0.8f;  c[3]=_c[3];  set_specular_color(c);
00159     }
00160 
00162     void set_base_color(const Vec4f& _c) { base_color_ = _c;}
00164     const Vec4f& base_color() const { return base_color_; }
00165 
00167     void set_ambient_color(const Vec4f& _a) { ambient_color_ = _a; }
00169     const Vec4f& ambient_color() const { return ambient_color_; }
00170 
00172     void set_diffuse_color(const Vec4f& _d) { diffuse_color_ = _d; }
00174     const Vec4f& diffuse_color() const { return diffuse_color_; }
00175 
00177     void set_specular_color(const Vec4f& _s) { specular_color_ = _s; }
00179     const Vec4f& specular_color() const { return specular_color_; }
00180 
00182     void colorMaterial( const bool _colorMaterial) { color_material_ = _colorMaterial; }
00184     void enable_color_material() { color_material_ = true; }
00186     void disable_color_material() { color_material_ = false; }
00188     bool colorMaterial() { return color_material_; }
00189 
00191     void set_shininess(float _s) { shininess_ = _s; }
00193     float shininess() const { return shininess_; }
00194 
00197   //===========================================================================
00200   //===========================================================================
00202     void set_point_size(float _sz) { point_size_ = _sz; }
00204     float point_size() const { return point_size_; }
00205 
00207     void set_line_width(float _sz) { line_width_ = _sz; }
00209     float line_width() const { return line_width_; }
00210 
00212     void set_round_points(bool _b) { round_points_ = _b; }
00214     bool round_points() const { return round_points_; }
00215 
00217     void set_line_smooth(bool _b) { lines_smooth_ = _b; }
00219     bool line_smooth() const { return lines_smooth_; }
00220 
00223   //===========================================================================
00226   //===========================================================================
00227 
00229     void enable_alpha_test(float _clip) {
00230       alpha_test_ = true; alpha_clip_ = _clip;
00231     }
00232 
00234     void disable_alpha_test() { alpha_test_ = false; }
00235 
00237     bool alpha_test() { return alpha_test_; };
00238 
00241   //===========================================================================
00244   //===========================================================================
00245 
00247     void enable_multisampling() {
00248       multiSampling_ = true;
00249     }
00250 
00252     void disable_multisampling() {
00253       multiSampling_ = false;
00254     }
00255 
00257     bool multiSampling() {
00258       return multiSampling_;
00259     }
00260 
00262     void set_multisampling( bool _state ) {
00263       multiSampling_ = _state;
00264     }
00265 
00273 
00274   float alpha_value(){ return alpha_clip_; };
00275 
00276   bool blending() { return blending_; };
00277 
00278   GLenum blending_param1() { return blend_param1_; };
00279   GLenum blending_param2() { return blend_param2_; };
00280 
00282   void enable_blending(GLenum _p1 = GL_SRC_ALPHA,
00283                        GLenum _p2 = GL_ONE_MINUS_SRC_ALPHA)
00284   { blending_ = true; blend_param1_ = _p1; blend_param2_ = _p2; }
00286   void disable_blending() { blending_ = false; }
00287 
00288   bool backface_culling() { return backface_culling_; };
00289 
00291   void enable_backface_culling() { backface_culling_ = true; }
00293   void disable_backface_culling() { backface_culling_ = false; }
00294 
00295 
00296 
00298   unsigned int applyProperties() const { return applyProperties_; }
00299 
00301   void applyProperties(unsigned int _applyProperties) {
00302     applyProperties_ = _applyProperties;
00303   }
00304 
00305 private:
00306 
00308   int applyProperties_;
00309 
00310   Vec4f    base_color_,      base_color_backup_;
00311   Vec4f    ambient_color_,   ambient_color_backup_;
00312   Vec4f    diffuse_color_,   diffuse_color_backup_;
00313   Vec4f    specular_color_,  specular_color_backup_;
00314 
00315   float    shininess_,       shininess_backup_;
00316   float    point_size_,      point_size_backup_;
00317   float    line_width_,      line_width_backup_;
00318 
00319   bool     round_points_,    round_points_backup_;
00320   bool     lines_smooth_,    lines_smooth_backup_;
00321 
00322   bool     alpha_test_,      alpha_test_backup_;
00323   float    alpha_clip_,      alpha_clip_backup_;
00324 
00325   bool     blending_,        blending_backup_;
00326   GLenum   blend_param1_,    blend_param1_backup_;
00327   GLenum   blend_param2_,    blend_param2_backup_;
00328 
00329   bool     color_material_,  color_material_backup_;
00330   bool     backface_culling_,backface_culling_backup_;
00331 
00332   bool     multiSampling_,   multiSampling_backup_;
00333 };
00334 
00335 
00336 //=============================================================================
00337 } // namespace SceneGraph
00338 } // namespace ACG
00339 //=============================================================================
00340 #endif // ACG_MATERIAL_NODE_HH defined
00341 //=============================================================================
00342 

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .