Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/tools/sg/gl2ps_action

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/sg/gl2ps_action (Version 11.3.0) and /externals/g4tools/include/tools/sg/gl2ps_action (Version 11.0.p1)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_sg_gl2ps_action                       4 #ifndef tools_sg_gl2ps_action
  5 #define tools_sg_gl2ps_action                       5 #define tools_sg_gl2ps_action
  6                                                     6 
  7 #include "gl2ps_manager"                            7 #include "gl2ps_manager"
  8 #include "../gl2ps"                                 8 #include "../gl2ps"
  9                                                     9 
 10 #include "render_action"                           10 #include "render_action"
 11 #include "primitive_visitor"                       11 #include "primitive_visitor"
 12 #include "../colorfs"                              12 #include "../colorfs"
 13 #include "../lina/plane"                       << 
 14                                                    13 
 15 #include <cstdio> //FILE                           14 #include <cstdio> //FILE
 16                                                    15 
 17 namespace tools {                                  16 namespace tools {
 18 namespace sg {                                     17 namespace sg {
 19                                                    18 
 20 class gl2ps_action : public render_action {        19 class gl2ps_action : public render_action {
 21   TOOLS_ACTION(gl2ps_action,tools::sg::gl2ps_a     20   TOOLS_ACTION(gl2ps_action,tools::sg::gl2ps_action,render_action)
 22 private:                                           21 private:
 23   gl2ps_action& get_me() {return *this;}           22   gl2ps_action& get_me() {return *this;}
 24                                                    23 
 25   static unsigned int _GL2PS_POINT()    {retur     24   static unsigned int _GL2PS_POINT()    {return 2;}
 26   static unsigned int _GL2PS_LINE()     {retur     25   static unsigned int _GL2PS_LINE()     {return 3;}
 27   static unsigned int _GL2PS_TRIANGLE() {retur     26   static unsigned int _GL2PS_TRIANGLE() {return 5;}
 28 public:                                            27 public:
 29   virtual void draw_vertex_array(gl::mode_t a_     28   virtual void draw_vertex_array(gl::mode_t a_mode,
 30                                  size_t a_floa     29                                  size_t a_floatn,
 31                                  const float*      30                                  const float* a_xyzs){
 32     m_pv.add_primitive(a_mode,a_floatn,a_xyzs)     31     m_pv.add_primitive(a_mode,a_floatn,a_xyzs);
 33   }                                                32   }
 34                                                    33 
 35   virtual void draw_vertex_array_xy(gl::mode_t     34   virtual void draw_vertex_array_xy(gl::mode_t a_mode,
 36                                     size_t a_f     35                                     size_t a_floatn,
 37                                     const floa     36                                     const float* a_xys){
 38     m_pv.add_primitive_xy(a_mode,a_floatn,a_xy     37     m_pv.add_primitive_xy(a_mode,a_floatn,a_xys);
 39   }                                                38   }
 40                                                    39 
 41   virtual void draw_vertex_color_array(gl::mod     40   virtual void draw_vertex_color_array(gl::mode_t a_mode,
 42                                        size_t      41                                        size_t a_floatn,
 43                                        const f     42                                        const float* a_xyzs,
 44                                        const f     43                                        const float* a_rgbas){
 45     m_pv.add_primitive_rgba(a_mode,a_floatn,a_     44     m_pv.add_primitive_rgba(a_mode,a_floatn,a_xyzs,a_rgbas);
 46   }                                                45   }
 47                                                    46 
 48   virtual void draw_vertex_normal_array(gl::mo     47   virtual void draw_vertex_normal_array(gl::mode_t a_mode,
 49                                         size_t     48                                         size_t a_floatn,
 50                                         const      49                                         const float* a_xyzs,
 51                                         const      50                                         const float* a_nms){
 52     m_pv.add_primitive_normal(a_mode,a_floatn,     51     m_pv.add_primitive_normal(a_mode,a_floatn,a_xyzs,a_nms);
 53   }                                                52   }
 54                                                    53 
 55   virtual void draw_vertex_color_normal_array(     54   virtual void draw_vertex_color_normal_array(gl::mode_t a_mode,
 56                                                    55                                               size_t a_floatn,
 57                                                    56                                               const float* a_xyzs,
 58                                                    57                                               const float* a_rgbas,
 59                                                    58                                               const float* a_nms){
 60     // We expect a_nms of size : 3*(a_floatn/3     59     // We expect a_nms of size : 3*(a_floatn/3)
 61     // (then one normal per 3D point).             60     // (then one normal per 3D point).
 62     m_pv.add_primitive_normal_rgba(a_mode,a_fl     61     m_pv.add_primitive_normal_rgba(a_mode,a_floatn,a_xyzs,a_nms,a_rgbas);
 63   }                                                62   }
 64                                                    63 
 65   virtual void clear_color(float a_r,float a_g     64   virtual void clear_color(float a_r,float a_g,float a_b,float /*a_a*/){
 66     //a_a ?                                        65     //a_a ?
 67     set_background(a_r,a_g,a_b);                   66     set_background(a_r,a_g,a_b);
 68   }                                                67   }
 69   virtual void color4f(float a_r,float a_g,flo     68   virtual void color4f(float a_r,float a_g,float a_b,float a_a){
 70     m_color.set_value(a_r,a_g,a_b,a_a);            69     m_color.set_value(a_r,a_g,a_b,a_a);
 71   }                                                70   }
 72   virtual void line_width(float a_v){m_line_wi     71   virtual void line_width(float a_v){m_line_width = a_v;}
 73   virtual void point_size(float a_v) {m_point_     72   virtual void point_size(float a_v) {m_point_size = a_v;}
 74   virtual void set_polygon_offset(bool a_v) {m     73   virtual void set_polygon_offset(bool a_v) {m_POLYGON_OFFSET_FILL = a_v;}
 75   virtual void normal(float a_x,float a_y,floa     74   virtual void normal(float a_x,float a_y,float a_z) {
 76     m_normal.set_value(a_x,a_y,a_z);               75     m_normal.set_value(a_x,a_y,a_z);
 77   }                                                76   }
 78                                                    77 
 79   virtual void set_winding(winding_type a_v) {     78   virtual void set_winding(winding_type a_v) {
 80     m_ccw = (a_v==winding_ccw?true:false);         79     m_ccw = (a_v==winding_ccw?true:false);
 81   }                                                80   }
 82                                                    81 
 83   virtual void set_shade_model(shade_type a_v)     82   virtual void set_shade_model(shade_type a_v) {
 84     if(a_v==shade_smooth) {}                       83     if(a_v==shade_smooth) {}
 85     else {}                                        84     else {}
 86   }                                                85   }
 87                                                    86 
 88   virtual void set_depth_test(bool a_on) {m_DE     87   virtual void set_depth_test(bool a_on) {m_DEPTH_TEST = a_on;}
 89                                                    88 
 90   virtual void set_cull_face(bool a_on) {m_CUL     89   virtual void set_cull_face(bool a_on) {m_CULL_FACE = a_on;}
 91   virtual void set_point_smooth(bool a_on) {m_     90   virtual void set_point_smooth(bool a_on) {m_POINT_SMOOTH = a_on;}
 92   virtual void set_line_smooth(bool a_on) {m_L     91   virtual void set_line_smooth(bool a_on) {m_LINE_SMOOTH = a_on;}
 93                                                    92 
 94   virtual void load_proj_matrix(const mat4f& a     93   virtual void load_proj_matrix(const mat4f& a_mtx) {m_proj = a_mtx;}
 95   virtual void load_model_matrix(const mat4f&      94   virtual void load_model_matrix(const mat4f& a_mtx) {
 96     m_model = a_mtx;                               95     m_model = a_mtx;
 97     set_normal_matrix();                           96     set_normal_matrix();
 98   }                                                97   }
 99                                                    98 
100   virtual unsigned int max_lights() {return 10     99   virtual unsigned int max_lights() {return 1000;}
101                                                   100 
102   virtual void enable_light(unsigned int,         101   virtual void enable_light(unsigned int,
103                             float a_dx,float a    102                             float a_dx,float a_dy,float a_dz,
104                             float a_r,float a_ << 103                             float a_r,float a_g,float a_b,float a_a){
105                             float a_ar,float a << 
106     m_light_color.set_value(a_r,a_g,a_b,a_a);     104     m_light_color.set_value(a_r,a_g,a_b,a_a);
107     m_light_ambient.set_value(a_ar,a_ag,a_ab,a << 
108     m_light_direction.set_value(a_dx,a_dy,a_dz    105     m_light_direction.set_value(a_dx,a_dy,a_dz);
109     m_light_direction.normalize();             << 
110     m_light_on = true;                            106     m_light_on = true;
111   }                                               107   }
112                                                   108 
113   virtual void set_lighting(bool a_on) {m_ligh    109   virtual void set_lighting(bool a_on) {m_light_on = a_on;}
114   virtual void set_blend(bool) {}                 110   virtual void set_blend(bool) {}
115                                                   111 
116   virtual void restore_state(unsigned int /*a_    112   virtual void restore_state(unsigned int /*a_ret_num_light*/) {
117     const sg::state& _state = state();            113     const sg::state& _state = state();
118     m_proj = _state.m_proj;                       114     m_proj = _state.m_proj;
119     m_model = _state.m_model;                     115     m_model = _state.m_model;
120     set_normal_matrix();                          116     set_normal_matrix();
121                                                   117 
122     m_color = _state.m_color;                     118     m_color = _state.m_color;
123     m_normal = _state.m_normal;                << 
124                                                << 
125     m_ccw = (_state.m_winding==winding_ccw?tru    119     m_ccw = (_state.m_winding==winding_ccw?true:false);
126     m_POLYGON_OFFSET_FILL = _state.m_GL_POLYGO    120     m_POLYGON_OFFSET_FILL = _state.m_GL_POLYGON_OFFSET_FILL;
127     m_CULL_FACE = _state.m_GL_CULL_FACE;          121     m_CULL_FACE = _state.m_GL_CULL_FACE;
128     m_POINT_SMOOTH = _state.m_GL_POINT_SMOOTH;    122     m_POINT_SMOOTH = _state.m_GL_POINT_SMOOTH;
129     m_LINE_SMOOTH = _state.m_GL_LINE_SMOOTH;      123     m_LINE_SMOOTH = _state.m_GL_LINE_SMOOTH;
130     m_point_size = _state.m_point_size;           124     m_point_size = _state.m_point_size;
131     m_line_width = _state.m_line_width;           125     m_line_width = _state.m_line_width;
132     m_light_on = _state.m_GL_LIGHTING;            126     m_light_on = _state.m_GL_LIGHTING;
133     m_DEPTH_TEST = _state.m_GL_DEPTH_TEST;        127     m_DEPTH_TEST = _state.m_GL_DEPTH_TEST;
134   }                                               128   }
135                                                   129 
136   ////////////////////////////////////////////    130   /////////////////////////////////////////////////////////////////
137   /// texture ////////////////////////////////    131   /// texture /////////////////////////////////////////////////////
138   ////////////////////////////////////////////    132   /////////////////////////////////////////////////////////////////
139   virtual void draw_vertex_array_texture(gl::m    133   virtual void draw_vertex_array_texture(gl::mode_t,size_t a_xyzn,const float* a_xyzs,
140                                          gstoi    134                                          gstoid a_id,const float* a_tcs) {
141     img_byte img;                                 135     img_byte img;
142     if(!m_mgr.find(a_id,img)) return;             136     if(!m_mgr.find(a_id,img)) return;
143     m_pv.add_texture(m_out,a_xyzn,a_xyzs,img,a    137     m_pv.add_texture(m_out,a_xyzn,a_xyzs,img,a_tcs);
144   }                                               138   }
145                                                   139 
146   virtual void draw_vertex_normal_array_textur    140   virtual void draw_vertex_normal_array_texture(gl::mode_t a_mode,
147                                          size_    141                                          size_t a_xyzn,
148                                          const    142                                          const float* a_xyzs,
149                                          const    143                                          const float* /*a_nms*/,
150                                          gstoi    144                                          gstoid a_id,
151                                          const    145                                          const float* a_tcs) {
152     draw_vertex_array_texture(a_mode,a_xyzn,a_    146     draw_vertex_array_texture(a_mode,a_xyzn,a_xyzs,a_id,a_tcs);
153   }                                               147   }
154                                                   148 
155   ////////////////////////////////////////////    149   /////////////////////////////////////////////////////////////////
156   /// VBO ////////////////////////////////////    150   /// VBO /////////////////////////////////////////////////////////
157   ////////////////////////////////////////////    151   /////////////////////////////////////////////////////////////////
158   virtual void begin_gsto(gstoid) {}              152   virtual void begin_gsto(gstoid) {}
159   virtual void draw_gsto_v(gl::mode_t,size_t,b    153   virtual void draw_gsto_v(gl::mode_t,size_t,bufpos){}
160   virtual void draw_gsto_vc(gl::mode_t,size_t,    154   virtual void draw_gsto_vc(gl::mode_t,size_t,bufpos,bufpos) {}
161   virtual void draw_gsto_vn(gl::mode_t,size_t,    155   virtual void draw_gsto_vn(gl::mode_t,size_t,bufpos,bufpos) {}
162   virtual void draw_gsto_vcn(gl::mode_t,size_t    156   virtual void draw_gsto_vcn(gl::mode_t,size_t,bufpos,bufpos,bufpos) {}
163   virtual void end_gsto() {}                      157   virtual void end_gsto() {}
164   ////////////////////////////////////////////    158   /////////////////////////////////////////////////////////////////
165   ////////////////////////////////////////////    159   /////////////////////////////////////////////////////////////////
166   ////////////////////////////////////////////    160   /////////////////////////////////////////////////////////////////
167   virtual sg::render_manager& render_manager()    161   virtual sg::render_manager& render_manager() {return m_mgr;}
168 public:                                           162 public:
169   gl2ps_action(gl2ps_manager& a_mgr,std::ostre    163   gl2ps_action(gl2ps_manager& a_mgr,std::ostream& a_out,unsigned int a_ww,unsigned int a_wh)
170   :parent(a_out,a_ww,a_wh)                        164   :parent(a_out,a_ww,a_wh)
171   ,m_mgr(a_mgr)                                   165   ,m_mgr(a_mgr)
172   ,m_gl2ps_context(0)                          << 
173   ,m_FILE(0)                                      166   ,m_FILE(0)
174   ,m_pv(get_me())                                 167   ,m_pv(get_me())
175   ,m_light_color(colorf_white())                  168   ,m_light_color(colorf_white())
176   ,m_light_ambient(colorf_black())             << 
177   ,m_light_direction(vec3f(0,0,-1))               169   ,m_light_direction(vec3f(0,0,-1))
178                                                   170 
179   ,m_ccw(true)                                    171   ,m_ccw(true)
180   ,m_POLYGON_OFFSET_FILL(false)                   172   ,m_POLYGON_OFFSET_FILL(false)
181   ,m_CULL_FACE(true)                              173   ,m_CULL_FACE(true)
182   ,m_POINT_SMOOTH(false)                          174   ,m_POINT_SMOOTH(false)
183   ,m_LINE_SMOOTH(false)                           175   ,m_LINE_SMOOTH(false)
184   ,m_point_size(1)                                176   ,m_point_size(1)
185   ,m_line_width(1)                                177   ,m_line_width(1)
186   ,m_light_on(false)                              178   ,m_light_on(false)
187   ,m_DEPTH_TEST(true)                             179   ,m_DEPTH_TEST(true)
188   {                                               180   {
189     m_back[0] = 1;                                181     m_back[0] = 1;
190     m_back[1] = 1;                                182     m_back[1] = 1;
191     m_back[2] = 1;                                183     m_back[2] = 1;
192                                                   184 
193     m_vp_mtx.set_identity();                      185     m_vp_mtx.set_identity();
194     m_vp_mtx.mul_translate(float(m_ww)/2,float    186     m_vp_mtx.mul_translate(float(m_ww)/2,float(m_wh)/2,0);
195     m_vp_mtx.mul_scale(float(m_ww)/2,float(m_w    187     m_vp_mtx.mul_scale(float(m_ww)/2,float(m_wh)/2,1);
196                                                   188 
197     //m_zb.change_size(a_ww,a_wh);                189     //m_zb.change_size(a_ww,a_wh);
198 //    m_zb.clear_color_buffer(0);                 190 //    m_zb.clear_color_buffer(0);
199 //    m_zb.clear_depth_buffer();                  191 //    m_zb.clear_depth_buffer();
200     m_proj.set_identity();                        192     m_proj.set_identity();
201     m_model.set_identity();                       193     m_model.set_identity();
202     m_normal_matrix.set_identity();               194     m_normal_matrix.set_identity();
203   }                                               195   }
204   virtual ~gl2ps_action(){                     << 196   virtual ~gl2ps_action(){}
205     close();                                   << 
206   }                                            << 
207 protected:                                        197 protected:
208   gl2ps_action(const gl2ps_action& a_from)        198   gl2ps_action(const gl2ps_action& a_from)
209   :parent(a_from)                                 199   :parent(a_from)
210   ,m_mgr(a_from.m_mgr)                            200   ,m_mgr(a_from.m_mgr)
211   ,m_gl2ps_context(0)                          << 
212   ,m_FILE(0)                                      201   ,m_FILE(0)
213                                                   202 
214   ,m_vp_mtx(a_from.m_vp_mtx)                      203   ,m_vp_mtx(a_from.m_vp_mtx)
215   ,m_pv(a_from.m_pv)                              204   ,m_pv(a_from.m_pv)
216   ,m_light_color(a_from.m_light_color)            205   ,m_light_color(a_from.m_light_color)
217   ,m_light_ambient(a_from.m_light_ambient)     << 
218   ,m_light_direction(a_from.m_light_direction)    206   ,m_light_direction(a_from.m_light_direction)
219   ,m_normal(a_from.m_normal)                      207   ,m_normal(a_from.m_normal)
220                                                   208 
221   ,m_proj(a_from.m_proj)                          209   ,m_proj(a_from.m_proj)
222   ,m_model(a_from.m_model)                        210   ,m_model(a_from.m_model)
223   ,m_normal_matrix(a_from.m_normal_matrix)        211   ,m_normal_matrix(a_from.m_normal_matrix)
224   ,m_color(a_from.m_color)                        212   ,m_color(a_from.m_color)
225   ,m_ccw(a_from.m_ccw)                            213   ,m_ccw(a_from.m_ccw)
226   ,m_POLYGON_OFFSET_FILL(a_from.m_POLYGON_OFFS    214   ,m_POLYGON_OFFSET_FILL(a_from.m_POLYGON_OFFSET_FILL)
227   ,m_CULL_FACE(a_from.m_CULL_FACE)                215   ,m_CULL_FACE(a_from.m_CULL_FACE)
228   ,m_POINT_SMOOTH(a_from.m_POINT_SMOOTH)          216   ,m_POINT_SMOOTH(a_from.m_POINT_SMOOTH)
229   ,m_LINE_SMOOTH(a_from.m_LINE_SMOOTH)            217   ,m_LINE_SMOOTH(a_from.m_LINE_SMOOTH)
230   ,m_point_size(a_from.m_point_size)              218   ,m_point_size(a_from.m_point_size)
231   ,m_line_width(a_from.m_line_width)              219   ,m_line_width(a_from.m_line_width)
232   ,m_light_on(a_from.m_light_on)                  220   ,m_light_on(a_from.m_light_on)
233   ,m_DEPTH_TEST(a_from.m_DEPTH_TEST)              221   ,m_DEPTH_TEST(a_from.m_DEPTH_TEST)
234   {                                               222   {
235     m_back[0] = a_from.m_back[0];                 223     m_back[0] = a_from.m_back[0];
236     m_back[1] = a_from.m_back[1];                 224     m_back[1] = a_from.m_back[1];
237     m_back[2] = a_from.m_back[2];                 225     m_back[2] = a_from.m_back[2];
238   }                                               226   }
239   gl2ps_action& operator=(const gl2ps_action&     227   gl2ps_action& operator=(const gl2ps_action& a_from){
240     parent::operator=(a_from);                    228     parent::operator=(a_from);
241     if(&a_from==this) return *this;               229     if(&a_from==this) return *this;
242     close();                                      230     close();
243     m_back[0] = a_from.m_back[0];                 231     m_back[0] = a_from.m_back[0];
244     m_back[1] = a_from.m_back[1];                 232     m_back[1] = a_from.m_back[1];
245     m_back[2] = a_from.m_back[2];                 233     m_back[2] = a_from.m_back[2];
246                                                   234 
247     m_vp_mtx = a_from.m_vp_mtx;                   235     m_vp_mtx = a_from.m_vp_mtx;
248     m_pv = a_from.m_pv;                           236     m_pv = a_from.m_pv;
249     m_light_color = a_from.m_light_color;         237     m_light_color = a_from.m_light_color;
250     m_light_ambient = a_from.m_light_ambient;  << 
251     m_light_direction = a_from.m_light_directi    238     m_light_direction = a_from.m_light_direction;
252     m_normal = a_from.m_normal;                   239     m_normal = a_from.m_normal;
253                                                   240 
254     m_proj = a_from.m_proj;                       241     m_proj = a_from.m_proj;
255     m_model = a_from.m_model;                     242     m_model = a_from.m_model;
256     m_normal_matrix = a_from.m_normal_matrix;     243     m_normal_matrix = a_from.m_normal_matrix;
257     m_color = a_from.m_color;                     244     m_color = a_from.m_color;
258     m_ccw = a_from.m_ccw;                         245     m_ccw = a_from.m_ccw;
259     m_POLYGON_OFFSET_FILL = a_from.m_POLYGON_O    246     m_POLYGON_OFFSET_FILL = a_from.m_POLYGON_OFFSET_FILL;
260     m_CULL_FACE = a_from.m_CULL_FACE;             247     m_CULL_FACE = a_from.m_CULL_FACE;
261     m_POINT_SMOOTH = a_from.m_POINT_SMOOTH;       248     m_POINT_SMOOTH = a_from.m_POINT_SMOOTH;
262     m_LINE_SMOOTH = a_from.m_LINE_SMOOTH;         249     m_LINE_SMOOTH = a_from.m_LINE_SMOOTH;
263     m_point_size = a_from.m_point_size;           250     m_point_size = a_from.m_point_size;
264     m_line_width = a_from.m_line_width;           251     m_line_width = a_from.m_line_width;
265     m_light_on = a_from.m_light_on;               252     m_light_on = a_from.m_light_on;
266     m_DEPTH_TEST = a_from.m_DEPTH_TEST;           253     m_DEPTH_TEST = a_from.m_DEPTH_TEST;
267     return *this;                                 254     return *this;
268   }                                               255   }
269 public:                                           256 public:
270   bool open(const std::string& a_name,int a_fo    257   bool open(const std::string& a_name,int a_format = TOOLS_GL2PS_EPS) {
271     return open(a_name,a_format,-1,-1);        << 258     if(m_FILE) return false;
272   }                                            << 259     m_FILE = ::fopen(a_name.c_str(),"w");
273   bool open(const std::string& a_name,int a_fo << 
274     close();                                   << 
275                                                << 
276     m_gl2ps_context = ::tools_gl2psCreateConte << 
277     if(!m_gl2ps_context) {                     << 
278       m_out << "tools::sg::gl2ps_action::open  << 
279             << " can't create gl2ps context."  << 
280             << std::endl;                      << 
281       return false;                            << 
282     }                                          << 
283                                                << 
284     m_FILE = ::fopen(a_name.c_str(),"wb");     << 
285     if(!m_FILE) {                                 260     if(!m_FILE) {
286       m_out << "tools::sg::gl2ps_action::open     261       m_out << "tools::sg::gl2ps_action::open :"
287             << " can't open file " << a_name <    262             << " can't open file " << a_name << "."
288             << std::endl;                         263             << std::endl;
289       ::tools_gl2psDeleteContext(m_gl2ps_conte << 
290       m_gl2ps_context = 0;                     << 
291       return false;                               264       return false;
292     }                                             265     }
293                                                   266 
294     int sort = 0;                              << 267     int options = TOOLS_GL2PS_OCCLUSION_CULL
295     if(a_sort==(-1)) {                         << 
296       sort = TOOLS_GL2PS_BSP_SORT;             << 
297     } else {                                   << 
298       sort = a_sort;                           << 
299     }                                          << 
300                                                << 
301     int options = 0;                           << 
302     if(a_options==(-1)) {                      << 
303       options = TOOLS_GL2PS_SILENT             << 
304       | TOOLS_GL2PS_OCCLUSION_CULL             << 
305       | TOOLS_GL2PS_BEST_ROOT                     268       | TOOLS_GL2PS_BEST_ROOT
                                                   >> 269       | TOOLS_GL2PS_SILENT
306       | TOOLS_GL2PS_DRAW_BACKGROUND;              270       | TOOLS_GL2PS_DRAW_BACKGROUND;
307     } else {                                   << 271     //int sort = TOOLS_GL2PS_NO_SORT;
308       options = a_options;                     << 272     //int sort = TOOLS_GL2PS_SIMPLE_SORT;
309     }                                          << 273     int sort = TOOLS_GL2PS_BSP_SORT;
310                                                << 274 
311     tools_GLint vp[4];                            275     tools_GLint vp[4];
312     vp[0] = 0;                                    276     vp[0] = 0;
313     vp[1] = 0;                                    277     vp[1] = 0;
314     vp[2] = m_ww;                                 278     vp[2] = m_ww;
315     vp[3] = m_wh;                                 279     vp[3] = m_wh;
316                                                   280 
317     int bufsize = 0;                              281     int bufsize = 0;
318     if(::tools_gl2psBeginPage(m_gl2ps_context, << 282     ::tools_gl2psBeginPage("","tools_sg_write_gl2ps",
319                      vp,a_format,sort,options,    283                      vp,a_format,sort,options,
320                      TOOLS_GL_RGBA,0, NULL,0,0    284                      TOOLS_GL_RGBA,0, NULL,0,0,0,bufsize,
321                      m_FILE,a_name.c_str())==T << 285                      m_FILE,a_name.c_str());
322       m_out << "tools::sg::gl2ps_action::open  << 286 
323             << " tools_gl2psBeginPage() failed << 287     ::tools_gl2psSetBackgroundColor(m_back[0],m_back[1],m_back[2]);
324             << std::endl;                      << 
325       ::fclose(m_FILE);                        << 
326       m_FILE = 0;                              << 
327       ::tools_gl2psDeleteContext(m_gl2ps_conte << 
328       m_gl2ps_context = 0;                     << 
329       return false;                            << 
330     }                                          << 
331                                                << 
332     ::tools_gl2psSetBackgroundColor(m_gl2ps_co << 
333                                                   288 
334     m_vp_mtx.set_identity();                      289     m_vp_mtx.set_identity();
335     m_vp_mtx.mul_translate(float(m_ww)/2,float    290     m_vp_mtx.mul_translate(float(m_ww)/2,float(m_wh)/2,0);
336     m_vp_mtx.mul_scale(float(m_ww)/2,float(m_w    291     m_vp_mtx.mul_scale(float(m_ww)/2,float(m_wh)/2,1);
337                                                   292 
338     return true;                                  293     return true;
339   }                                               294   }
340                                                   295 
341   bool close() {                                  296   bool close() {
342     tools_GLint _status = 0;                   << 297     if(!m_FILE) return false;
343     if(m_gl2ps_context) {                      << 298     ::tools_gl2psEndPage();
344       _status = ::tools_gl2psEndPage(m_gl2ps_c << 299     ::fclose(m_FILE);
345     }                                          << 300     m_FILE = 0;
346     if(m_FILE) {                               << 
347       ::fclose(m_FILE);                        << 
348       m_FILE = 0;                              << 
349     }                                          << 
350     if(m_gl2ps_context) {                      << 
351       ::tools_gl2psDeleteContext(m_gl2ps_conte << 
352       m_gl2ps_context = 0;                     << 
353     }                                          << 
354     if (_status == TOOLS_GL2PS_OVERFLOW) retur << 
355     return true;                                  301     return true;
356   }                                               302   }
357   void set_background(float a_r,float a_g,floa    303   void set_background(float a_r,float a_g,float a_b) {
358     m_back[0] = a_r;                              304     m_back[0] = a_r;
359     m_back[1] = a_g;                              305     m_back[1] = a_g;
360     m_back[2] = a_b;                              306     m_back[2] = a_b;
361   }                                               307   }
362 protected:                                        308 protected:
363   void set_normal_matrix() {                      309   void set_normal_matrix() {
364     mat4f tmp(m_model);                           310     mat4f tmp(m_model);
365     tmp.no_translate();                           311     tmp.no_translate();
366     if(!tmp.invert(m_normal_matrix)) {            312     if(!tmp.invert(m_normal_matrix)) {
367       m_out << "tools::sg::gl2ps_action::set_n << 313       m_out << "mem_action::set_normal_matrix : can't invert model matrix." << std::endl;
368     }                                             314     }
369     m_normal_matrix.transpose();                  315     m_normal_matrix.transpose();
370   }                                               316   }
371                                                   317 
372   bool project_point(float& a_x,float& a_y,flo    318   bool project_point(float& a_x,float& a_y,float& a_z,float& a_w) {
373     a_w = 1;                                      319     a_w = 1;
374     m_model.mul_4f(a_x,a_y,a_z,a_w);              320     m_model.mul_4f(a_x,a_y,a_z,a_w);
375     m_proj.mul_4f(a_x,a_y,a_z,a_w);               321     m_proj.mul_4f(a_x,a_y,a_z,a_w);
376     if(a_w==0) return false;                      322     if(a_w==0) return false;
377     a_x /= a_w;                                   323     a_x /= a_w;
378     a_y /= a_w;                                   324     a_y /= a_w;
379     a_z /= a_w;                                   325     a_z /= a_w;
380     return true;                                  326     return true;
381   }                                               327   }
382 //  bool project_normal(float& a_x,float& a_y,    328 //  bool project_normal(float& a_x,float& a_y,float& a_z) {
383 //    m_normal_matrix.mul_dir_3f(a_x,a_y,a_z);    329 //    m_normal_matrix.mul_dir_3f(a_x,a_y,a_z);
384 //  //m_proj.mul_dir_3f(a_x,a_y,a_z); //?         330 //  //m_proj.mul_dir_3f(a_x,a_y,a_z); //?
385 //    return true;                                331 //    return true;
386 //  }                                             332 //  }
387                                                   333 
388   static void set_vtx(tools_GL2PSvertex* a_vs,    334   static void set_vtx(tools_GL2PSvertex* a_vs,unsigned int a_index,
389                       float a_x,float a_y,floa    335                       float a_x,float a_y,float a_z,
390                       float a_r,float a_g,floa    336                       float a_r,float a_g,float a_b,float a_a){
391     a_vs[a_index].xyz[0] = a_x;                   337     a_vs[a_index].xyz[0] = a_x;
392     a_vs[a_index].xyz[1] = a_y;                   338     a_vs[a_index].xyz[1] = a_y;
393     a_vs[a_index].xyz[2] = a_z;                   339     a_vs[a_index].xyz[2] = a_z;
394     a_vs[a_index].rgba[0] = a_r;                  340     a_vs[a_index].rgba[0] = a_r;
395     a_vs[a_index].rgba[1] = a_g;                  341     a_vs[a_index].rgba[1] = a_g;
396     a_vs[a_index].rgba[2] = a_b;                  342     a_vs[a_index].rgba[2] = a_b;
397     a_vs[a_index].rgba[3] = a_a;                  343     a_vs[a_index].rgba[3] = a_a;
398   }                                               344   }
399                                                   345 
400   class primvis : public primitive_visitor {      346   class primvis : public primitive_visitor {
401   protected:                                      347   protected:
402     virtual bool project(float& a_x,float& a_y    348     virtual bool project(float& a_x,float& a_y,float& a_z,float& a_w) {
403       return m_this.project_point(a_x,a_y,a_z,    349       return m_this.project_point(a_x,a_y,a_z,a_w);
404     }                                             350     }
405     virtual bool add_point(float a_x,float a_y    351     virtual bool add_point(float a_x,float a_y,float a_z,float) {
406       if(!m_this.m_gl2ps_context) return false << 
407                                                << 
408       float r = m_this.m_color[0];                352       float r = m_this.m_color[0];
409       float g = m_this.m_color[1];                353       float g = m_this.m_color[1];
410       float b = m_this.m_color[2];                354       float b = m_this.m_color[2];
411       float a = m_this.m_color[3];                355       float a = m_this.m_color[3];
412                                                   356 
413       tools_GLint offset = 0;                     357       tools_GLint offset = 0;
414       tools_GLfloat ofactor = 0;               << 358       tools_GLfloat ofactor = 0; //
415       tools_GLfloat ounits = 0;                << 359       tools_GLfloat ounits = 0;  //
416       tools_GLushort pattern = 0;                 360       tools_GLushort pattern = 0;
417       tools_GLint factor = 0;                     361       tools_GLint factor = 0;
418       tools_GLfloat sz = m_this.m_point_size;     362       tools_GLfloat sz = m_this.m_point_size;
419       tools_GLint linecap = 0;                 << 363       tools_GLint linecap = 0;  //
420       tools_GLint linejoin = 0;                << 364       tools_GLint linejoin = 0; //
421       char boundary = 0;                       << 365       char boundary = 0;  //
422                                                   366 
423       tools_GL2PSvertex vertices[1];              367       tools_GL2PSvertex vertices[1];
424                                                   368 
425       m_this.m_vp_mtx.mul_3f(a_x,a_y,a_z);        369       m_this.m_vp_mtx.mul_3f(a_x,a_y,a_z);
426                                                   370 
427       m_this.set_vtx(vertices,0, a_x,a_y,a_z,     371       m_this.set_vtx(vertices,0, a_x,a_y,a_z, r,g,b,a);
428       ::tools_gl2psAddPolyPrimitive(m_this.m_g << 372 
                                                   >> 373       ::tools_gl2psAddPolyPrimitive(_GL2PS_POINT(),1,vertices,offset,ofactor,ounits,pattern,factor,sz,linecap,linejoin,boundary);
429       return true;                                374       return true;
430     }                                             375     }
431                                                   376 
432     virtual bool add_point(float a_x,float a_y    377     virtual bool add_point(float a_x,float a_y,float a_z,float,
433                            float a_r,float a_g    378                            float a_r,float a_g,float a_b,float a_a) {
434       if(!m_this.m_gl2ps_context) return false << 
435                                                << 
436       tools_GLint offset = 0;                     379       tools_GLint offset = 0;
437       tools_GLfloat ofactor = 0;               << 380       tools_GLfloat ofactor = 0; //
438       tools_GLfloat ounits = 0;                << 381       tools_GLfloat ounits = 0;  //
439       tools_GLushort pattern = 0;                 382       tools_GLushort pattern = 0;
440       tools_GLint factor = 0;                     383       tools_GLint factor = 0;
441       tools_GLfloat sz = m_this.m_point_size;     384       tools_GLfloat sz = m_this.m_point_size;
442       tools_GLint linecap = 0;                 << 385       tools_GLint linecap = 0;  //
443       tools_GLint linejoin = 0;                << 386       tools_GLint linejoin = 0; //
444       char boundary = 0;                       << 387       char boundary = 0;  //
445                                                   388 
446       tools_GL2PSvertex vertices[1];              389       tools_GL2PSvertex vertices[1];
447                                                   390 
448       m_this.m_vp_mtx.mul_3f(a_x,a_y,a_z);        391       m_this.m_vp_mtx.mul_3f(a_x,a_y,a_z);
449                                                   392 
450       m_this.set_vtx(vertices,0, a_x,a_y,a_z,     393       m_this.set_vtx(vertices,0, a_x,a_y,a_z, a_r,a_g,a_b,a_a);
451                                                   394 
452       ::tools_gl2psAddPolyPrimitive(m_this.m_g << 395       //::tools_gl2psAddPolyPrimitive(_GL2PS_POINT(),1,vertices,0,pattern,factor,sz,0);
                                                   >> 396       ::tools_gl2psAddPolyPrimitive(_GL2PS_POINT(),1,vertices,offset,ofactor,ounits,pattern,factor,sz,linecap,linejoin,boundary);
453       return true;                                397       return true;
454     }                                             398     }
455                                                   399 
456     virtual bool add_line(float a_bx,float a_b    400     virtual bool add_line(float a_bx,float a_by,float a_bz,float,
457                           float a_ex,float a_e    401                           float a_ex,float a_ey,float a_ez,float) {
458       if(!m_this.m_gl2ps_context) return false << 
459                                                << 
460       float r = m_this.m_color[0];                402       float r = m_this.m_color[0];
461       float g = m_this.m_color[1];                403       float g = m_this.m_color[1];
462       float b = m_this.m_color[2];                404       float b = m_this.m_color[2];
463       float a = m_this.m_color[3];                405       float a = m_this.m_color[3];
464                                                   406 
465       tools_GLint offset = 0;                     407       tools_GLint offset = 0;
466       tools_GLfloat ofactor = 0;               << 408       tools_GLfloat ofactor = 0; //
467       tools_GLfloat ounits = 0;                << 409       tools_GLfloat ounits = 0;  //
468       tools_GLushort pattern = 0;                 410       tools_GLushort pattern = 0;
469       tools_GLint factor = 0;                     411       tools_GLint factor = 0;
470       tools_GLfloat lwidth = m_this.m_line_wid    412       tools_GLfloat lwidth = m_this.m_line_width;
471       tools_GLint linecap = 0;                 << 413       tools_GLint linecap = 0;  //
472       tools_GLint linejoin = 0;                << 414       tools_GLint linejoin = 0; //
473       char boundary = 0;                       << 415       char boundary = 0;  //
474                                                   416 
475       tools_GL2PSvertex vertices[2];              417       tools_GL2PSvertex vertices[2];
476                                                   418 
477       m_this.m_vp_mtx.mul_3f(a_bx,a_by,a_bz);     419       m_this.m_vp_mtx.mul_3f(a_bx,a_by,a_bz);
478       m_this.m_vp_mtx.mul_3f(a_ex,a_ey,a_ez);     420       m_this.m_vp_mtx.mul_3f(a_ex,a_ey,a_ez);
479                                                   421 
480       m_this.set_vtx(vertices,0, a_bx,a_by,a_b    422       m_this.set_vtx(vertices,0, a_bx,a_by,a_bz, r,g,b,a);
481       m_this.set_vtx(vertices,1, a_ex,a_ey,a_e    423       m_this.set_vtx(vertices,1, a_ex,a_ey,a_ez, r,g,b,a);
482                                                   424 
483       ::tools_gl2psAddPolyPrimitive(m_this.m_g << 425       //::tools_gl2psAddPolyPrimitive(_GL2PS_LINE(),2,vertices,0,pattern,factor,lwidth,0);
                                                   >> 426       ::tools_gl2psAddPolyPrimitive(_GL2PS_LINE(),2,vertices,offset,ofactor,ounits,pattern,factor,lwidth,linecap,linejoin,boundary);
484                                                   427 
485       return true;                                428       return true;
486     }                                             429     }
487                                                   430 
488     virtual bool add_line(float a_bx,float a_b    431     virtual bool add_line(float a_bx,float a_by,float a_bz,float,
489                           float a_br,float a_b    432                           float a_br,float a_bg,float a_bb,float a_ba,
490                           float a_ex,float a_e    433                           float a_ex,float a_ey,float a_ez,float,
491                           float a_er,float a_e    434                           float a_er,float a_eg,float a_eb,float a_ea){
492       if(!m_this.m_gl2ps_context) return false << 
493                                                   435 
494       tools_GLint offset = 0;                     436       tools_GLint offset = 0;
495       tools_GLfloat ofactor = 0;               << 437       tools_GLfloat ofactor = 0; //
496       tools_GLfloat ounits = 0;                << 438       tools_GLfloat ounits = 0;  //
497       tools_GLushort pattern = 0;                 439       tools_GLushort pattern = 0;
498       tools_GLint factor = 0;                     440       tools_GLint factor = 0;
499       tools_GLfloat lwidth = m_this.m_line_wid    441       tools_GLfloat lwidth = m_this.m_line_width;
500       tools_GLint linecap = 0;                 << 442       tools_GLint linecap = 0;  //
501       tools_GLint linejoin = 0;                << 443       tools_GLint linejoin = 0; //
502       char boundary = 0;                       << 444       char boundary = 0;  //
503                                                   445 
504       tools_GL2PSvertex vertices[2];              446       tools_GL2PSvertex vertices[2];
505                                                   447 
506       m_this.m_vp_mtx.mul_3f(a_bx,a_by,a_bz);     448       m_this.m_vp_mtx.mul_3f(a_bx,a_by,a_bz);
507       m_this.m_vp_mtx.mul_3f(a_ex,a_ey,a_ez);     449       m_this.m_vp_mtx.mul_3f(a_ex,a_ey,a_ez);
508                                                   450 
509       m_this.set_vtx(vertices,0, a_bx,a_by,a_b    451       m_this.set_vtx(vertices,0, a_bx,a_by,a_bz, a_br,a_bg,a_bb,a_ba);
510       m_this.set_vtx(vertices,1, a_ex,a_ey,a_e    452       m_this.set_vtx(vertices,1, a_ex,a_ey,a_ez, a_er,a_eg,a_eb,a_ea);
511                                                   453 
512       //tools_gl2psAddPolyPrimitive(m_this.m_g << 454       //tools_gl2psAddPolyPrimitive(_GL2PS_LINE(),2,vertices,0,pattern,factor,lwidth,0);
513       ::tools_gl2psAddPolyPrimitive(m_this.m_g << 455       ::tools_gl2psAddPolyPrimitive(_GL2PS_LINE(),2,vertices,offset,ofactor,ounits,pattern,factor,lwidth,linecap,linejoin,boundary);
514                                                   456 
515       return true;                                457       return true;
516     }                                             458     }
517                                                   459 
518     virtual bool add_triangle(float a_p1x,floa << 460     virtual bool add_triangle(float a_p1x,float a_p1y,float a_p1z,float,
519                               float a_p2x,floa << 461                               float a_p2x,float a_p2y,float a_p2z,float,
520                               float a_p3x,floa << 462                               float a_p3x,float a_p3y,float a_p3z,float){
521       float r = m_this.m_color[0];                463       float r = m_this.m_color[0];
522       float g = m_this.m_color[1];                464       float g = m_this.m_color[1];
523       float b = m_this.m_color[2];                465       float b = m_this.m_color[2];
524       float a = m_this.m_color[3];                466       float a = m_this.m_color[3];
525       return _add_triangle(a_p1x,a_p1y,a_p1z,a << 467 
526                            m_this.m_normal.x() << 468       tools_GLint offset = 0;
527                            r,g,b,a,            << 469       tools_GLfloat ofactor = 0; //
528                            a_p2x,a_p2y,a_p2z,a << 470       tools_GLfloat ounits = 0;  //
529                            m_this.m_normal.x() << 471       tools_GLushort pattern = 0;
530                            r,g,b,a,            << 472       tools_GLint factor = 0;
531                            a_p3x,a_p3y,a_p3z,a << 473       tools_GLfloat lwidth = m_this.m_line_width;
532                            m_this.m_normal.x() << 474       tools_GLint linecap = 0;  //
533                            r,g,b,a);           << 475       tools_GLint linejoin = 0; //
                                                   >> 476       char boundary = 0;  //
                                                   >> 477 
                                                   >> 478       tools_GL2PSvertex vertices[3];
                                                   >> 479 
                                                   >> 480       m_this.m_vp_mtx.mul_3f(a_p1x,a_p1y,a_p1z);
                                                   >> 481       m_this.m_vp_mtx.mul_3f(a_p2x,a_p2y,a_p2z);
                                                   >> 482       m_this.m_vp_mtx.mul_3f(a_p3x,a_p3y,a_p3z);
                                                   >> 483 
                                                   >> 484       m_this.set_vtx(vertices,0, a_p1x,a_p1y,a_p1z, r,g,b,a);
                                                   >> 485       m_this.set_vtx(vertices,1, a_p2x,a_p2y,a_p2z, r,g,b,a);
                                                   >> 486       m_this.set_vtx(vertices,2, a_p3x,a_p3y,a_p3z, r,g,b,a);
                                                   >> 487 
                                                   >> 488       //tools_gl2psAddPolyPrimitive(_GL2PS_TRIANGLE(),3,vertices,0,pattern,factor,lwidth,0);
                                                   >> 489       ::tools_gl2psAddPolyPrimitive(_GL2PS_TRIANGLE(),3,vertices,offset,ofactor,ounits,pattern,factor,lwidth,linecap,linejoin,boundary);
                                                   >> 490 
                                                   >> 491       return true;
534     }                                             492     }
535                                                   493 
536     virtual bool add_triangle(                    494     virtual bool add_triangle(
537       float a_p1x,float a_p1y,float a_p1z,floa << 495       float a_p1x,float a_p1y,float a_p1z,float,
538       float a_r1,float a_g1,float a_b1,float a    496       float a_r1,float a_g1,float a_b1,float a_a1,
539       float a_p2x,float a_p2y,float a_p2z,floa << 497       float a_p2x,float a_p2y,float a_p2z,float,
540       float a_r2,float a_g2,float a_b2,float a    498       float a_r2,float a_g2,float a_b2,float a_a2,
541       float a_p3x,float a_p3y,float a_p3z,floa << 499       float a_p3x,float a_p3y,float a_p3z,float,
542       float a_r3,float a_g3,float a_b3,float a    500       float a_r3,float a_g3,float a_b3,float a_a3){
543                                                   501 
544       return _add_triangle(a_p1x,a_p1y,a_p1z,a << 502       tools_GLint offset = 0;
545                            m_this.m_normal.x() << 503       tools_GLfloat ofactor = 0; //
546                            a_r1,a_g1,a_b1,a_a1 << 504       tools_GLfloat ounits = 0;  //
547                            a_p2x,a_p2y,a_p2z,a << 505       tools_GLushort pattern = 0;
548                            m_this.m_normal.x() << 506       tools_GLint factor = 0;
549                            a_r2,a_g2,a_b2,a_a2 << 507       tools_GLfloat lwidth = m_this.m_line_width;
550                            a_p3x,a_p3y,a_p3z,a << 508       tools_GLint linecap = 0;  //
551                            m_this.m_normal.x() << 509       tools_GLint linejoin = 0; //
552                            a_r3,a_g3,a_b3,a_a3 << 510       char boundary = 0;  //
                                                   >> 511 
                                                   >> 512       tools_GL2PSvertex vertices[3];
                                                   >> 513 
                                                   >> 514       m_this.m_vp_mtx.mul_3f(a_p1x,a_p1y,a_p1z);
                                                   >> 515       m_this.m_vp_mtx.mul_3f(a_p2x,a_p2y,a_p2z);
                                                   >> 516       m_this.m_vp_mtx.mul_3f(a_p3x,a_p3y,a_p3z);
                                                   >> 517 
                                                   >> 518       m_this.set_vtx(vertices,0, a_p1x,a_p1y,a_p1z, a_r1,a_g1,a_b1,a_a1);
                                                   >> 519       m_this.set_vtx(vertices,1, a_p2x,a_p2y,a_p2z, a_r2,a_g2,a_b2,a_a2);
                                                   >> 520       m_this.set_vtx(vertices,2, a_p3x,a_p3y,a_p3z, a_r3,a_g3,a_b3,a_a3);
                                                   >> 521 
                                                   >> 522       //tools_gl2psAddPolyPrimitive(_GL2PS_TRIANGLE(),3,vertices,0,pattern,factor,lwidth,0);
                                                   >> 523       ::tools_gl2psAddPolyPrimitive(_GL2PS_TRIANGLE(),3,vertices,offset,ofactor,ounits,pattern,factor,lwidth,linecap,linejoin,boundary);
                                                   >> 524 
                                                   >> 525       return true;
553     }                                             526     }
554                                                   527 
555     virtual bool project_normal(float& /*a_x*/    528     virtual bool project_normal(float& /*a_x*/,float& /*a_y*/,float& /*a_z*/) {
556       //return m_this.project_normal(a_x,a_y,a    529       //return m_this.project_normal(a_x,a_y,a_z);
557       return true;                                530       return true;
558     }                                             531     }
559     virtual bool add_point_normal(float a_x,fl    532     virtual bool add_point_normal(float a_x,float a_y,float a_z,float a_w,
560                                   float /*a_nx    533                                   float /*a_nx*/,float /*a_ny*/,float /*a_nz*/) {
561       add_point(a_x,a_y,a_z,a_w);                 534       add_point(a_x,a_y,a_z,a_w);
562     //m_this.m_points.add_normal(a_nx,a_ny,a_n    535     //m_this.m_points.add_normal(a_nx,a_ny,a_nz);
563       return true;                                536       return true;
564     }                                             537     }
565     virtual bool add_point_normal(float a_x,fl    538     virtual bool add_point_normal(float a_x,float a_y,float a_z,float a_w,
566                                   float /*a_nx    539                                   float /*a_nx*/,float /*a_ny*/,float /*a_nz*/,
567                                   float a_r,fl    540                                   float a_r,float a_g,float a_b,float a_a) {
568       add_point(a_x,a_y,a_z,a_w,a_r,a_g,a_b,a_    541       add_point(a_x,a_y,a_z,a_w,a_r,a_g,a_b,a_a);
569     //m_this.m_points.add_normal(a_nx,a_ny,a_n    542     //m_this.m_points.add_normal(a_nx,a_ny,a_nz);
570       return true;                                543       return true;
571     }                                             544     }
572     virtual bool add_line_normal(float a_bx,fl    545     virtual bool add_line_normal(float a_bx,float a_by,float a_bz,float a_bw,
573                                  float /*a_bnx    546                                  float /*a_bnx*/,float /*a_bny*/,float /*a_bnz*/,
574                                  float a_ex,fl    547                                  float a_ex,float a_ey,float a_ez,float a_ew,
575                                  float /*a_enx    548                                  float /*a_enx*/,float /*a_eny*/,float /*a_enz*/) {
576       add_line(a_bx,a_by,a_bz,a_bw, a_ex,a_ey,    549       add_line(a_bx,a_by,a_bz,a_bw, a_ex,a_ey,a_ez,a_ew);
577     //m_this.m_lines.add_normal(a_bnx,a_bny,a_    550     //m_this.m_lines.add_normal(a_bnx,a_bny,a_bnz);
578     //m_this.m_lines.add_normal(a_enx,a_eny,a_    551     //m_this.m_lines.add_normal(a_enx,a_eny,a_enz);
579       return true;                                552       return true;
580     }                                             553     }
581     virtual bool add_line_normal(float a_bx,fl    554     virtual bool add_line_normal(float a_bx,float a_by,float a_bz,float a_bw,
582                                  float /*a_bnx    555                                  float /*a_bnx*/,float /*a_bny*/,float /*a_bnz*/,
583                                  float a_br,fl    556                                  float a_br,float a_bg,float a_bb,float a_ba,
584                                  float a_ex,fl    557                                  float a_ex,float a_ey,float a_ez,float a_ew,
585                                  float /*a_enx    558                                  float /*a_enx*/,float /*a_eny*/,float /*a_enz*/,
586                                  float a_er,fl    559                                  float a_er,float a_eg,float a_eb,float a_ea){
587       add_line(a_bx,a_by,a_bz,a_bw, a_br,a_bg,    560       add_line(a_bx,a_by,a_bz,a_bw, a_br,a_bg,a_bb,a_ba, a_ex,a_ey,a_ez,a_ew, a_er,a_eg,a_eb,a_ea);
588     //m_this.m_lines.add_normal(a_bnx,a_bny,a_    561     //m_this.m_lines.add_normal(a_bnx,a_bny,a_bnz);
589     //m_this.m_lines.add_normal(a_enx,a_eny,a_    562     //m_this.m_lines.add_normal(a_enx,a_eny,a_enz);
590       return true;                                563       return true;
591     }                                             564     }
592     virtual bool add_triangle_normal(             565     virtual bool add_triangle_normal(
593       float a_p1x,float a_p1y,float a_p1z,floa    566       float a_p1x,float a_p1y,float a_p1z,float a_p1w,
594       float a_n1x,float a_n1y,float a_n1z,     << 567       float /*a_n1x*/,float /*a_n1y*/,float /*a_n1z*/,
595       float a_p2x,float a_p2y,float a_p2z,floa    568       float a_p2x,float a_p2y,float a_p2z,float a_p2w,
596       float a_n2x,float a_n2y,float a_n2z,     << 569       float /*a_n2x*/,float /*a_n2y*/,float /*a_n2z*/,
597       float a_p3x,float a_p3y,float a_p3z,floa    570       float a_p3x,float a_p3y,float a_p3z,float a_p3w,
598       float a_n3x,float a_n3y,float a_n3z) {   << 571       float /*a_n3x*/,float /*a_n3y*/,float /*a_n3z*/) {
599                                                << 572       add_triangle(a_p1x,a_p1y,a_p1z,a_p1w,
600       float r = m_this.m_color[0];             << 573                    a_p2x,a_p2y,a_p2z,a_p2w,
601       float g = m_this.m_color[1];             << 574                    a_p3x,a_p3y,a_p3z,a_p3w);
602       float b = m_this.m_color[2];             << 575     //m_this.m_triangles.add_normal(a_n1x,a_n1y,a_n1z);
603       float a = m_this.m_color[3];             << 576     //m_this.m_triangles.add_normal(a_n2x,a_n2y,a_n2z);
604                                                << 577     //m_this.m_triangles.add_normal(a_n3x,a_n3y,a_n3z);
605       return _add_triangle(a_p1x,a_p1y,a_p1z,a << 578       return true;
606                            a_n1x,a_n1y,a_n1z,  << 
607                            r,g,b,a,            << 
608                            a_p2x,a_p2y,a_p2z,a << 
609                            a_n2x,a_n2y,a_n2z,  << 
610                            r,g,b,a,            << 
611                            a_p3x,a_p3y,a_p3z,a << 
612                            a_n3x,a_n3y,a_n3z,  << 
613                            r,g,b,a);           << 
614     }                                             579     }
615     virtual bool add_triangle_normal(             580     virtual bool add_triangle_normal(
616       float a_p1x,float a_p1y,float a_p1z,floa    581       float a_p1x,float a_p1y,float a_p1z,float a_p1w,
617       float a_n1x,float a_n1y,float a_n1z,     << 582       float /*a_n1x*/,float /*a_n1y*/,float /*a_n1z*/,
618       float a_r1,float a_g1,float a_b1,float a    583       float a_r1,float a_g1,float a_b1,float a_a1,
619       float a_p2x,float a_p2y,float a_p2z,floa    584       float a_p2x,float a_p2y,float a_p2z,float a_p2w,
620       float a_n2x,float a_n2y,float a_n2z,     << 585       float /*a_n2x*/,float /*a_n2y*/,float /*a_n2z*/,
621       float a_r2,float a_g2,float a_b2,float a    586       float a_r2,float a_g2,float a_b2,float a_a2,
622       float a_p3x,float a_p3y,float a_p3z,floa    587       float a_p3x,float a_p3y,float a_p3z,float a_p3w,
623       float a_n3x,float a_n3y,float a_n3z,     << 588       float /*a_n3x*/,float /*a_n3y*/,float /*a_n3z*/,
624       float a_r3,float a_g3,float a_b3,float a    589       float a_r3,float a_g3,float a_b3,float a_a3){
625       return _add_triangle(a_p1x,a_p1y,a_p1z,a << 590       add_triangle(a_p1x,a_p1y,a_p1z,a_p1w,
626                            a_n1x,a_n1y,a_n1z,  << 591                    a_r1,a_g1,a_b1,a_a1,
627                            a_r1,a_g1,a_b1,a_a1 << 592                    a_p2x,a_p2y,a_p2z,a_p2w,
628                            a_p2x,a_p2y,a_p2z,a << 593                    a_r2,a_g2,a_b2,a_a2,
629                            a_n2x,a_n2y,a_n2z,  << 594                    a_p3x,a_p3y,a_p3z,a_p3w,
630                            a_r2,a_g2,a_b2,a_a2 << 595                    a_r3,a_g3,a_b3,a_a3);
631                            a_p3x,a_p3y,a_p3z,a << 596     //m_this.m_triangles.add_normal(a_n1x,a_n1y,a_n1z);
632                            a_n3x,a_n3y,a_n3z,  << 597     //m_this.m_triangles.add_normal(a_n2x,a_n2y,a_n2z);
633                            a_r3,a_g3,a_b3,a_a3 << 598     //m_this.m_triangles.add_normal(a_n3x,a_n3y,a_n3z);
                                                   >> 599       return true;
634     }                                             600     }
635   public:                                         601   public:
636     primvis(gl2ps_action& a_this):m_this(a_thi    602     primvis(gl2ps_action& a_this):m_this(a_this){}
637     virtual ~primvis(){}                          603     virtual ~primvis(){}
638   public:                                         604   public:
639     primvis(const primvis& a_from)                605     primvis(const primvis& a_from)
640     :primitive_visitor(a_from)                    606     :primitive_visitor(a_from)
641     ,m_this(a_from.m_this)                        607     ,m_this(a_from.m_this)
642     {}                                            608     {}
643     primvis& operator=(const primvis& a_from){    609     primvis& operator=(const primvis& a_from){
644       primitive_visitor::operator=(a_from);       610       primitive_visitor::operator=(a_from);
645       return *this;                               611       return *this;
646     }                                             612     }
647   protected:                                   << 
648     bool _add_triangle(float a_p1x,float a_p1y << 
649                        float a_n1x,float a_n1y << 
650                        float a_r1,float a_g1,f << 
651                        float a_p2x,float a_p2y << 
652                        float a_n2x,float a_n2y << 
653                        float a_r2,float a_g2,f << 
654                        float a_p3x,float a_p3y << 
655                        float a_n3x,float a_n3y << 
656                        float a_r3,float a_g3,f << 
657                                                << 
658       if(!m_this.m_gl2ps_context) return false << 
659                                                << 
660       float p1x = a_p1x;float p1y = a_p1y;floa << 
661       float p2x = a_p2x;float p2y = a_p2y;floa << 
662       float p3x = a_p3x;float p3y = a_p3y;floa << 
663                                                << 
664       m_this.m_vp_mtx.mul_3f(p1x,p1y,p1z);     << 
665       m_this.m_vp_mtx.mul_3f(p2x,p2y,p2z);     << 
666       m_this.m_vp_mtx.mul_3f(p3x,p3y,p3z);     << 
667                                                << 
668      {plane<vec3f> pn(                         << 
669         vec3f(p1x,p1y,p1z),                    << 
670         vec3f(p2x,p2y,p2z),                    << 
671         vec3f(p3x,p3y,p3z)                     << 
672       );                                       << 
673       if(!pn.is_valid()) return true;          << 
674       float C = pn.normal()[2];                << 
675       if(m_this.m_CULL_FACE){                  << 
676         if(m_this.m_ccw) {                     << 
677           if(C<=0) return true;                << 
678         } else {                               << 
679           if(C>=0) return true;                << 
680         }                                      << 
681       }}                                       << 
682                                                << 
683       tools_GL2PSvertex vertices[3];           << 
684                                                << 
685       if(m_this.m_light_on) {  // same logic a << 
686                                                << 
687         float nx = (a_n1x+a_n2x+a_n3x)/3.0f;   << 
688         float ny = (a_n1y+a_n2y+a_n3y)/3.0f;   << 
689         float nz = (a_n1z+a_n2z+a_n3z)/3.0f;   << 
690                                                << 
691         m_this.m_normal_matrix.mul_dir_3f(nx,n << 
692         vec3f _normal(nx,ny,nz);_normal.normal << 
693                                                << 
694         float _dot = _normal.dot(m_this.m_ligh << 
695                                                << 
696         float _r = (a_r1+a_r2+a_r3)/3.0f;      << 
697         float _g = (a_g1+a_g2+a_g3)/3.0f;      << 
698         float _b = (a_b1+a_b2+a_b3)/3.0f;      << 
699         float _a = (a_a1+a_a2+a_a3)/3.0f;      << 
700         colorf a_color(_r,_g,_b,_a);           << 
701                                                << 
702         colorf frag_color = a_color;           << 
703                                                << 
704         if(_dot<0.0) {                         << 
705           _dot *= -1.0;                        << 
706                                                << 
707           colorf _tmp = m_this.m_light_color;  << 
708           _tmp *= _dot;                        << 
709           _tmp += m_this.m_light_ambient;      << 
710                                                << 
711           frag_color *= _tmp;                  << 
712                                                << 
713         } else {                               << 
714           frag_color *= m_this.m_light_ambient << 
715   }                                            << 
716                                                << 
717         frag_color.clamp();                    << 
718         frag_color.set_a(a_color.a());         << 
719                                                << 
720         float r = frag_color.r();              << 
721         float g = frag_color.g();              << 
722         float b = frag_color.b();              << 
723         float a = frag_color.a();              << 
724                                                << 
725         m_this.set_vtx(vertices,0, p1x,p1y,p1z << 
726         m_this.set_vtx(vertices,1, p2x,p2y,p2z << 
727         m_this.set_vtx(vertices,2, p3x,p3y,p3z << 
728                                                << 
729       } else {                                 << 
730         m_this.set_vtx(vertices,0, p1x,p1y,p1z << 
731         m_this.set_vtx(vertices,1, p2x,p2y,p2z << 
732         m_this.set_vtx(vertices,2, p3x,p3y,p3z << 
733                                                << 
734       }                                        << 
735                                                << 
736       tools_GLint offset = 0;                  << 
737       tools_GLfloat ofactor = 0;               << 
738       tools_GLfloat ounits = 0;                << 
739       tools_GLushort pattern = 0;              << 
740       tools_GLint factor = 0;                  << 
741       tools_GLfloat lwidth = m_this.m_line_wid << 
742       tools_GLint linecap = 0;                 << 
743       tools_GLint linejoin = 0;                << 
744       char boundary = 0;                       << 
745                                                << 
746       ::tools_gl2psAddPolyPrimitive(m_this.m_g << 
747                                                << 
748       return true;                             << 
749     }                                          << 
750   protected:                                      613   protected:
751     gl2ps_action& m_this;                         614     gl2ps_action& m_this;
752   };                                              615   };
753                                                   616 
754 protected:                                        617 protected:
755   gl2ps_manager& m_mgr;                           618   gl2ps_manager& m_mgr;
756   tools_GL2PScontext* m_gl2ps_context;         << 
757                                                << 
758   FILE* m_FILE;                                   619   FILE* m_FILE;
759   float m_back[3];                                620   float m_back[3];
760   mat4f m_vp_mtx;                                 621   mat4f m_vp_mtx;
761   primvis m_pv;                                   622   primvis m_pv;
762                                                   623 
763   colorf m_light_color;                           624   colorf m_light_color;
764   colorf m_light_ambient;                      << 
765   vec3f m_light_direction;                        625   vec3f m_light_direction;
766   vec3f m_normal;                                 626   vec3f m_normal;
767                                                   627 
768   // to be restored in restore_state() :          628   // to be restored in restore_state() :
769   mat4f m_proj;                                   629   mat4f m_proj;
770   mat4f m_model;                                  630   mat4f m_model;
771   mat4f m_normal_matrix;                          631   mat4f m_normal_matrix;
772   colorf m_color;                                 632   colorf m_color;
773   bool m_ccw;                                     633   bool m_ccw;
774   bool m_POLYGON_OFFSET_FILL;                     634   bool m_POLYGON_OFFSET_FILL;
775   bool m_CULL_FACE;                               635   bool m_CULL_FACE;
776   bool m_POINT_SMOOTH;                            636   bool m_POINT_SMOOTH;
777   bool m_LINE_SMOOTH;                             637   bool m_LINE_SMOOTH;
778   float m_point_size;                             638   float m_point_size;
779   float m_line_width;                             639   float m_line_width;
780   bool m_light_on;                                640   bool m_light_on;
781   bool m_DEPTH_TEST;                              641   bool m_DEPTH_TEST;
782 };                                                642 };
783                                                   643 
784 inline bool gl2ps_s2format(const std::string&  << 644 inline bool s2format(const std::string& a_format,int& a_gl2ps_format) {
785   if(a_format=="gl2ps_eps") {a_gl2ps_format =     645   if(a_format=="gl2ps_eps") {a_gl2ps_format = TOOLS_GL2PS_EPS;return true;}
786   if(a_format=="gl2ps_ps")  {a_gl2ps_format =  << 646   if(a_format=="gl2ps_ps")  {a_gl2ps_format = TOOLS_GL2PS_PS;return true;}
787   if(a_format=="gl2ps_pdf") {a_gl2ps_format =     647   if(a_format=="gl2ps_pdf") {a_gl2ps_format = TOOLS_GL2PS_PDF;return true;}
788   if(a_format=="gl2ps_svg") {a_gl2ps_format =     648   if(a_format=="gl2ps_svg") {a_gl2ps_format = TOOLS_GL2PS_SVG;return true;}
789   if(a_format=="gl2ps_tex") {a_gl2ps_format =     649   if(a_format=="gl2ps_tex") {a_gl2ps_format = TOOLS_GL2PS_TEX;return true;}
790   if(a_format=="gl2ps_pgf") {a_gl2ps_format =     650   if(a_format=="gl2ps_pgf") {a_gl2ps_format = TOOLS_GL2PS_PGF;return true;}
791   a_gl2ps_format = TOOLS_GL2PS_PS;                651   a_gl2ps_format = TOOLS_GL2PS_PS;
792   return false;                                   652   return false;
793 }                                                 653 }
794                                                   654 
795 inline bool gl2ps_s2sort(const std::string& a_ << 
796   if(a_sort=="NO_SORT")     {a_gl2ps_sort = TO << 
797   if(a_sort=="SIMPLE_SORT") {a_gl2ps_sort = TO << 
798   if(a_sort=="BSP_SORT")    {a_gl2ps_sort = TO << 
799   a_gl2ps_sort = TOOLS_GL2PS_NO_SORT;          << 
800   return false;                                << 
801 }                                              << 
802                                                << 
803 }}                                                655 }}
804                                                << 
805 #include "../words"                            << 
806 #include "../forit"                            << 
807 #include "../touplow"                          << 
808 #include "../sout"                             << 
809                                                << 
810 namespace tools {                              << 
811 namespace sg {                                 << 
812                                                << 
813 inline bool gl2ps_s2options(const std::string& << 
814   std::vector<std::string> opts;               << 
815   words(a_opts,"|",false,opts);                << 
816   a_gl2ps_opts = 0;                            << 
817   tools_vforit(std::string,opts,it) {          << 
818     touppercase(*it);                          << 
819     const std::string& item = *it;             << 
820          if(item=="NONE")                 a_gl << 
821     else if(item=="DRAW_BACKGROUND")      a_gl << 
822     else if(item=="SIMPLE_LINE_OFFSET")   a_gl << 
823     else if(item=="SILENT")               a_gl << 
824     else if(item=="BEST_ROOT")            a_gl << 
825     else if(item=="OCCLUSION_CULL")       a_gl << 
826     else if(item=="NO_TEXT")              a_gl << 
827     else if(item=="LANDSCAPE")            a_gl << 
828     else if(item=="NO_PS3_SHADING")       a_gl << 
829     else if(item=="NO_PIXMAP")            a_gl << 
830     else if(item=="USE_CURRENT_VIEWPORT") a_gl << 
831     else if(item=="COMPRESS")             a_gl << 
832     else if(item=="NO_BLENDING")          a_gl << 
833     else if(item=="TIGHT_BOUNDING_BOX")   a_gl << 
834     else if(item=="NO_OPENGL_CONTEXT")    a_gl << 
835     else if(item=="NO_TEX_FONTSIZE")      a_gl << 
836     else if(item=="PORTABLE_SORT")        a_gl << 
837     else                                  {a_g << 
838   }                                            << 
839   return true;                                 << 
840 }                                              << 
841                                                << 
842 }}                                             << 
843                                                << 
844                                                   656 
845 #endif                                            657 #endif