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
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/misc/sg_path.hxx>
38 #include <Main/globals.hxx>
39 #include <Main/fg_props.hxx>
40 #include <Main/viewmgr.hxx>
41 #include <Time/light.hxx>
51 // The number of polygon-offset "units" to place between layers. In
52 // principle, one is supposed to be enough. In practice, I find that
53 // my hardware/driver requires many more.
57 ////////////////////////////////////////////////////////////////////////
59 ////////////////////////////////////////////////////////////////////////
63 * Calculate the aspect adjustment for the panel.
66 get_aspect_adjust (int xsize, int ysize)
68 float ideal_aspect = float(WIN_W) / float(WIN_H);
69 float real_aspect = float(xsize) / float(ysize);
70 return (real_aspect / ideal_aspect);
75 ////////////////////////////////////////////////////////////////////////
77 ////////////////////////////////////////////////////////////////////////
82 if(globals->get_current_panel() == 0)
84 if(globals->get_current_panel()->getVisibility() == 0)
86 if(globals->get_viewmgr()->get_current() != 0)
88 if(globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS != 0)
95 ////////////////////////////////////////////////////////////////////////
96 // Implementation of FGTextureManager.
97 ////////////////////////////////////////////////////////////////////////
99 map<string,ssgTexture *> FGTextureManager::_textureMap;
102 FGTextureManager::createTexture (const string &relativePath)
104 ssgTexture * texture = _textureMap[relativePath];
106 SG_LOG( SG_COCKPIT, SG_DEBUG,
107 "Texture " << relativePath << " does not yet exist" );
108 SGPath tpath(globals->get_fg_root());
109 tpath.append(relativePath);
110 texture = new ssgTexture((char *)tpath.c_str(), false, false);
111 _textureMap[relativePath] = texture;
112 if (_textureMap[relativePath] == 0)
113 SG_LOG( SG_COCKPIT, SG_ALERT, "Texture *still* doesn't exist" );
114 SG_LOG( SG_COCKPIT, SG_DEBUG, "Created texture " << relativePath
115 << " handle=" << texture->getHandle() );
124 ////////////////////////////////////////////////////////////////////////
125 // Implementation of FGCropped Texture.
126 ////////////////////////////////////////////////////////////////////////
129 FGCroppedTexture::FGCroppedTexture ()
130 : _path(""), _texture(0),
131 _minX(0.0), _minY(0.0), _maxX(1.0), _maxY(1.0)
136 FGCroppedTexture::FGCroppedTexture (const string &path,
137 float minX, float minY,
138 float maxX, float maxY)
139 : _path(path), _texture(0),
140 _minX(minX), _minY(minY), _maxX(maxX), _maxY(maxY)
145 FGCroppedTexture::~FGCroppedTexture ()
151 FGCroppedTexture::getTexture ()
154 _texture = FGTextureManager::createTexture(_path);
161 ////////////////////////////////////////////////////////////////////////
162 // Implementation of FGPanel.
163 ////////////////////////////////////////////////////////////////////////
165 static fntRenderer text_renderer;
166 static fntTexFont *default_font = 0;
167 static fntTexFont *led_font = 0;
175 _width(WIN_W), _height(int(WIN_H * 0.5768 + 1)),
176 _view_height(int(WIN_H * 0.4232)),
177 _visibility(fgGetNode("/sim/panel/visibility", true)),
178 _x_offset(fgGetNode("/sim/panel/x-offset", true)),
179 _y_offset(fgGetNode("/sim/panel/y-offset", true)),
180 _jitter(fgGetNode("/sim/panel/jitter", true)),
181 _flipx(fgGetNode("/sim/panel/flip-x", true)),
182 _xsize_node(fgGetNode("/sim/startup/xsize", true)),
183 _ysize_node(fgGetNode("/sim/startup/ysize", true))
193 for (instrument_list_type::iterator it = _instruments.begin();
194 it != _instruments.end();
203 * Add an instrument to the panel.
206 FGPanel::addInstrument (FGPanelInstrument * instrument)
208 _instruments.push_back(instrument);
213 * Initialize the panel.
219 char* envp = ::getenv( "FG_FONTS" );
220 if ( envp != NULL ) {
221 base_path.set( envp );
223 base_path.set( globals->get_fg_root() );
224 base_path.append( "Fonts" );
229 // Install the default font
231 fntpath.append( "typewriter.txf" );
232 default_font = new fntTexFont ;
233 default_font -> load ( (char *)fntpath.c_str() ) ;
235 // Install the LED font
237 fntpath.append( "led.txf" );
238 led_font = new fntTexFont ;
239 led_font -> load ( (char *)fntpath.c_str() ) ;
244 * Bind panel properties.
249 fgSetArchivable("/sim/panel/visibility");
250 fgSetArchivable("/sim/panel/x-offset");
251 fgSetArchivable("/sim/panel/y-offset");
252 fgSetArchivable("/sim/panel/jitter");
257 * Unbind panel properties.
269 FGPanel::update (double dt)
271 // Do nothing if the panel isn't visible.
272 if ( !fgPanelVisible() ) {
278 // Now, draw the panel
279 float aspect_adjust = get_aspect_adjust(_xsize_node->getIntValue(),
280 _ysize_node->getIntValue());
281 if (aspect_adjust <1.0)
282 update(WIN_X, int(WIN_W * aspect_adjust), WIN_Y, WIN_H);
284 update(WIN_X, WIN_W, WIN_Y, int(WIN_H / aspect_adjust));
288 * Handle repeatable mouse events. Called from update() and from
289 * fgUpdate3DPanels(). This functionality needs to move into the
290 * input subsystem. Counting a tick every two frames is clumsy...
292 void FGPanel::updateMouseDelay()
296 if (_mouseDelay < 0) {
297 _mouseInstrument->doMouseAction(_mouseButton, 0, _mouseX, _mouseY);
305 FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
307 // Calculate accelerations
308 // and jiggle the panel accordingly
309 // The factors and bounds are just
310 // initial guesses; using sqrt smooths
312 double x_offset = _x_offset->getIntValue();
313 double y_offset = _y_offset->getIntValue();
316 if (_jitter->getFloatValue() != 0.0) {
317 double a_x_pilot = current_aircraft.fdm_state->get_A_X_pilot();
318 double a_y_pilot = current_aircraft.fdm_state->get_A_Y_pilot();
319 double a_z_pilot = current_aircraft.fdm_state->get_A_Z_pilot();
321 double a_zx_pilot = a_z_pilot - a_x_pilot;
323 int x_adjust = int(sqrt(fabs(a_y_pilot) * _jitter->getFloatValue())) *
324 (a_y_pilot < 0 ? -1 : 1);
325 int y_adjust = int(sqrt(fabs(a_zx_pilot) * _jitter->getFloatValue())) *
326 (a_zx_pilot < 0 ? -1 : 1);
328 // adjustments in screen coordinates
329 x_offset += x_adjust;
330 y_offset += y_adjust;
334 glMatrixMode(GL_PROJECTION);
337 if ( _flipx->getBoolValue() ) {
338 gluOrtho2D(winx + winw, winx, winy + winh, winy); /* up side down */
340 gluOrtho2D(winx, winx + winw, winy, winy + winh); /* right side up */
343 glMatrixMode(GL_MODELVIEW);
347 glTranslated(x_offset, y_offset, 0);
351 glMatrixMode(GL_PROJECTION);
353 glMatrixMode(GL_MODELVIEW);
356 ssgForceBasicState();
357 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
363 // In 3D mode, it's possible that we are being drawn exactly on top
364 // of an existing polygon. Use an offset to prevent z-fighting. In
365 // 2D mode, this is a no-op.
366 glEnable(GL_POLYGON_OFFSET_FILL);
367 glPolygonOffset(-1, -POFF_UNITS);
370 glPushAttrib( GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT
371 | GL_TEXTURE_BIT | GL_PIXEL_MODE_BIT | GL_CULL_FACE
372 | GL_DEPTH_BUFFER_BIT );
374 // Draw the background
375 glEnable(GL_TEXTURE_2D);
376 glDisable(GL_LIGHTING);
378 glEnable(GL_ALPHA_TEST);
379 glEnable(GL_COLOR_MATERIAL);
380 glEnable(GL_CULL_FACE);
382 glDisable(GL_DEPTH_TEST);
385 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
386 sgCopyVec4( panel_color, l->scene_diffuse());
387 if ( fgGetDouble("/systems/electrical/outputs/instrument-lights") > 1.0 ) {
388 if ( panel_color[0] < 0.7 ) panel_color[0] = 0.7;
389 if ( panel_color[1] < 0.2 ) panel_color[1] = 0.2;
390 if ( panel_color[2] < 0.2 ) panel_color[2] = 0.2;
392 glColor4fv( panel_color );
394 glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
395 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
396 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
397 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
399 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X, WIN_Y);
400 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + _width, WIN_Y);
401 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + _width, WIN_Y + _height);
402 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X, WIN_Y + _height);
405 for (int i = 0; i < 4; i ++) {
406 // top row of textures...(1,3,5,7)
407 glBindTexture(GL_TEXTURE_2D, _mbg[i*2]->getHandle());
408 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
410 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
411 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
412 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + _height);
413 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + _height);
415 // bottom row of textures...(2,4,6,8)
416 glBindTexture(GL_TEXTURE_2D, _mbg[(i*2)+1]->getHandle());
417 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
419 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y);
420 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y);
421 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
422 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
427 // Draw the instruments.
428 instrument_list_type::const_iterator current = _instruments.begin();
429 instrument_list_type::const_iterator end = _instruments.end();
431 for ( ; current != end; current++) {
432 FGPanelInstrument * instr = *current;
434 glTranslated(instr->getXPos(), instr->getYPos(), 0);
439 // Draw yellow "hotspots" if directed to. This is a panel authoring
440 // feature; not intended to be high performance or to look good.
441 if ( fgGetBool("/sim/panel-hotspots") ) {
442 glDisable(GL_TEXTURE_2D);
445 for ( unsigned int i = 0; i < _instruments.size(); i++ )
446 _instruments[i]->drawHotspots();
450 // restore some original state
452 glPolygonOffset(0, 0);
453 glDisable(GL_POLYGON_OFFSET_FILL);
457 * Set the panel's visibility.
460 FGPanel::setVisibility (bool visibility)
462 _visibility->setBoolValue( visibility );
467 * Return true if the panel is visible.
470 FGPanel::getVisibility () const
472 return _visibility->getBoolValue();
477 * Set the panel's background texture.
480 FGPanel::setBackground (ssgTexture * texture)
486 * Set the panel's multiple background textures.
489 FGPanel::setMultiBackground (ssgTexture * texture, int idx)
496 * Set the panel's x-offset.
499 FGPanel::setXOffset (int offset)
501 if (offset <= 0 && offset >= -_width + WIN_W)
502 _x_offset->setIntValue( offset );
507 * Set the panel's y-offset.
510 FGPanel::setYOffset (int offset)
512 if (offset <= 0 && offset >= -_height)
513 _y_offset->setIntValue( offset );
517 * Handle a mouse action in panel-local (not screen) coordinates.
518 * Used by the 3D panel code in Model/panelnode.cxx, in situations
519 * where the panel doesn't control its own screen location.
522 FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
524 // Note a released button and return
526 if (_mouseInstrument != 0)
527 _mouseInstrument->doMouseAction(_mouseButton, 1, _mouseX, _mouseY);
529 _mouseInstrument = 0;
533 // Search for a matching instrument.
534 for (int i = 0; i < (int)_instruments.size(); i++) {
535 FGPanelInstrument *inst = _instruments[i];
536 int ix = inst->getXPos();
537 int iy = inst->getYPos();
538 int iw = inst->getWidth() / 2;
539 int ih = inst->getHeight() / 2;
540 if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
543 _mouseInstrument = inst;
544 _mouseButton = button;
547 // Always do the action once.
548 return _mouseInstrument->doMouseAction(_mouseButton, 0,
556 * Perform a mouse action.
559 FGPanel::doMouseAction (int button, int updown, int x, int y)
561 // FIXME: this same code appears in update()
562 int xsize = _xsize_node->getIntValue();
563 int ysize = _ysize_node->getIntValue();
564 float aspect_adjust = get_aspect_adjust(xsize, ysize);
566 // Scale for the real window size.
567 if (aspect_adjust < 1.0) {
568 x = int(((float)x / xsize) * WIN_W * aspect_adjust);
569 y = int(WIN_H - ((float(y) / ysize) * WIN_H));
571 x = int(((float)x / xsize) * WIN_W);
572 y = int((WIN_H - ((float(y) / ysize) * WIN_H)) / aspect_adjust);
575 // Adjust for offsets.
576 x -= _x_offset->getIntValue();
577 y -= _y_offset->getIntValue();
579 // Having fixed up the coordinates, fall through to the local
580 // coordinate handler.
581 return doLocalMouseAction(button, updown, x, y);
586 ////////////////////////////////////////////////////////////////////////.
587 // Implementation of FGPanelAction.
588 ////////////////////////////////////////////////////////////////////////
590 FGPanelAction::FGPanelAction ()
594 FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h,
596 : _button(button), _x(x), _y(y), _w(w), _h(h), _repeatable(repeatable)
598 for (unsigned int i = 0; i < 2; i++) {
599 for (unsigned int j = 0; j < _bindings[i].size(); j++)
600 delete _bindings[i][j];
604 FGPanelAction::~FGPanelAction ()
609 FGPanelAction::addBinding (FGBinding * binding, int updown)
611 _bindings[updown].push_back(binding);
615 FGPanelAction::doAction (int updown)
618 if ((updown != _last_state) || (updown == 0 && _repeatable)) {
619 int nBindings = _bindings[updown].size();
620 for (int i = 0; i < nBindings; i++)
621 _bindings[updown][i]->fire();
623 _last_state = updown;
632 ////////////////////////////////////////////////////////////////////////
633 // Implementation of FGPanelTransformation.
634 ////////////////////////////////////////////////////////////////////////
636 FGPanelTransformation::FGPanelTransformation ()
641 FGPanelTransformation::~FGPanelTransformation ()
648 ////////////////////////////////////////////////////////////////////////
649 // Implementation of FGPanelInstrument.
650 ////////////////////////////////////////////////////////////////////////
653 FGPanelInstrument::FGPanelInstrument ()
659 FGPanelInstrument::FGPanelInstrument (int x, int y, int w, int h)
665 FGPanelInstrument::~FGPanelInstrument ()
667 for (action_list_type::iterator it = _actions.begin();
668 it != _actions.end();
676 FGPanelInstrument::drawHotspots()
678 for ( unsigned int i = 0; i < _actions.size(); i++ ) {
679 FGPanelAction* a = _actions[i];
680 float x1 = getXPos() + a->getX();
681 float x2 = x1 + a->getWidth();
682 float y1 = getYPos() + a->getY();
683 float y2 = y1 + a->getHeight();
685 glBegin(GL_LINE_LOOP);
695 FGPanelInstrument::setPosition (int x, int y)
702 FGPanelInstrument::setSize (int w, int h)
709 FGPanelInstrument::getXPos () const
715 FGPanelInstrument::getYPos () const
721 FGPanelInstrument::getWidth () const
727 FGPanelInstrument::getHeight () const
733 FGPanelInstrument::addAction (FGPanelAction * action)
735 _actions.push_back(action);
738 // Coordinates relative to centre.
740 FGPanelInstrument::doMouseAction (int button, int updown, int x, int y)
743 action_list_type::iterator it = _actions.begin();
744 action_list_type::iterator last = _actions.end();
745 for ( ; it != last; it++) {
746 if ((*it)->inArea(button, x, y) &&
747 (*it)->doAction(updown))
756 ////////////////////////////////////////////////////////////////////////
757 // Implementation of FGLayeredInstrument.
758 ////////////////////////////////////////////////////////////////////////
760 FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
761 : FGPanelInstrument(x, y, w, h)
765 FGLayeredInstrument::~FGLayeredInstrument ()
767 for (layer_list::iterator it = _layers.begin(); it != _layers.end(); it++) {
774 FGLayeredInstrument::draw ()
779 for (int i = 0; i < (int)_layers.size(); i++) {
787 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
789 int n = _layers.size();
790 if (layer->getWidth() == -1) {
791 layer->setWidth(getWidth());
793 if (layer->getHeight() == -1) {
794 layer->setHeight(getHeight());
796 _layers.push_back(layer);
801 FGLayeredInstrument::addLayer (FGCroppedTexture &texture,
804 return addLayer(new FGTexturedLayer(texture, w, h));
808 FGLayeredInstrument::addTransformation (FGPanelTransformation * transformation)
810 int layer = _layers.size() - 1;
811 _layers[layer]->addTransformation(transformation);
816 ////////////////////////////////////////////////////////////////////////
817 // Implementation of FGInstrumentLayer.
818 ////////////////////////////////////////////////////////////////////////
820 FGInstrumentLayer::FGInstrumentLayer (int w, int h)
826 FGInstrumentLayer::~FGInstrumentLayer ()
828 for (transformation_list::iterator it = _transformations.begin();
829 it != _transformations.end();
837 FGInstrumentLayer::transform () const
839 transformation_list::const_iterator it = _transformations.begin();
840 transformation_list::const_iterator last = _transformations.end();
842 FGPanelTransformation *t = *it;
844 float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
847 val = fmod(val, t->mod);
850 } else if (val > t->max) {
855 val = val * t->factor + t->offset;
857 val = t->table->interpolate(val) * t->factor + t->offset;
861 case FGPanelTransformation::XSHIFT:
862 glTranslatef(val, 0.0, 0.0);
864 case FGPanelTransformation::YSHIFT:
865 glTranslatef(0.0, val, 0.0);
867 case FGPanelTransformation::ROTATION:
868 glRotatef(-val, 0.0, 0.0, 1.0);
877 FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
879 _transformations.push_back(transformation);
884 ////////////////////////////////////////////////////////////////////////
885 // Implementation of FGGroupLayer.
886 ////////////////////////////////////////////////////////////////////////
888 FGGroupLayer::FGGroupLayer ()
892 FGGroupLayer::~FGGroupLayer ()
894 for (unsigned int i = 0; i < _layers.size(); i++)
899 FGGroupLayer::draw ()
903 int nLayers = _layers.size();
904 for (int i = 0; i < nLayers; i++)
910 FGGroupLayer::addLayer (FGInstrumentLayer * layer)
912 _layers.push_back(layer);
917 ////////////////////////////////////////////////////////////////////////
918 // Implementation of FGTexturedLayer.
919 ////////////////////////////////////////////////////////////////////////
922 FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
923 : FGInstrumentLayer(w, h)
929 FGTexturedLayer::~FGTexturedLayer ()
935 FGTexturedLayer::draw ()
942 glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
945 // From Curt: turn on the panel
946 // lights after sundown.
949 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
950 sgCopyVec4( panel_color, l->scene_diffuse());
951 if ( fgGetDouble("/systems/electrical/outputs/instrument-lights") > 1.0 ) {
952 if ( panel_color[0] < 0.7 ) panel_color[0] = 0.7;
953 if ( panel_color[1] < 0.2 ) panel_color[1] = 0.2;
954 if ( panel_color[2] < 0.2 ) panel_color[2] = 0.2;
956 glColor4fv( panel_color );
958 glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
959 glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
960 glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
961 glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
968 ////////////////////////////////////////////////////////////////////////
969 // Implementation of FGTextLayer.
970 ////////////////////////////////////////////////////////////////////////
972 FGTextLayer::FGTextLayer (int w, int h)
973 : FGInstrumentLayer(w, h), _pointSize(14.0), _font_name("default")
976 _color[0] = _color[1] = _color[2] = 0.0;
980 FGTextLayer::~FGTextLayer ()
982 chunk_list::iterator it = _chunks.begin();
983 chunk_list::iterator last = _chunks.end();
984 for ( ; it != last; it++) {
995 if ( _font_name == "led" && led_font != 0) {
996 text_renderer.setFont(led_font);
998 text_renderer.setFont(guiFntHandle);
1000 text_renderer.setPointSize(_pointSize);
1001 text_renderer.begin();
1002 text_renderer.start3f(0, 0, 0);
1005 long diff = _now - _then;
1007 if (diff > 100000 || diff < 0 ) {
1008 // ( diff < 0 ) is a sanity check and indicates our time stamp
1009 // difference math probably overflowed. We can handle a max
1010 // difference of 35.8 minutes since the returned value is in
1011 // usec. So if the panel is left off longer than that we can
1012 // over flow the math with it is turned back on. This (diff <
1013 // 0) catches that situation, get's us out of trouble, and
1019 // Something is goofy. The code in this file renders only CCW
1020 // polygons, and I have verified that the font code in plib
1021 // renders only CCW trianbles. Yet they come out backwards.
1022 // Something around here or in plib is either changing the winding
1023 // order or (more likely) pushing a left-handed matrix onto the
1024 // stack. But I can't find it; get out the chainsaw...
1026 text_renderer.puts((char *)(_value.c_str()));
1027 glFrontFace(GL_CCW);
1029 text_renderer.end();
1030 glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
1035 FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
1037 _chunks.push_back(chunk);
1041 FGTextLayer::setColor (float r, float g, float b)
1050 FGTextLayer::setPointSize (float size)
1056 FGTextLayer::setFontName(const string &name)
1063 FGTextLayer::setFont(fntFont * font)
1065 text_renderer.setFont(font);
1070 FGTextLayer::recalc_value () const
1073 chunk_list::const_iterator it = _chunks.begin();
1074 chunk_list::const_iterator last = _chunks.end();
1075 for ( ; it != last; it++) {
1076 _value += (*it)->getValue();
1082 ////////////////////////////////////////////////////////////////////////
1083 // Implementation of FGTextLayer::Chunk.
1084 ////////////////////////////////////////////////////////////////////////
1086 FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
1087 : _type(FGTextLayer::TEXT), _fmt(fmt)
1094 FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
1095 const string &fmt, float mult, float offs)
1096 : _type(type), _fmt(fmt), _mult(mult), _offs(offs)
1099 if (type == TEXT_VALUE)
1108 FGTextLayer::Chunk::getValue () const
1114 sprintf(_buf, _fmt.c_str(), _text.c_str());
1117 sprintf(_buf, _fmt.c_str(), _node->getStringValue());
1120 sprintf(_buf, _fmt.c_str(), _offs + _node->getFloatValue() * _mult);
1131 ////////////////////////////////////////////////////////////////////////
1132 // Implementation of FGSwitchLayer.
1133 ////////////////////////////////////////////////////////////////////////
1135 FGSwitchLayer::FGSwitchLayer ()
1141 FGSwitchLayer::draw ()
1145 int nLayers = _layers.size();
1146 for (int i = 0; i < nLayers; i++) {
1147 if (_layers[i]->test()) {