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