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