1 // panel.cxx - default, 2D single-engine prop instrument panel
3 // Written by David Megginson, started January 2000.
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <stdio.h> // sprintf
32 #include <simgear/compiler.h>
39 #include <simgear/debug/logstream.hxx>
40 #include <simgear/misc/sg_path.hxx>
42 #include <Main/globals.hxx>
43 #include <Main/fg_props.hxx>
44 #include <Main/viewmgr.hxx>
45 #include <Time/light.hxx>
55 // The number of polygon-offset "units" to place between layers. In
56 // principle, one is supposed to be enough. In practice, I find that
57 // my hardware/driver requires many more.
60 ////////////////////////////////////////////////////////////////////////
62 ////////////////////////////////////////////////////////////////////////
66 * Calculate the aspect adjustment for the panel.
69 get_aspect_adjust (int xsize, int ysize)
71 float ideal_aspect = float(WIN_W) / float(WIN_H);
72 float real_aspect = float(xsize) / float(ysize);
73 return (real_aspect / ideal_aspect);
78 ////////////////////////////////////////////////////////////////////////
80 ////////////////////////////////////////////////////////////////////////
85 if(globals->get_current_panel() == 0)
87 if(globals->get_current_panel()->getVisibility() == 0)
89 if(globals->get_viewmgr()->get_current() != 0)
91 if(globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS != 0)
98 ////////////////////////////////////////////////////////////////////////
99 // Implementation of FGTextureManager.
100 ////////////////////////////////////////////////////////////////////////
102 map<string,ssgTexture *> FGTextureManager::_textureMap;
105 FGTextureManager::createTexture (const string &relativePath)
107 ssgTexture * texture = _textureMap[relativePath];
109 SG_LOG( SG_COCKPIT, SG_DEBUG,
110 "Texture " << relativePath << " does not yet exist" );
111 SGPath tpath(globals->get_fg_root());
112 tpath.append(relativePath);
113 texture = new ssgTexture((char *)tpath.c_str(), false, false);
114 _textureMap[relativePath] = texture;
115 if (_textureMap[relativePath] == 0)
116 SG_LOG( SG_COCKPIT, SG_ALERT, "Texture *still* doesn't exist" );
117 SG_LOG( SG_COCKPIT, SG_DEBUG, "Created texture " << relativePath
118 << " handle=" << texture->getHandle() );
127 ////////////////////////////////////////////////////////////////////////
128 // Implementation of FGCropped Texture.
129 ////////////////////////////////////////////////////////////////////////
132 FGCroppedTexture::FGCroppedTexture ()
133 : _path(""), _texture(0),
134 _minX(0.0), _minY(0.0), _maxX(1.0), _maxY(1.0)
139 FGCroppedTexture::FGCroppedTexture (const string &path,
140 float minX, float minY,
141 float maxX, float maxY)
142 : _path(path), _texture(0),
143 _minX(minX), _minY(minY), _maxX(maxX), _maxY(maxY)
148 FGCroppedTexture::~FGCroppedTexture ()
154 FGCroppedTexture::getTexture ()
157 _texture = FGTextureManager::createTexture(_path);
164 ////////////////////////////////////////////////////////////////////////
165 // Implementation of FGPanel.
166 ////////////////////////////////////////////////////////////////////////
168 static fntRenderer text_renderer;
169 static fntTexFont *default_font = 0;
170 static fntTexFont *led_font = 0;
178 _width(WIN_W), _height(int(WIN_H * 0.5768 + 1)),
179 _view_height(int(WIN_H * 0.4232)),
180 _visibility(fgGetNode("/sim/panel/visibility", true)),
181 _x_offset(fgGetNode("/sim/panel/x-offset", true)),
182 _y_offset(fgGetNode("/sim/panel/y-offset", true)),
183 _jitter(fgGetNode("/sim/panel/jitter", true)),
184 _flipx(fgGetNode("/sim/panel/flip-x", true)),
185 _xsize_node(fgGetNode("/sim/startup/xsize", true)),
186 _ysize_node(fgGetNode("/sim/startup/ysize", true))
196 for (instrument_list_type::iterator it = _instruments.begin();
197 it != _instruments.end();
206 * Add an instrument to the panel.
209 FGPanel::addInstrument (FGPanelInstrument * instrument)
211 _instruments.push_back(instrument);
216 * Initialize the panel.
222 char* envp = ::getenv( "FG_FONTS" );
223 if ( envp != NULL ) {
224 base_path.set( envp );
226 base_path.set( globals->get_fg_root() );
227 base_path.append( "Fonts" );
232 // Install the default font
234 fntpath.append( "typewriter.txf" );
235 default_font = new fntTexFont ;
236 default_font -> load ( (char *)fntpath.c_str() ) ;
238 // Install the LED font
240 fntpath.append( "led.txf" );
241 led_font = new fntTexFont ;
242 led_font -> load ( (char *)fntpath.c_str() ) ;
247 * Bind panel properties.
252 fgSetArchivable("/sim/panel/visibility");
253 fgSetArchivable("/sim/panel/x-offset");
254 fgSetArchivable("/sim/panel/y-offset");
255 fgSetArchivable("/sim/panel/jitter");
260 * Unbind panel properties.
272 FGPanel::update (double dt)
274 // Do nothing if the panel isn't visible.
275 if ( !fgPanelVisible() ) {
281 // Now, draw the panel
282 float aspect_adjust = get_aspect_adjust(_xsize_node->getIntValue(),
283 _ysize_node->getIntValue());
284 if (aspect_adjust <1.0)
285 update(WIN_X, int(WIN_W * aspect_adjust), WIN_Y, WIN_H);
287 update(WIN_X, WIN_W, WIN_Y, int(WIN_H / aspect_adjust));
291 * Handle repeatable mouse events. Called from update() and from
292 * fgUpdate3DPanels(). This functionality needs to move into the
293 * input subsystem. Counting a tick every two frames is clumsy...
295 void FGPanel::updateMouseDelay()
299 if (_mouseDelay < 0) {
300 _mouseInstrument->doMouseAction(_mouseButton, 0, _mouseX, _mouseY);
308 FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
310 // Calculate accelerations
311 // and jiggle the panel accordingly
312 // The factors and bounds are just
313 // initial guesses; using sqrt smooths
315 double x_offset = _x_offset->getIntValue();
316 double y_offset = _y_offset->getIntValue();
319 if (_jitter->getFloatValue() != 0.0) {
320 double a_x_pilot = current_aircraft.fdm_state->get_A_X_pilot();
321 double a_y_pilot = current_aircraft.fdm_state->get_A_Y_pilot();
322 double a_z_pilot = current_aircraft.fdm_state->get_A_Z_pilot();
324 double a_zx_pilot = a_z_pilot - a_x_pilot;
326 int x_adjust = int(sqrt(fabs(a_y_pilot) * _jitter->getFloatValue())) *
327 (a_y_pilot < 0 ? -1 : 1);
328 int y_adjust = int(sqrt(fabs(a_zx_pilot) * _jitter->getFloatValue())) *
329 (a_zx_pilot < 0 ? -1 : 1);
331 // adjustments in screen coordinates
332 x_offset += x_adjust;
333 y_offset += y_adjust;
337 glMatrixMode(GL_PROJECTION);
340 if ( _flipx->getBoolValue() ) {
341 gluOrtho2D(winx + winw, winx, winy + winh, winy); /* up side down */
343 gluOrtho2D(winx, winx + winw, winy, winy + winh); /* right side up */
346 glMatrixMode(GL_MODELVIEW);
350 glTranslated(x_offset, y_offset, 0);
354 glMatrixMode(GL_PROJECTION);
356 glMatrixMode(GL_MODELVIEW);
359 ssgForceBasicState();
360 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
366 // In 3D mode, it's possible that we are being drawn exactly on top
367 // of an existing polygon. Use an offset to prevent z-fighting. In
368 // 2D mode, this is a no-op.
369 glEnable(GL_POLYGON_OFFSET_FILL);
370 glPolygonOffset(-1, -POFF_UNITS);
373 glPushAttrib( GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT
374 | GL_TEXTURE_BIT | GL_PIXEL_MODE_BIT | GL_CULL_FACE
375 | GL_DEPTH_BUFFER_BIT );
377 // Draw the background
378 glEnable(GL_TEXTURE_2D);
379 glDisable(GL_LIGHTING);
381 glEnable(GL_ALPHA_TEST);
382 glEnable(GL_COLOR_MATERIAL);
383 glEnable(GL_CULL_FACE);
385 glDisable(GL_DEPTH_TEST);
388 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
389 sgCopyVec4( panel_color, l->scene_diffuse());
390 if ( fgGetDouble("/systems/electrical/outputs/instrument-lights") > 1.0 ) {
391 if ( panel_color[0] < 0.7 ) panel_color[0] = 0.7;
392 if ( panel_color[1] < 0.2 ) panel_color[1] = 0.2;
393 if ( panel_color[2] < 0.2 ) panel_color[2] = 0.2;
395 glColor4fv( panel_color );
397 glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
398 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
399 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
400 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
402 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X, WIN_Y);
403 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + _width, WIN_Y);
404 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + _width, WIN_Y + _height);
405 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X, WIN_Y + _height);
408 for (int i = 0; i < 4; i ++) {
409 // top row of textures...(1,3,5,7)
410 glBindTexture(GL_TEXTURE_2D, _mbg[i*2]->getHandle());
411 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
413 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
414 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
415 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + _height);
416 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + _height);
418 // bottom row of textures...(2,4,6,8)
419 glBindTexture(GL_TEXTURE_2D, _mbg[(i*2)+1]->getHandle());
420 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
422 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y);
423 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y);
424 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
425 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
430 // Draw the instruments.
431 instrument_list_type::const_iterator current = _instruments.begin();
432 instrument_list_type::const_iterator end = _instruments.end();
434 for ( ; current != end; current++) {
435 FGPanelInstrument * instr = *current;
437 glTranslated(instr->getXPos(), instr->getYPos(), 0);
442 // Draw yellow "hotspots" if directed to. This is a panel authoring
443 // feature; not intended to be high performance or to look good.
444 if ( fgGetBool("/sim/panel-hotspots") ) {
445 glDisable(GL_TEXTURE_2D);
448 for ( unsigned int i = 0; i < _instruments.size(); i++ )
449 _instruments[i]->drawHotspots();
453 // restore some original state
455 glPolygonOffset(0, 0);
456 glDisable(GL_POLYGON_OFFSET_FILL);
460 * Set the panel's visibility.
463 FGPanel::setVisibility (bool visibility)
465 _visibility->setBoolValue( visibility );
470 * Return true if the panel is visible.
473 FGPanel::getVisibility () const
475 return _visibility->getBoolValue();
480 * Set the panel's background texture.
483 FGPanel::setBackground (ssgTexture * texture)
489 * Set the panel's multiple background textures.
492 FGPanel::setMultiBackground (ssgTexture * texture, int idx)
499 * Set the panel's x-offset.
502 FGPanel::setXOffset (int offset)
504 if (offset <= 0 && offset >= -_width + WIN_W)
505 _x_offset->setIntValue( offset );
510 * Set the panel's y-offset.
513 FGPanel::setYOffset (int offset)
515 if (offset <= 0 && offset >= -_height)
516 _y_offset->setIntValue( offset );
520 * Handle a mouse action in panel-local (not screen) coordinates.
521 * Used by the 3D panel code in Model/panelnode.cxx, in situations
522 * where the panel doesn't control its own screen location.
525 FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
527 // Note a released button and return
529 if (_mouseInstrument != 0)
530 _mouseInstrument->doMouseAction(_mouseButton, 1, _mouseX, _mouseY);
532 _mouseInstrument = 0;
536 // Search for a matching instrument.
537 for (int i = 0; i < (int)_instruments.size(); i++) {
538 FGPanelInstrument *inst = _instruments[i];
539 int ix = inst->getXPos();
540 int iy = inst->getYPos();
541 int iw = inst->getWidth() / 2;
542 int ih = inst->getHeight() / 2;
543 if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
546 _mouseInstrument = inst;
547 _mouseButton = button;
550 // Always do the action once.
551 return _mouseInstrument->doMouseAction(_mouseButton, 0,
559 * Perform a mouse action.
562 FGPanel::doMouseAction (int button, int updown, int x, int y)
564 // FIXME: this same code appears in update()
565 int xsize = _xsize_node->getIntValue();
566 int ysize = _ysize_node->getIntValue();
567 float aspect_adjust = get_aspect_adjust(xsize, ysize);
569 // Scale for the real window size.
570 if (aspect_adjust < 1.0) {
571 x = int(((float)x / xsize) * WIN_W * aspect_adjust);
572 y = int(WIN_H - ((float(y) / ysize) * WIN_H));
574 x = int(((float)x / xsize) * WIN_W);
575 y = int((WIN_H - ((float(y) / ysize) * WIN_H)) / aspect_adjust);
578 // Adjust for offsets.
579 x -= _x_offset->getIntValue();
580 y -= _y_offset->getIntValue();
582 // Having fixed up the coordinates, fall through to the local
583 // coordinate handler.
584 return doLocalMouseAction(button, updown, x, y);
589 ////////////////////////////////////////////////////////////////////////.
590 // Implementation of FGPanelAction.
591 ////////////////////////////////////////////////////////////////////////
593 FGPanelAction::FGPanelAction ()
597 FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h,
599 : _button(button), _x(x), _y(y), _w(w), _h(h), _repeatable(repeatable)
601 for (unsigned int i = 0; i < 2; i++) {
602 for (unsigned int j = 0; j < _bindings[i].size(); j++)
603 delete _bindings[i][j];
607 FGPanelAction::~FGPanelAction ()
612 FGPanelAction::addBinding (FGBinding * binding, int updown)
614 _bindings[updown].push_back(binding);
618 FGPanelAction::doAction (int updown)
621 if ((updown != _last_state) || (updown == 0 && _repeatable)) {
622 int nBindings = _bindings[updown].size();
623 for (int i = 0; i < nBindings; i++)
624 _bindings[updown][i]->fire();
626 _last_state = updown;
635 ////////////////////////////////////////////////////////////////////////
636 // Implementation of FGPanelTransformation.
637 ////////////////////////////////////////////////////////////////////////
639 FGPanelTransformation::FGPanelTransformation ()
644 FGPanelTransformation::~FGPanelTransformation ()
651 ////////////////////////////////////////////////////////////////////////
652 // Implementation of FGPanelInstrument.
653 ////////////////////////////////////////////////////////////////////////
656 FGPanelInstrument::FGPanelInstrument ()
662 FGPanelInstrument::FGPanelInstrument (int x, int y, int w, int h)
668 FGPanelInstrument::~FGPanelInstrument ()
670 for (action_list_type::iterator it = _actions.begin();
671 it != _actions.end();
679 FGPanelInstrument::drawHotspots()
681 for ( unsigned int i = 0; i < _actions.size(); i++ ) {
682 FGPanelAction* a = _actions[i];
683 float x1 = getXPos() + a->getX();
684 float x2 = x1 + a->getWidth();
685 float y1 = getYPos() + a->getY();
686 float y2 = y1 + a->getHeight();
688 glBegin(GL_LINE_LOOP);
698 FGPanelInstrument::setPosition (int x, int y)
705 FGPanelInstrument::setSize (int w, int h)
712 FGPanelInstrument::getXPos () const
718 FGPanelInstrument::getYPos () const
724 FGPanelInstrument::getWidth () const
730 FGPanelInstrument::getHeight () const
736 FGPanelInstrument::addAction (FGPanelAction * action)
738 _actions.push_back(action);
741 // Coordinates relative to centre.
743 FGPanelInstrument::doMouseAction (int button, int updown, int x, int y)
746 action_list_type::iterator it = _actions.begin();
747 action_list_type::iterator last = _actions.end();
748 for ( ; it != last; it++) {
749 if ((*it)->inArea(button, x, y) &&
750 (*it)->doAction(updown))
759 ////////////////////////////////////////////////////////////////////////
760 // Implementation of FGLayeredInstrument.
761 ////////////////////////////////////////////////////////////////////////
763 FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
764 : FGPanelInstrument(x, y, w, h)
768 FGLayeredInstrument::~FGLayeredInstrument ()
770 for (layer_list::iterator it = _layers.begin(); it != _layers.end(); it++) {
777 FGLayeredInstrument::draw ()
782 for (int i = 0; i < (int)_layers.size(); i++) {
790 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
792 int n = _layers.size();
793 if (layer->getWidth() == -1) {
794 layer->setWidth(getWidth());
796 if (layer->getHeight() == -1) {
797 layer->setHeight(getHeight());
799 _layers.push_back(layer);
804 FGLayeredInstrument::addLayer (FGCroppedTexture &texture,
807 return addLayer(new FGTexturedLayer(texture, w, h));
811 FGLayeredInstrument::addTransformation (FGPanelTransformation * transformation)
813 int layer = _layers.size() - 1;
814 _layers[layer]->addTransformation(transformation);
819 ////////////////////////////////////////////////////////////////////////
820 // Implementation of FGInstrumentLayer.
821 ////////////////////////////////////////////////////////////////////////
823 FGInstrumentLayer::FGInstrumentLayer (int w, int h)
829 FGInstrumentLayer::~FGInstrumentLayer ()
831 for (transformation_list::iterator it = _transformations.begin();
832 it != _transformations.end();
840 FGInstrumentLayer::transform () const
842 transformation_list::const_iterator it = _transformations.begin();
843 transformation_list::const_iterator last = _transformations.end();
845 FGPanelTransformation *t = *it;
847 float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
850 val = fmod(val, t->mod);
853 } else if (val > t->max) {
858 val = val * t->factor + t->offset;
860 val = t->table->interpolate(val) * t->factor + t->offset;
864 case FGPanelTransformation::XSHIFT:
865 glTranslatef(val, 0.0, 0.0);
867 case FGPanelTransformation::YSHIFT:
868 glTranslatef(0.0, val, 0.0);
870 case FGPanelTransformation::ROTATION:
871 glRotatef(-val, 0.0, 0.0, 1.0);
880 FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
882 _transformations.push_back(transformation);
887 ////////////////////////////////////////////////////////////////////////
888 // Implementation of FGGroupLayer.
889 ////////////////////////////////////////////////////////////////////////
891 FGGroupLayer::FGGroupLayer ()
895 FGGroupLayer::~FGGroupLayer ()
897 for (unsigned int i = 0; i < _layers.size(); i++)
902 FGGroupLayer::draw ()
906 int nLayers = _layers.size();
907 for (int i = 0; i < nLayers; i++)
913 FGGroupLayer::addLayer (FGInstrumentLayer * layer)
915 _layers.push_back(layer);
920 ////////////////////////////////////////////////////////////////////////
921 // Implementation of FGTexturedLayer.
922 ////////////////////////////////////////////////////////////////////////
925 FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
926 : FGInstrumentLayer(w, h)
932 FGTexturedLayer::~FGTexturedLayer ()
938 FGTexturedLayer::draw ()
945 glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
948 // From Curt: turn on the panel
949 // lights after sundown.
952 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
953 sgCopyVec4( panel_color, l->scene_diffuse());
954 if ( fgGetDouble("/systems/electrical/outputs/instrument-lights") > 1.0 ) {
955 if ( panel_color[0] < 0.7 ) panel_color[0] = 0.7;
956 if ( panel_color[1] < 0.2 ) panel_color[1] = 0.2;
957 if ( panel_color[2] < 0.2 ) panel_color[2] = 0.2;
959 glColor4fv( panel_color );
961 glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
962 glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
963 glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
964 glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
971 ////////////////////////////////////////////////////////////////////////
972 // Implementation of FGTextLayer.
973 ////////////////////////////////////////////////////////////////////////
975 FGTextLayer::FGTextLayer (int w, int h)
976 : FGInstrumentLayer(w, h), _pointSize(14.0), _font_name("default")
979 _color[0] = _color[1] = _color[2] = 0.0;
983 FGTextLayer::~FGTextLayer ()
985 chunk_list::iterator it = _chunks.begin();
986 chunk_list::iterator last = _chunks.end();
987 for ( ; it != last; it++) {
998 if ( _font_name == "led" && led_font != 0) {
999 text_renderer.setFont(led_font);
1001 text_renderer.setFont(guiFntHandle);
1003 text_renderer.setPointSize(_pointSize);
1004 text_renderer.begin();
1005 text_renderer.start3f(0, 0, 0);
1008 long diff = _now - _then;
1010 if (diff > 100000 || diff < 0 ) {
1011 // ( diff < 0 ) is a sanity check and indicates our time stamp
1012 // difference math probably overflowed. We can handle a max
1013 // difference of 35.8 minutes since the returned value is in
1014 // usec. So if the panel is left off longer than that we can
1015 // over flow the math with it is turned back on. This (diff <
1016 // 0) catches that situation, get's us out of trouble, and
1022 // Something is goofy. The code in this file renders only CCW
1023 // polygons, and I have verified that the font code in plib
1024 // renders only CCW trianbles. Yet they come out backwards.
1025 // Something around here or in plib is either changing the winding
1026 // order or (more likely) pushing a left-handed matrix onto the
1027 // stack. But I can't find it; get out the chainsaw...
1029 text_renderer.puts((char *)(_value.c_str()));
1030 glFrontFace(GL_CCW);
1032 text_renderer.end();
1033 glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
1038 FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
1040 _chunks.push_back(chunk);
1044 FGTextLayer::setColor (float r, float g, float b)
1053 FGTextLayer::setPointSize (float size)
1059 FGTextLayer::setFontName(const string &name)
1066 FGTextLayer::setFont(fntFont * font)
1068 text_renderer.setFont(font);
1073 FGTextLayer::recalc_value () const
1076 chunk_list::const_iterator it = _chunks.begin();
1077 chunk_list::const_iterator last = _chunks.end();
1078 for ( ; it != last; it++) {
1079 _value += (*it)->getValue();
1085 ////////////////////////////////////////////////////////////////////////
1086 // Implementation of FGTextLayer::Chunk.
1087 ////////////////////////////////////////////////////////////////////////
1089 FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
1090 : _type(FGTextLayer::TEXT), _fmt(fmt)
1097 FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
1098 const string &fmt, float mult, float offs,
1100 : _type(type), _fmt(fmt), _mult(mult), _offs(offs), _trunc(truncation)
1103 if (type == TEXT_VALUE)
1112 FGTextLayer::Chunk::getValue () const
1118 sprintf(_buf, _fmt.c_str(), _text.c_str());
1121 sprintf(_buf, _fmt.c_str(), _node->getStringValue());
1124 double d = _offs + _node->getFloatValue() * _mult;
1125 if (_trunc) d = (d < 0) ? -floor(-d) : floor(d);
1126 sprintf(_buf, _fmt.c_str(), d);
1137 ////////////////////////////////////////////////////////////////////////
1138 // Implementation of FGSwitchLayer.
1139 ////////////////////////////////////////////////////////////////////////
1141 FGSwitchLayer::FGSwitchLayer ()
1147 FGSwitchLayer::draw ()
1151 int nLayers = _layers.size();
1152 for (int i = 0; i < nLayers; i++) {
1153 if (_layers[i]->test()) {