1
0
Fork 0

Tiled panel background support from Jim Wilson.

This commit is contained in:
david 2002-02-19 21:57:09 +00:00
parent 254de7695d
commit d13b46b8f1
3 changed files with 115 additions and 52 deletions

View file

@ -164,8 +164,7 @@ FGCroppedTexture::getTexture ()
FGPanel * current_panel = NULL;
static fntRenderer text_renderer;
static fntTexFont *default_font;
static fntTexFont *led_font;
/**
* Constructor.
@ -216,28 +215,7 @@ FGPanel::addInstrument (FGPanelInstrument * instrument)
void
FGPanel::init ()
{
SGPath base_path;
char* envp = ::getenv( "FG_FONTS" );
if ( envp != NULL ) {
base_path.set( envp );
} else {
base_path.set( globals->get_fg_root() );
base_path.append( "Fonts" );
}
SGPath fntpath;
// Install the default font
fntpath = base_path;
fntpath.append( "typewriter.txf" );
default_font = new fntTexFont ;
default_font -> load ( (char *)fntpath.c_str() ) ;
// Install the LED font
fntpath = base_path;
fntpath.append( "led.txf" );
led_font = new fntTexFont ;
led_font -> load ( (char *)fntpath.c_str() ) ;
// NO-OP
}
@ -354,16 +332,40 @@ FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
} else {
glColor4f(0.7, 0.2, 0.2, 1.0);
}
glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X, WIN_Y, 0);
glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + _width, WIN_Y, 0);
glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + _width, WIN_Y + _height, 0);
glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X, WIN_Y + _height, 0);
glEnd();
if (_bg != 0) {
glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X, WIN_Y, 0);
glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + _width, WIN_Y, 0);
glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + _width, WIN_Y + _height, 0);
glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X, WIN_Y + _height, 0);
glEnd();
} else {
for (int i = 0; i < 4; i ++) {
// top row of textures...(1,3,5,7)
glBindTexture(GL_TEXTURE_2D, _mbg[i*2]->getHandle());
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + (_height/2), 0);
glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2), 0);
glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + _height, 0);
glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + _height, 0);
glEnd();
// bottom row of textures...(2,4,6,8)
glBindTexture(GL_TEXTURE_2D, _mbg[(i*2)+1]->getHandle());
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y, 0);
glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y, 0);
glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2), 0);
glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + (_height/2), 0);
glEnd();
}
}
// Draw the instruments.
instrument_list_type::const_iterator current = _instruments.begin();
@ -415,6 +417,15 @@ FGPanel::setBackground (ssgTexture * texture)
_bg = texture;
}
/**
* Set the panel's multiple background textures.
*/
void
FGPanel::setMultiBackground (ssgTexture * texture, int idx)
{
_bg = 0;
_mbg[idx] = texture;
}
/**
* Set the panel's x-offset.
@ -846,7 +857,7 @@ FGTexturedLayer::draw ()
////////////////////////////////////////////////////////////////////////
FGTextLayer::FGTextLayer (int w, int h)
: FGInstrumentLayer(w, h), _pointSize(14.0), _font_name("default")
: FGInstrumentLayer(w, h), _pointSize(14.0)
{
_then.stamp();
_color[0] = _color[1] = _color[2] = 0.0;
@ -869,11 +880,7 @@ FGTextLayer::draw ()
glPushMatrix();
glColor4fv(_color);
transform();
if ( _font_name == "led" ) {
text_renderer.setFont(led_font);
} else {
text_renderer.setFont(guiFntHandle);
}
text_renderer.setFont(guiFntHandle);
text_renderer.setPointSize(_pointSize);
text_renderer.begin();
text_renderer.start3f(0, 0, 0);
@ -912,13 +919,6 @@ FGTextLayer::setPointSize (float size)
_pointSize = size;
}
void
FGTextLayer::setFontName(const string &name)
{
_font_name = name;
}
void
FGTextLayer::setFont(fntFont * font)
{
@ -1019,3 +1019,5 @@ FGSwitchLayer::draw ()
// end of panel.cxx

View file

@ -150,6 +150,9 @@ public:
// Background texture.
virtual void setBackground (ssgTexture * texture);
// Background multiple textures.
virtual void setMultiBackground (ssgTexture * texture, int idx);
// Make the panel visible or invisible.
virtual bool getVisibility () const;
virtual void setVisibility (bool visibility);
@ -196,6 +199,7 @@ private:
const SGPropertyNode * _ysize_node;
ssgTexture * _bg;
ssgTexture * _mbg[8];
// List of instruments in panel.
instrument_list_type _instruments;
};
@ -498,7 +502,6 @@ public:
virtual void addChunk (Chunk * chunk);
virtual void setColor (float r, float g, float b);
virtual void setPointSize (float size);
virtual void setFontName ( const string &name );
virtual void setFont (fntFont * font);
private:
@ -510,7 +513,7 @@ private:
float _color[4];
float _pointSize;
mutable string _font_name;
mutable string _value;
mutable SGTimeStamp _then;
mutable SGTimeStamp _now;
@ -566,3 +569,4 @@ extern FGPanel * current_panel; // TODO: move to globals
// end of panel.hxx

View file

@ -508,8 +508,7 @@ readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
tlayer->setPointSize(pointSize);
// Set the font.
string fontName = node->getStringValue("font", "default");
tlayer->setFontName(fontName);
// TODO
const SGPropertyNode * chunk_group = node->getNode("chunks");
if (chunk_group != 0) {
@ -706,7 +705,9 @@ readPanel (const SGPropertyNode * root)
if (!fgHasNode("/sim/panel/x-offset"))
fgSetInt("/sim/panel/x-offset", root->getIntValue("x-offset", 0));
if (!fgHasNode("/sim/panel/y-offset"))
// conditional removed by jim wilson to allow panel xml code
// with y-offset defined to work...
// if (!fgHasNode("/sim/panel/y-offset"))
fgSetInt("/sim/panel/y-offset", root->getIntValue("y-offset", 0));
//
@ -718,6 +719,59 @@ readPanel (const SGPropertyNode * root)
panel->setBackground(FGTextureManager::createTexture(bgTexture.c_str()));
SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << bgTexture );
//
// Get multibackground if any...
//
string mbgTexture = root->getStringValue("multibackground[0]");
if (mbgTexture != "") {
panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 0);
SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
mbgTexture = root->getStringValue("multibackground[1]");
if (mbgTexture == "")
mbgTexture = "FOO";
panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 1);
SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
mbgTexture = root->getStringValue("multibackground[2]");
if (mbgTexture == "")
mbgTexture = "FOO";
panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 2);
SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
mbgTexture = root->getStringValue("multibackground[3]");
if (mbgTexture == "")
mbgTexture = "FOO";
panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 3);
SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
mbgTexture = root->getStringValue("multibackground[4]");
if (mbgTexture == "")
mbgTexture = "FOO";
panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 4);
SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
mbgTexture = root->getStringValue("multibackground[5]");
if (mbgTexture == "")
mbgTexture = "FOO";
panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 5);
SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
mbgTexture = root->getStringValue("multibackground[6]");
if (mbgTexture == "")
mbgTexture = "FOO";
panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 6);
SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
mbgTexture = root->getStringValue("multibackground[7]");
if (mbgTexture == "")
mbgTexture = "FOO";
panel->setMultiBackground(FGTextureManager::createTexture(mbgTexture.c_str()), 7);
SG_LOG( SG_COCKPIT, SG_INFO, "Set background texture to " << mbgTexture );
}
//
// Create each instrument.
@ -798,3 +852,6 @@ fgReadPanel (const string &relative_path)
// end of panel_io.cxx