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 #ifndef ACG_GLSTATE_HH
00052 #define ACG_GLSTATE_HH
00053
00054
00055
00056
00057
00058 #include "gl.hh"
00059 #include "../Math/GLMatrixT.hh"
00060 #include "../Math/VectorT.hh"
00061 #include "../Config/ACGDefines.hh"
00062 #include "ColorStack.hh"
00063 #include <stack>
00064 #include <vector>
00065
00066 #ifdef WIN32
00067 #pragma warning(push)
00068 #pragma warning(disable:4251)
00069 #endif
00070
00071
00072
00073
00074 namespace ACG {
00075
00076
00077
00078
00079
00090 class ACGDLLEXPORT GLState
00091 {
00092 public:
00093
00095 GLState(bool _updateGL = true);
00096
00098 ~GLState() {}
00099
00100
00101 void makeCurrent() { }
00102
00104 void initialize();
00105
00107 bool updateGL() const { return updateGL_; }
00109 void set_updateGL(bool _b) { updateGL_ = _b; }
00110
00112 unsigned int msSinceLastRedraw () const { return msSinceLastRedraw_; }
00113
00115 void set_msSinceLastRedraw (unsigned int _ms) { msSinceLastRedraw_ = _ms; }
00116
00118 void setState ();
00119
00121 void clearBuffers ();
00122
00123
00124
00125
00127 void reset_projection();
00128
00130 void set_projection(const GLMatrixd& _m) {
00131 GLMatrixd inv_m(_m); inv_m.invert(); set_projection(_m, inv_m);
00132 }
00134 void set_projection(const GLMatrixd& _m, const GLMatrixd& _inv_m);
00135
00137 void ortho( double _left, double _right,
00138 double _bottom, double _top,
00139 double _near_plane, double _far_plane );
00140
00142 void frustum( double _left, double _right,
00143 double _bottom, double _top,
00144 double _near_plane, double _far_plane );
00145
00147 void perspective( double _fovY, double _aspect,
00148 double _near_plane, double _far_plane );
00149
00151 void viewport( int _left, int _bottom, int _width, int _height,
00152 int _glwidth = 0, int _glheight = 0);
00153
00154
00155
00156
00157
00158
00159
00160
00162 void reset_modelview();
00163
00165 void set_modelview(const GLMatrixd& _m) {
00166 GLMatrixd inv_m(_m); inv_m.invert(); set_modelview(_m, inv_m);
00167 }
00169 void set_modelview(const GLMatrixd& _m, const GLMatrixd& _inv_m);
00170
00172 void lookAt( const Vec3d& _eye, const Vec3d& _center, const Vec3d& _up );
00173
00175 void translate( double _x, double _y, double _z,
00176 MultiplyFrom _mult_from = MULT_FROM_RIGHT );
00177
00179 void rotate( double _angle, double _x, double _y, double _z,
00180 MultiplyFrom _mult_from = MULT_FROM_RIGHT );
00181
00183 void scale( double _s )
00184 { scale(_s, _s, _s); }
00185
00187 void scale( double _s,
00188 MultiplyFrom )
00189 { scale(_s, _s, _s); }
00190
00192 void scale( double _sx, double _sy, double _sz,
00193 MultiplyFrom _mult_from = MULT_FROM_RIGHT );
00194
00196 void mult_matrix( const GLMatrixd& _m, const GLMatrixd& _inv_m,
00197 MultiplyFrom _mult_from = MULT_FROM_RIGHT );
00198
00199
00201 void push_projection_matrix();
00203 void pop_projection_matrix();
00204
00206 void push_modelview_matrix();
00208 void pop_modelview_matrix();
00209
00210
00211
00212
00213
00215 const GLMatrixd& projection() const {
00216 return projection_;
00217 }
00218
00220 const GLMatrixd& modelview() const {
00221 return modelview_;
00222 }
00223
00225 const GLMatrixd& viewport() const {
00226 return window2viewport_;
00227 }
00228
00230 const GLMatrixd& forward_projection() const {
00231 return forward_projection_;
00232 }
00233
00235 const GLMatrixd& inverse_projection() const {
00236 return inverse_projection_;
00237 }
00238
00240 const GLMatrixd& inverse_modelview() const {
00241 return inverse_modelview_;
00242 }
00243
00245 void get_viewport( int& _left, int& _bottom,
00246 int& _width, int& _height ) const {
00247 _left = left_; _bottom = bottom_; _width = width_; _height = height_;
00248 }
00249
00251 int viewport_width() const { return width_; }
00253 int viewport_height() const { return height_; }
00254
00256 int context_width() const { return glwidth_; }
00257
00259 int context_height() const { return glheight_; }
00260
00262 double near_plane() const { return near_plane_; }
00263
00265 double far_plane() const { return far_plane_; }
00266
00268 double fovy() const;
00269
00271 double aspect() const;
00272
00274 Vec3d eye() const;
00275
00277 Vec3d viewing_direction() const {
00278 return viewing_direction(width_>>1, height_>>1);
00279 }
00280
00282 Vec3d viewing_direction(int _x, int _y) const;
00283
00285 Vec3d up() const;
00286
00288 Vec3d right() const;
00289
00293 void viewing_ray(int _x, int _y, Vec3d& _origin, Vec3d& _direction) const;
00294
00295
00296
00297
00299 Vec3d project(const Vec3d& _point) const;
00300
00302 Vec3d unproject(const Vec3d& _winPoint) const;
00303
00304
00305
00306
00307
00308
00310 static const Vec4f default_clear_color;
00312 static const Vec4f default_base_color;
00314 static const Vec4f default_ambient_color;
00316 static const Vec4f default_diffuse_color;
00318 static const Vec4f default_specular_color;
00320 static const float default_shininess;
00321
00322
00324 void set_clear_color(const Vec4f& _col);
00326 const Vec4f& clear_color() const { return clear_color_; }
00327
00329 void set_base_color(const Vec4f& _col);
00331 const Vec4f& base_color() const { return base_color_; }
00332
00334 void set_ambient_color(const Vec4f& _col);
00336 const Vec4f& ambient_color() const { return ambient_color_; }
00337
00339 void set_diffuse_color(const Vec4f& _col);
00341 const Vec4f& diffuse_color() const { return diffuse_color_; }
00342
00344 void set_specular_color(const Vec4f& _col);
00346 const Vec4f& specular_color() const { return specular_color_; }
00347
00349 void set_shininess(float _shininess);
00351 float shininess() const { return shininess_; }
00352
00353
00354
00355
00356
00357
00359 void set_point_size(float _f);
00361 float point_size() const { return point_size_; }
00362
00364 void set_line_width(float _f);
00366 float line_width() const { return line_width_; }
00367
00368
00369
00370
00371
00372
00374 void set_blending(bool _b) { blending_ = _b; }
00376 bool blending() { return blending_; }
00377
00379 void set_twosided_lighting(bool _b);
00381 bool twosided_lighting() { return twosided_lighting_; }
00382
00383
00384
00386 void set_multisampling( bool _b );
00387
00389 bool multisampling(){ return multisampling_; };
00390
00392 void allow_multisampling( bool _b ) { allow_multisampling_ = _b; };
00393
00395 bool multisampling_alloowed(){ return allow_multisampling_; };
00396
00397
00398
00407
00408 void pick_init (bool _color);
00409
00413 bool pick_set_maximum (unsigned int _idx);
00414
00416 void pick_set_name (unsigned int _idx);
00417
00421 Vec4uc pick_get_name_color (unsigned int _idx);
00422
00424 void pick_push_name (unsigned int _idx);
00425
00427 void pick_pop_name ();
00428
00431 std::vector<unsigned int> pick_color_to_stack (Vec4uc _rgba) const;
00432
00434 unsigned int pick_free_indicies () const;
00435
00438 bool pick_error () const;
00439
00443 unsigned int pick_current_index () const;
00444
00446 bool color_picking () const;
00447
00448
00449 private:
00450
00451
00452 void update_matrices();
00453
00454
00455
00456 std::stack<GLMatrixd> stack_projection_,
00457 stack_modelview_,
00458 stack_inverse_projection_,
00459 stack_inverse_modelview_;
00460
00461
00462 GLMatrixd projection_,
00463 inverse_projection_,
00464 modelview_,
00465 inverse_modelview_,
00466 window2viewport_,
00467 inverse_window2viewport_,
00468 forward_projection_,
00469 backward_projection_;
00470
00471
00472 int left_, bottom_, width_, height_;
00473
00474
00475 int glwidth_, glheight_;
00476
00477
00478 double near_plane_, far_plane_;
00479
00480
00481 Vec4f clear_color_,
00482 base_color_,
00483 ambient_color_,
00484 diffuse_color_,
00485 specular_color_;
00486
00487 float shininess_;
00488
00489
00490 float point_size_, line_width_;
00491
00492
00493 bool twosided_lighting_;
00494
00495
00496 bool multisampling_;
00497 bool allow_multisampling_;
00498
00499
00500 bool updateGL_;
00501
00502
00503 bool blending_;
00504
00505
00506 unsigned int msSinceLastRedraw_;
00507
00508
00509 ColorStack colorStack_;
00510
00511
00512 bool colorPicking_;
00513
00514 };
00515
00516 #ifdef WIN32
00517 #pragma warning(push)
00518 #endif
00519
00520
00521 }
00522
00523 #endif // ACG_GLSTATE_HH defined
00524