Material2Node.hh
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef ACG_MATERIAL2NODE_HH
00053 #define ACG_MATERIAL2NODE_HH
00054
00055
00056
00057 #include "BaseNode.hh"
00058 #include <string>
00059
00060
00061
00062 namespace ACG {
00063 namespace SceneGraph {
00064
00065
00066
00067
00068 class ACGDLLEXPORT Material2Node : public BaseNode
00069 {
00070 public:
00071
00073 enum ApplyProperties
00074 {
00076 None=0,
00078 All=0xffff,
00080 BaseColor=1,
00082 Material=2,
00084 PointSize=4,
00086 LineWidth=8,
00088 RoundPoints=16,
00090 AlphaTest=32,
00092 Blending=64,
00094 BackFaceCulling=128
00095 };
00096
00097
00098 enum Side
00099 {
00100 FrontSide = 0,
00101 BackSide = 1
00102 };
00103
00105 Material2Node( BaseNode* _parent = 0,
00106 const std::string& _name = "<Material2Node>",
00107 unsigned int _applyProperties = (All &
00108 ~BackFaceCulling));
00109
00111 virtual ~Material2Node() {};
00112
00113
00114 ACG_CLASSNAME(Material2Node);
00115
00117 void read( std::istream & _is);
00118
00119
00121 void enter(GLState& _state, DrawModes::DrawMode _drawmode);
00123 void leave(GLState& _state, DrawModes::DrawMode _drawmode);
00124
00125
00127 unsigned int applyProperties() const { return applyProperties_; }
00129 void applyProperties(unsigned int _applyProperties) {
00130 applyProperties_ = _applyProperties;
00131 }
00132
00133
00135 void set_color( const Vec4f & _c,
00136 Side _side = FrontSide )
00137 {
00138 Vec4f c;
00139 set_base_color( _c, _side );
00140 c = _c * 0.2f; c[3]=_c[3]; set_ambient_color( c, _side );
00141 c = _c * 0.6f; c[3]=_c[3]; set_diffuse_color( c, _side );
00142 c = _c * 0.8f; c[3]=_c[3]; set_specular_color( c, _side );
00143 }
00144
00146 void set_base_color( const Vec4f & _c,
00147 Side _side = FrontSide )
00148 {
00149 base_color_[ _side ] = _c;
00150 }
00151
00153 const Vec4f& base_color( Side _side = FrontSide ) const
00154 {
00155 return base_color_[ _side ];
00156 }
00157
00159 void set_ambient_color( const Vec4f& _a,
00160 Side _side = FrontSide )
00161 {
00162 ambient_color_[ _side ] = _a;
00163 }
00164
00166 const Vec4f& ambient_color( Side _side = FrontSide ) const
00167 {
00168 return ambient_color_[ _side ];
00169 }
00170
00172 void set_diffuse_color( const Vec4f& _d,
00173 Side _side = FrontSide )
00174 {
00175 diffuse_color_[ _side ] = _d;
00176 }
00177
00179 const Vec4f& diffuse_color( Side _side = FrontSide ) const
00180 {
00181 return diffuse_color_[ _side ];
00182 }
00183
00185 void set_specular_color( const Vec4f& _s,
00186 Side _side = FrontSide )
00187 {
00188 specular_color_[ _side ] = _s;
00189 }
00190
00192 const Vec4f& specular_color( Side _side = FrontSide ) const
00193 {
00194 return specular_color_[ _side ];
00195 }
00196
00198 void set_shininess(float _s) { shininess_ = _s; }
00200 float shininess() const { return shininess_; }
00201
00202
00204 void set_point_size(float _sz) { point_size_ = _sz; }
00206 float point_size() const { return point_size_; }
00207
00209 void set_line_width(float _sz) { line_width_ = _sz; }
00211 float line_width() const { return line_width_; }
00212
00214 void set_round_points(bool _b) { round_points_ = _b; }
00216 bool round_points() const { return round_points_; }
00217
00219 void enable_alpha_test(float _clip) {
00220 alpha_test_ = true; alpha_clip_ = _clip;
00221 }
00223 void disable_alpha_test() { alpha_test_ = false; }
00224
00226 void enable_blending(GLenum _p1 = GL_SRC_ALPHA,
00227 GLenum _p2 = GL_ONE_MINUS_SRC_ALPHA)
00228 { blending_ = true; blend_param1_ = _p1; blend_param2_ = _p2; }
00230 void disable_blending() { blending_ = false; }
00231
00233 void enable_backface_culling() { backface_culling_ = true; }
00235 void disable_backface_culling() { backface_culling_ = false; }
00236
00238 void set_twosided( bool _twosided ) { twosided_ = _twosided; }
00239
00240 private:
00241
00243 int applyProperties_;
00244
00245 Vec4f base_color_[2], base_color_backup_[2];
00246 Vec4f ambient_color_[2], ambient_color_backup_[2];
00247 Vec4f diffuse_color_[2], diffuse_color_backup_[2];
00248 Vec4f specular_color_[2], specular_color_backup_[2];
00249
00250 float shininess_, shininess_backup_;
00251 float point_size_, point_size_backup_;
00252 float line_width_, line_width_backup_;
00253
00254 bool round_points_, round_points_backup_;
00255
00256 bool alpha_test_, alpha_test_backup_;
00257 float alpha_clip_, alpha_clip_backup_;
00258
00259 bool blending_, blending_backup_;
00260 GLenum blend_param1_, blend_param1_backup_;
00261 GLenum blend_param2_, blend_param2_backup_;
00262
00263 bool backface_culling_, backface_culling_backup_;
00264
00265 bool twosided_;
00266 };
00267
00268
00269
00270 }
00271 }
00272
00273 #endif // ACG_MATERIAL2NODE_HH defined
00274
00275