]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD.cxx
Merge branch 'next' into durk-atc
[flightgear.git] / src / Instrumentation / HUD / HUD.cxx
1 // HUD.cxx -- Head Up Display
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  [micheleamerica#geocities:com]
6 // Copyright (C) 2006  Melchior FRANZ  [mfranz#aon:at]
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #include <simgear/compiler.h>
23 #include <simgear/structure/exception.hxx>
24
25 #include <string>
26 #include <fstream>
27
28 #ifdef HAVE_CONFIG_H
29 #  include <config.h>
30 #endif
31
32 #include <simgear/constants.h>
33 #include <simgear/misc/sg_path.hxx>
34 #include <simgear/props/props_io.hxx>
35 #include <osg/GLU>
36
37 #include <Main/globals.hxx>
38 #include <Main/viewmgr.hxx>
39 #include <Main/viewer.hxx>
40
41 #include "HUD.hxx"
42
43
44 static float clamp(float f)
45 {
46     return f < 0.0f ? 0.0f : f > 1.0f ? 1.0f : f;
47 }
48
49
50 HUD::HUD() :
51     _path(fgGetNode("/sim/hud/path[1]", "Huds/default.xml")),
52     _current(fgGetNode("/sim/hud/current-color", true)),
53     _visibility(fgGetNode("/sim/hud/visibility[1]", true)),
54     _3DenabledN(fgGetNode("/sim/hud/enable3d[1]", true)),
55     _antialiasing(fgGetNode("/sim/hud/color/antialiased", true)),
56     _transparency(fgGetNode("/sim/hud/color/transparent", true)),
57     _red(fgGetNode("/sim/hud/color/red", true)),
58     _green(fgGetNode("/sim/hud/color/green", true)),
59     _blue(fgGetNode("/sim/hud/color/blue", true)),
60     _alpha(fgGetNode("/sim/hud/color/alpha", true)),
61     _alpha_clamp(fgGetNode("/sim/hud/color/alpha-clamp", true)),
62     _brightness(fgGetNode("/sim/hud/color/brightness", true)),
63     _visible(false),
64     _antialiased(false),
65     _transparent(false),
66     _a(0.67),                                                                   // FIXME better names
67     _cl(0.01),
68     //
69     _scr_widthN(fgGetNode("/sim/startup/xsize", true)),
70     _scr_heightN(fgGetNode("/sim/startup/ysize", true)),
71     _unitsN(fgGetNode("/sim/startup/units", true)),
72     _timer(0.0),
73     //
74     _font_renderer(new fntRenderer()),
75     _font(0),
76     _font_size(0.0),
77     _style(0),
78     _listener_active(false),
79     _clip_box(0)
80 {
81     SG_LOG(SG_COCKPIT, SG_INFO, "Initializing HUD Instrument");
82
83     _path->addChangeListener(this);
84     _visibility->addChangeListener(this);
85     _3DenabledN->addChangeListener(this);
86     _antialiasing->addChangeListener(this);
87     _transparency->addChangeListener(this);
88     _red->addChangeListener(this);
89     _green->addChangeListener(this);
90     _blue->addChangeListener(this);
91     _alpha->addChangeListener(this);
92     _alpha_clamp->addChangeListener(this);
93     _brightness->addChangeListener(this);
94     _current->addChangeListener(this);
95     _scr_widthN->addChangeListener(this);
96     _scr_heightN->addChangeListener(this);
97     _unitsN->addChangeListener(this, true);
98 }
99
100
101 HUD::~HUD()
102 {
103     _path->removeChangeListener(this);
104     _visibility->removeChangeListener(this);
105     _3DenabledN->removeChangeListener(this);
106     _antialiasing->removeChangeListener(this);
107     _transparency->removeChangeListener(this);
108     _red->removeChangeListener(this);
109     _green->removeChangeListener(this);
110     _blue->removeChangeListener(this);
111     _alpha->removeChangeListener(this);
112     _alpha_clamp->removeChangeListener(this);
113     _brightness->removeChangeListener(this);
114     _current->removeChangeListener(this);
115     _scr_widthN->removeChangeListener(this);
116     _scr_heightN->removeChangeListener(this);
117     _unitsN->removeChangeListener(this);
118     delete _font_renderer;
119     
120     deinit();
121 }
122
123
124 void HUD::init()
125 {
126     const char* fontName = 0;
127     _font_cache = globals->get_fontcache();
128     if (!_font) {
129         fontName = fgGetString("/sim/hud/font/name", "Helvetica.txf");
130         _font = _font_cache->getTexFont(fontName);
131     }
132     if (!_font)
133         throw sg_io_exception("/sim/hud/font/name is not a texture font",
134                               sg_location(fontName));
135
136     _font_size = fgGetFloat("/sim/hud/font/size", 8);
137     _font_renderer->setFont(_font);
138     _font_renderer->setPointSize(_font_size);
139     _text_list.setFont(_font_renderer);
140
141     currentColorChanged();
142     
143     _path->fireValueChanged();
144 }
145
146 void HUD::deinit()
147 {
148   deque<Item *>::const_iterator it, end = _items.end();
149     for (it = _items.begin(); it != end; ++it)
150         delete *it;
151     end = _ladders.end();
152     for (it = _ladders.begin(); it != end; ++it)
153         delete *it;
154         
155   _items.clear();
156   _ladders.clear();
157   
158   delete _clip_box;
159   _clip_box = NULL;
160 }
161
162 void HUD::reinit()
163 {
164     deinit();
165     _path->fireValueChanged();
166 }
167
168 void HUD::update(double dt)
169 {
170     _timer += dt;
171 }
172
173
174 void HUD::draw(osg::State&)
175 {
176     if (!isVisible())
177         return;
178
179     if (!_items.size() && !_ladders.size())
180         return;
181
182     if (is3D()) {
183         draw3D();
184         return;
185     }
186
187     const float normal_aspect = 640.0f / 480.0f;
188     // note: aspect_ratio is Y/X
189     float current_aspect = 1.0f / globals->get_current_view()->get_aspect_ratio();
190     if (current_aspect > normal_aspect) {
191         float aspect_adjust = current_aspect / normal_aspect;
192         float adjust = 320.0f * aspect_adjust - 320.0f;
193         draw2D(-adjust, 0.0f, 640.0f + adjust, 480.0f);
194
195     } else {
196         float aspect_adjust = normal_aspect / current_aspect;
197         float adjust = 240.0f * aspect_adjust - 240.0f;
198         draw2D(0.0f, -adjust, 640.0f, 480.0f + adjust);
199     }
200
201     glViewport(0, 0, _scr_width, _scr_height);
202 }
203
204
205 void HUD::draw3D()
206 {
207     using namespace osg;
208     FGViewer* view = globals->get_current_view();
209
210     // Standard fgfs projection, with essentially meaningless clip
211     // planes (we'll map the whole HUD plane to z=-1)
212     glMatrixMode(GL_PROJECTION);
213     glPushMatrix();
214     Matrixf proj
215         = Matrixf::perspective(view->get_v_fov(), 1/view->get_aspect_ratio(),
216                                0.1, 10);
217     glLoadMatrix(proj.ptr());
218
219     glMatrixMode(GL_MODELVIEW);
220     glPushMatrix();
221
222     // Standard fgfs view direction computation
223     Vec3f lookat;
224     lookat[0] = -sin(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
225     lookat[1] = tan(SG_DEGREES_TO_RADIANS * view->getPitchOffset_deg());
226     lookat[2] = -cos(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
227     if (fabs(lookat[1]) > 9999)
228         lookat[1] = 9999; // FPU sanity
229     Matrixf mv = Matrixf::lookAt(Vec3f(0.0, 0.0, 0.0), lookat,
230                                  Vec3f(0.0, 1.0, 0.0));
231     glLoadMatrix(mv.ptr());
232
233     // Map the -1:1 square to a 55.0x41.25 degree wide patch at z=1.
234     // This is the default fgfs field of view, which the HUD files are
235     // written to assume.
236     float dx = 0.52056705; // tan(55/2)
237     float dy = dx * 0.75;  // assumes 4:3 aspect ratio
238     float m[16];
239     m[0] = dx, m[4] =  0, m[ 8] = 0, m[12] = 0;
240     m[1] =  0, m[5] = dy, m[ 9] = 0, m[13] = 0;
241     m[2] =  0, m[6] =  0, m[10] = 1, m[14] = 0;
242     m[3] =  0, m[7] =  0, m[11] = 0, m[15] = 1;
243     glMultMatrixf(m);
244
245     // Convert the 640x480 "HUD standard" coordinate space to a square
246     // about the origin in the range [-1:1] at depth of -1
247     glScalef(1.0 / 320, 1.0 / 240, 1);
248     glTranslatef(-320, -240, -1);
249
250     common_draw();
251
252     glMatrixMode(GL_PROJECTION);
253     glPopMatrix();
254     glMatrixMode(GL_MODELVIEW);
255     glPopMatrix();
256 }
257
258
259 void HUD::draw2D(GLfloat x_start, GLfloat y_start, GLfloat x_end, GLfloat y_end)
260 {
261     using namespace osg;
262     glMatrixMode(GL_PROJECTION);
263     glPushMatrix();
264     Matrixf proj = Matrixf::ortho2D(x_start, x_end, y_start, y_end);
265     glLoadMatrix(proj.ptr());
266
267     glMatrixMode(GL_MODELVIEW);
268     glPushMatrix();
269     glLoadIdentity();
270
271     common_draw();
272
273     glMatrixMode(GL_PROJECTION);
274     glPopMatrix();
275     glMatrixMode(GL_MODELVIEW);
276     glPopMatrix();
277 }
278
279
280 void HUD::common_draw()
281 {
282     _text_list.erase();
283     _line_list.erase();
284     _stipple_line_list.erase();
285
286     glDisable(GL_DEPTH_TEST);
287     glDisable(GL_LIGHTING);
288
289     glEnable(GL_BLEND);
290     if (isTransparent())
291         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
292     else
293         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
294
295     if (isAntialiased()) {
296         glEnable(GL_LINE_SMOOTH);
297         glAlphaFunc(GL_GREATER, alphaClamp());
298         glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
299         //glLineWidth(1.5);
300     } else {
301         //glLineWidth(1.0);
302     }
303
304     setColor();
305     _clip_box->set();
306
307     deque<Item *>::const_iterator it, end = _items.end();
308     for (it = _items.begin(); it != end; ++it)
309         if ((*it)->isEnabled())
310             (*it)->draw();
311
312     _text_list.draw();
313     _line_list.draw();
314
315     if (_stipple_line_list.size()) {
316         glEnable(GL_LINE_STIPPLE);
317         glLineStipple(1, 0x00FF);
318         _stipple_line_list.draw();
319         glDisable(GL_LINE_STIPPLE);
320     }
321
322     // ladders last, as they can have their own clip planes
323     end = _ladders.end();
324     for (it = _ladders.begin(); it != end; ++it)
325         if ((*it)->isEnabled())
326             (*it)->draw();
327
328     _clip_box->unset();
329
330     if (isAntialiased()) {
331         glDisable(GL_ALPHA_TEST);
332         glDisable(GL_LINE_SMOOTH);
333         //glLineWidth(1.0);
334     }
335
336     if (isTransparent())
337         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
338
339     glEnable(GL_DEPTH_TEST);
340     glEnable(GL_LIGHTING);
341 }
342
343
344 int HUD::load(const char *file, float x, float y, int level, const string& indent)
345 {
346     const sgDebugPriority TREE = SG_INFO;
347     const int MAXNEST = 10;
348
349     SGPath path(globals->resolve_maybe_aircraft_path(file));
350     if (path.isNull())
351     {
352         SG_LOG(SG_INPUT, SG_ALERT, "HUD: Cannot find configuration file '" << file << "'.");
353         return 0x2;
354     }
355
356     if (!level) {
357         SG_LOG(SG_INPUT, TREE, endl << "load " << file);
358         _items.erase(_items.begin(), _items.end());
359         _ladders.erase(_ladders.begin(), _ladders.end());
360     } else if (level > MAXNEST) {
361         SG_LOG(SG_INPUT, SG_ALERT, "HUD: files nested more than " << MAXNEST << " levels");
362         return 0x1;
363     } else if (!file || !file[0]) {
364         SG_LOG(SG_INPUT, SG_ALERT, "HUD: invalid filename ");
365         return 0x2;
366     }
367
368     int ret = 0;
369     ifstream input(path.c_str());
370     if (!input.good()) {
371         SG_LOG(SG_INPUT, SG_ALERT, "HUD: Cannot read configuration from '" << path.c_str() << "'");
372         return 0x4;
373     }
374
375     SGPropertyNode root;
376     try {
377         readProperties(input, &root);
378     } catch (const sg_exception &e) {
379         input.close();
380         guiErrorMessage("HUD: Error ", e);
381         return 0x8;
382     }
383
384     delete _clip_box;
385     _clip_box = new ClipBox(fgGetNode("/sim/hud/clipping"), x, y);
386
387     for (int i = 0; i < root.nChildren(); i++) {
388         SGPropertyNode *n = root.getChild(i);
389         const char *d = n->getStringValue("name", 0);
390         string desc;
391         if (d)
392             desc = string(": \"") + d + '"';
393
394         const char *name = n->getName();
395         if (!strcmp(name, "name")) {
396             continue;
397
398         } else if (!strcmp(name, "enable3d")) {
399             // set in the tree so that valueChanged() picks it up
400             _3DenabledN->setBoolValue(n->getBoolValue());
401             continue;
402
403         } else if (!strcmp(name, "import")) {
404             const char *fn = n->getStringValue("path", "");
405             float xoffs = n->getFloatValue("x-offset", 0.0f);
406             float yoffs = n->getFloatValue("y-offset", 0.0f);
407
408             SG_LOG(SG_INPUT, TREE, indent << "|__import " << fn << desc);
409
410             string ind = indent + string(i + 1 < root.nChildren() ? "|    " : "     ");
411             ret |= load(fn, x + xoffs, y + yoffs, level + 1, ind);
412             continue;
413         }
414
415         SG_LOG(SG_INPUT, TREE, indent << "|__" << name << desc);
416
417         Item *item;
418         if (!strcmp(name, "label")) {
419             item = static_cast<Item *>(new Label(this, n, x, y));
420         } else if (!strcmp(name, "gauge")) {
421             item = static_cast<Item *>(new Gauge(this, n, x, y));
422         } else if (!strcmp(name, "tape")) {
423             item = static_cast<Item *>(new Tape(this, n, x, y));
424         } else if (!strcmp(name, "dial")) {
425             item = static_cast<Item *>(new Dial(this, n, x, y));
426         } else if (!strcmp(name, "turn-bank-indicator")) {
427             item = static_cast<Item *>(new TurnBankIndicator(this, n, x, y));
428         } else if (!strcmp(name, "ladder")) {
429             item = static_cast<Item *>(new Ladder(this, n, x, y));
430             _ladders.insert(_ladders.begin(), item);
431             continue;
432         } else if (!strcmp(name, "runway")) {
433             item = static_cast<Item *>(new Runway(this, n, x, y));
434         } else if (!strcmp(name, "aiming-reticle")) {
435             item = static_cast<Item *>(new AimingReticle(this, n, x, y));
436         } else {
437             SG_LOG(SG_INPUT, TREE, indent << "      \\...unsupported!");
438             continue;
439         }
440         _items.insert(_items.begin(), item);
441     }
442     input.close();
443     SG_LOG(SG_INPUT, TREE, indent);
444     return ret;
445 }
446
447
448 void HUD::valueChanged(SGPropertyNode *node)
449 {
450     if (_listener_active)
451         return;
452     _listener_active = true;
453     if (!strcmp(node->getName(), "path"))
454         load(fgGetString("/sim/hud/path[1]", "Huds/default.xml"));
455
456     if (!strcmp(node->getName(), "current-color")) {
457         currentColorChanged();
458     }
459     
460     _scr_width = _scr_widthN->getIntValue();
461     _scr_height = _scr_heightN->getIntValue();
462
463     _visible = _visibility->getBoolValue();
464     _3Denabled = _3DenabledN->getBoolValue();
465     _transparent = _transparency->getBoolValue();
466     _antialiased = _antialiasing->getBoolValue();
467     float brt = _brightness->getFloatValue();
468     _r = clamp(brt * _red->getFloatValue());
469     _g = clamp(brt * _green->getFloatValue());
470     _b = clamp(brt * _blue->getFloatValue());
471     _a = clamp(_alpha->getFloatValue());
472     _cl = clamp(_alpha_clamp->getFloatValue());
473
474     _units = strcmp(_unitsN->getStringValue(), "feet") ? METER : FEET;
475     _listener_active = false;
476 }
477
478 void HUD::currentColorChanged()
479 {
480   SGPropertyNode *n = fgGetNode("/sim/hud/palette", true);
481   int index = _current->getIntValue();
482   if (index < 0) {
483     index = 0;
484   }
485   
486   n = n->getChild("color", index, false);
487   if (!n) {
488     return;
489   }
490   
491   if (n->hasValue("red"))
492       _red->setFloatValue(n->getFloatValue("red", 1.0));
493   if (n->hasValue("green"))
494       _green->setFloatValue(n->getFloatValue("green", 1.0));
495   if (n->hasValue("blue"))
496       _blue->setFloatValue(n->getFloatValue("blue", 1.0));
497   if (n->hasValue("alpha"))
498       _alpha->setFloatValue(n->getFloatValue("alpha", 0.67));
499   if (n->hasValue("alpha-clamp"))
500       _alpha_clamp->setFloatValue(n->getFloatValue("alpha-clamp", 0.01));
501   if (n->hasValue("brightness"))
502       _brightness->setFloatValue(n->getFloatValue("brightness", 0.75));
503   if (n->hasValue("antialiased"))
504       _antialiasing->setBoolValue(n->getBoolValue("antialiased", false));
505   if (n->hasValue("transparent"))
506       _transparency->setBoolValue(n->getBoolValue("transparent", false));
507 }
508
509 void HUD::setColor() const
510 {
511     if (_antialiased)
512         glColor4f(_r, _g, _b, _a);
513     else
514         glColor3f(_r, _g, _b);
515 }
516
517
518 void HUD::textAlign(fntRenderer *rend, const char *s, int align,
519         float *x, float *y, float *l, float *r, float *b, float *t)
520 {
521     fntFont *font = rend->getFont();
522     float gap = font->getGap();
523     float left, right, bot, top;
524     font->getBBox(s, rend->getPointSize(), rend->getSlant(), &left, &right, &bot, &top);
525
526     if (align & HUD::HCENTER)
527         *x -= left - gap + (right - left - gap) / 2.0;
528     else if (align & HUD::RIGHT)
529         *x -= right;
530     else if (align & HUD::LEFT)
531         *x -= left;
532
533     if (align & HUD::VCENTER)
534         *y -= bot + (top - bot) / 2.0;
535     else if (align & HUD::TOP)
536         *y -= top;
537     else if (align & HUD::BOTTOM)
538         *y -= bot;
539
540     *l = *x + left;
541     *r = *x + right;
542     *b = *y + bot;
543     *t = *y + top;
544 }
545
546
547
548
549 // HUDText -- text container for TextList vector
550
551
552 HUDText::HUDText(fntRenderer *fnt, float x, float y, const char *s, int align, int d) :
553     _fnt(fnt),
554     _x(x),
555     _y(y),
556     _digits(d)
557 {
558     strncpy(_msg, s, BUFSIZE);
559     if (!align || !s[0])
560         return;
561     float ign;
562     HUD::textAlign(fnt, s, align, &_x, &_y, &ign, &ign, &ign, &ign);
563 }
564
565
566 void HUDText::draw()
567 {
568     if (!_digits) { // show all digits in same size
569         _fnt->start2f(_x, _y);
570         _fnt->puts(_msg);
571         return;
572     }
573
574     // FIXME
575     // this code is changed to display Numbers with big/small digits
576     // according to MIL Standards for example Altitude above 10000 ft
577     // is shown as 10ooo.
578
579     int c = 0, i = 0;
580     char *t = _msg;
581     int p = 4;
582
583     if (t[0] == '-') {
584         //if negative value then increase the c and p values
585         //for '-' sign.
586         c++; // was moved to the comment. Unintentionally?   TODO
587         p++;
588     }
589     char *tmp = _msg;
590     while (tmp[i] != '\0') {
591         if ((tmp[i] >= '0') && (tmp[i] <= '9'))
592             c++;
593         i++;
594     }
595
596     float orig_size = _fnt->getPointSize();
597     if (c > p) {
598         _fnt->setPointSize(orig_size * 0.8);
599         int p1 = c - 3;
600         char *tmp1 = _msg + p1;
601         int p2 = p1 * 8;
602
603         _fnt->start2f(_x + p2, _y);
604         _fnt->puts(tmp1);
605
606         _fnt->setPointSize(orig_size * 1.2);
607         char tmp2[BUFSIZE];
608         strncpy(tmp2, _msg, p1);
609         tmp2[p1] = '\0';
610
611         _fnt->start2f(_x, _y);
612         _fnt->puts(tmp2);
613     } else {
614         _fnt->setPointSize(orig_size * 1.2);
615         _fnt->start2f(_x, _y);
616         _fnt->puts(tmp);
617     }
618     _fnt->setPointSize(orig_size);
619 }
620
621
622 void TextList::align(const char *s, int align, float *x, float *y,
623         float *l, float *r, float *b, float *t) const
624 {
625     HUD::textAlign(_font, s, align, x, y, l, r, b, t);
626 }
627
628
629 void TextList::draw()
630 {
631     assert(_font);
632
633     // FIXME
634     glPushAttrib(GL_COLOR_BUFFER_BIT);
635     glEnable(GL_BLEND);
636
637     _font->begin();
638     vector<HUDText>::iterator it, end = _list.end();
639     for (it = _list.begin(); it != end; ++it)
640         it->draw();
641     _font->end();
642
643     glDisable(GL_TEXTURE_2D);
644     glPopAttrib();
645 }
646
647
648 ClipBox::ClipBox(const SGPropertyNode *n, float xoffset, float yoffset) :
649     _active(false),
650     _xoffs(xoffset),
651     _yoffs(yoffset)
652 {
653     if (!n)
654         return;
655
656     // const_cast is necessary because ATM there's no matching getChild(const ...)
657     // prototype and getNode(const ..., <bool>) is wrongly interpreted as
658     // getNode(const ..., <int>)
659     _top_node = (const_cast<SGPropertyNode *>(n))->getChild("top", 0, true);
660     _bot_node = (const_cast<SGPropertyNode *>(n))->getChild("bottom", 0, true);
661     _left_node = (const_cast<SGPropertyNode *>(n))->getChild("left", 0, true);
662     _right_node = (const_cast<SGPropertyNode *>(n))->getChild("right", 0, true);
663
664     _left[0] = 1.0, _left[1] = _left[2] = 0.0;
665     _right[0] = -1.0, _right[1] = _right[2] = 0.0;
666     _top[0] = 0.0, _top[1] = -1.0, _top[2] = 0.0;
667     _bot[0] = 0.0, _bot[1] = 1.0, _bot[2] = 0.0;
668     _active = true;
669 }
670
671
672 void ClipBox::set()
673 {
674     if (!_active)
675         return;
676
677     _left[3] = -_left_node->getDoubleValue() - _xoffs;
678     _right[3] = _right_node->getDoubleValue() + _xoffs;
679     _bot[3] = -_bot_node->getDoubleValue() - _yoffs;
680     _top[3] = _top_node->getDoubleValue() + _yoffs;
681
682     glClipPlane(GL_CLIP_PLANE0, _top);
683     glEnable(GL_CLIP_PLANE0);
684     glClipPlane(GL_CLIP_PLANE1, _bot);
685     glEnable(GL_CLIP_PLANE1);
686     glClipPlane(GL_CLIP_PLANE2, _left);
687     glEnable(GL_CLIP_PLANE2);
688     glClipPlane(GL_CLIP_PLANE3, _right);
689     glEnable(GL_CLIP_PLANE3);
690 }
691
692
693 void ClipBox::unset()
694 {
695     if (_active) {
696         glDisable(GL_CLIP_PLANE0);
697         glDisable(GL_CLIP_PLANE1);
698         glDisable(GL_CLIP_PLANE2);
699         glDisable(GL_CLIP_PLANE3);
700     }
701 }