- copy preset colors from <palette> to /sim/hud/color
- listen to color, alpha, alpha-clamping - fix blend mode
This commit is contained in:
parent
5723bebbcc
commit
782e6b82f0
2 changed files with 80 additions and 53 deletions
|
@ -957,9 +957,10 @@ void drawHUD()
|
||||||
|
|
||||||
if (HUD->isAntialiased()) {
|
if (HUD->isAntialiased()) {
|
||||||
glEnable(GL_LINE_SMOOTH);
|
glEnable(GL_LINE_SMOOTH);
|
||||||
|
glAlphaFunc(GL_GREATER, HUD->alphaClamp());
|
||||||
// glEnable(GL_BLEND);
|
// glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
|
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
|
||||||
glLineWidth(2.0);
|
glLineWidth(2.0);
|
||||||
} else {
|
} else {
|
||||||
glLineWidth(1.0);
|
glLineWidth(1.0);
|
||||||
|
@ -1034,6 +1035,7 @@ void drawHUD()
|
||||||
|
|
||||||
if (HUD->isAntialiased()) {
|
if (HUD->isAntialiased()) {
|
||||||
// glDisable(GL_BLEND);
|
// glDisable(GL_BLEND);
|
||||||
|
glDisable(GL_ALPHA_TEST);
|
||||||
glDisable(GL_LINE_SMOOTH);
|
glDisable(GL_LINE_SMOOTH);
|
||||||
glLineWidth(1.0);
|
glLineWidth(1.0);
|
||||||
}
|
}
|
||||||
|
@ -1044,42 +1046,87 @@ void drawHUD()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void fgTextList::draw()
|
||||||
|
{
|
||||||
|
if (!Font)
|
||||||
|
return;
|
||||||
|
|
||||||
|
vector<fgText>::iterator curString = List.begin();
|
||||||
|
vector<fgText>::iterator lastString = List.end();
|
||||||
|
|
||||||
|
glPushAttrib(GL_COLOR_BUFFER_BIT);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
if (HUD->isAntialiased()) {
|
||||||
|
glEnable(GL_ALPHA_TEST);
|
||||||
|
glAlphaFunc(GL_GREATER, HUD->alphaClamp());
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
} else {
|
||||||
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
}
|
||||||
|
|
||||||
|
Font->begin();
|
||||||
|
for (; curString != lastString; curString++)
|
||||||
|
curString->Draw(Font,curString->digit);
|
||||||
|
Font->end();
|
||||||
|
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
glPopAttrib();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// HUD property listener class
|
// HUD property listener class
|
||||||
//
|
//
|
||||||
HUD_Properties::HUD_Properties() :
|
HUD_Properties::HUD_Properties() :
|
||||||
_r(1.0),
|
_current(fgGetNode("/sim/hud/current-color", true)),
|
||||||
_g(1.0),
|
_visibility(fgGetNode("/sim/hud/visibility", true)),
|
||||||
_b(1.0)
|
_antialiasing(fgGetNode("/sim/hud/color/antialiased", true)),
|
||||||
|
_red(fgGetNode("/sim/hud/color/red", true)),
|
||||||
|
_green(fgGetNode("/sim/hud/color/green", true)),
|
||||||
|
_blue(fgGetNode("/sim/hud/color/blue", true)),
|
||||||
|
_alpha(fgGetNode("/sim/hud/color/alpha", true)),
|
||||||
|
_alpha_clamp(fgGetNode("/sim/hud/color/alpha-clamp", true)),
|
||||||
|
_brightness(fgGetNode("/sim/hud/color/brightness", true))
|
||||||
{
|
{
|
||||||
_colors = fgGetNode("/sim/hud/colors", true)->getChildren("color");
|
|
||||||
_which = fgGetNode("/sim/hud/current-color", true);
|
|
||||||
_brightness = fgGetNode("/sim/hud/brightness", true);
|
|
||||||
_alpha = fgGetNode("/sim/hud/alpha", true);
|
|
||||||
_visibility = fgGetNode("/sim/hud/visibility", true);
|
|
||||||
_antialiasing = fgGetNode("/sim/hud/antialiased", true);
|
|
||||||
|
|
||||||
_which->addChangeListener(this);
|
|
||||||
_brightness->addChangeListener(this);
|
|
||||||
_alpha->addChangeListener(this);
|
|
||||||
_visibility->addChangeListener(this);
|
_visibility->addChangeListener(this);
|
||||||
_antialiasing->addChangeListener(this, true);
|
_antialiasing->addChangeListener(this);
|
||||||
|
_red->addChangeListener(this);
|
||||||
|
_green->addChangeListener(this);
|
||||||
|
_blue->addChangeListener(this);
|
||||||
|
_alpha->addChangeListener(this);
|
||||||
|
_alpha_clamp->addChangeListener(this);
|
||||||
|
_brightness->addChangeListener(this);
|
||||||
|
_current->addChangeListener(this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HUD_Properties::valueChanged(SGPropertyNode *n)
|
void HUD_Properties::valueChanged(SGPropertyNode *node)
|
||||||
{
|
{
|
||||||
|
if (!strcmp(node->getName(), "current-color")) {
|
||||||
|
int i = node->getIntValue();
|
||||||
|
if (i < 0)
|
||||||
|
i = 0;
|
||||||
|
SGPropertyNode *n = fgGetNode("/sim/hud/palette", true);
|
||||||
|
if ((n = n->getChild("color", i, false))) {
|
||||||
|
_red->setFloatValue(n->getFloatValue("red", 1.0));
|
||||||
|
_green->setFloatValue(n->getFloatValue("green", 1.0));
|
||||||
|
_blue->setFloatValue(n->getFloatValue("blue", 1.0));
|
||||||
|
if (n->hasValue("alpha"))
|
||||||
|
_alpha->setFloatValue(n->getFloatValue("alpha", 1.0));
|
||||||
|
if (n->hasValue("alpha-clamp"))
|
||||||
|
_alpha_clamp->setFloatValue(n->getFloatValue("alpha-clamp", 0.01));
|
||||||
|
if (n->hasValue("brightness"))
|
||||||
|
_brightness->setFloatValue(n->getFloatValue("brightness", 0.75));
|
||||||
|
}
|
||||||
|
}
|
||||||
_visible = _visibility->getBoolValue();
|
_visible = _visibility->getBoolValue();
|
||||||
_antialiased = _antialiasing->getBoolValue();
|
_antialiased = _antialiasing->getBoolValue();
|
||||||
float brt = _brightness->getFloatValue();
|
float brt = _brightness->getFloatValue();
|
||||||
int w = _which->getIntValue();
|
_r = clamp(brt * _red->getFloatValue());
|
||||||
if (w >= 0 && w < int(_colors.size())) {
|
_g = clamp(brt * _green->getFloatValue());
|
||||||
_r = clamp(brt * _colors[w]->getFloatValue("red", 1.0));
|
_b = clamp(brt * _blue->getFloatValue());
|
||||||
_g = clamp(brt * _colors[w]->getFloatValue("green", 1.0));
|
_a = clamp(_alpha->getFloatValue());
|
||||||
_b = clamp(brt * _colors[w]->getFloatValue("blue", 1.0));
|
_cl = clamp(_alpha_clamp->getFloatValue());
|
||||||
}
|
|
||||||
_a = _alpha->getFloatValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,6 @@ SG_USING_STD(vector);
|
||||||
SG_USING_NAMESPACE(std);
|
SG_USING_NAMESPACE(std);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// some of Norman's crazy optimizations. :-)
|
// some of Norman's crazy optimizations. :-)
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
@ -385,28 +384,7 @@ public:
|
||||||
void setFont( fntRenderer *Renderer ) { Font = Renderer; }
|
void setFont( fntRenderer *Renderer ) { Font = Renderer; }
|
||||||
void add( const fgText& String ) { List.push_back(String); }
|
void add( const fgText& String ) { List.push_back(String); }
|
||||||
void erase( void ) { List.erase( List.begin(), List.end() ); }
|
void erase( void ) { List.erase( List.begin(), List.end() ); }
|
||||||
|
void draw( void );
|
||||||
void draw( void ) {
|
|
||||||
if( Font == 0 )
|
|
||||||
return;
|
|
||||||
vector < fgText > :: iterator curString = List.begin();
|
|
||||||
vector < fgText > :: iterator lastString = List.end();
|
|
||||||
|
|
||||||
glPushAttrib( GL_COLOR_BUFFER_BIT );
|
|
||||||
glEnable ( GL_ALPHA_TEST ) ;
|
|
||||||
glEnable ( GL_BLEND ) ;
|
|
||||||
glAlphaFunc ( GL_GREATER, 0.1 ) ;
|
|
||||||
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
|
|
||||||
|
|
||||||
Font->begin();
|
|
||||||
for( ; curString != lastString; curString++ ) {
|
|
||||||
curString->Draw(Font,curString->digit); //suma
|
|
||||||
}
|
|
||||||
Font->end();
|
|
||||||
|
|
||||||
glDisable ( GL_TEXTURE_2D ) ;
|
|
||||||
glPopAttrib();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1052,17 +1030,19 @@ public:
|
||||||
void setColor() const;
|
void setColor() const;
|
||||||
bool isVisible() const { return _visible; }
|
bool isVisible() const { return _visible; }
|
||||||
bool isAntialiased() const { return _antialiased; }
|
bool isAntialiased() const { return _antialiased; }
|
||||||
|
float alphaClamp() const { return _cl; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float clamp(float f) { return f < 0.0f ? 0.0f : f > 1.0f ? 1.0f : f; }
|
float clamp(float f) { return f < 0.0f ? 0.0f : f > 1.0f ? 1.0f : f; }
|
||||||
vector<SGPropertyNode_ptr> _colors;
|
SGPropertyNode_ptr _current;
|
||||||
SGPropertyNode_ptr _which;
|
|
||||||
SGPropertyNode_ptr _brightness;
|
|
||||||
SGPropertyNode_ptr _alpha;
|
|
||||||
SGPropertyNode_ptr _visibility;
|
SGPropertyNode_ptr _visibility;
|
||||||
SGPropertyNode_ptr _antialiasing;
|
SGPropertyNode_ptr _antialiasing;
|
||||||
bool _visible, _antialiased;
|
SGPropertyNode_ptr _red, _green, _blue, _alpha;
|
||||||
float _r, _g, _b, _a;
|
SGPropertyNode_ptr _alpha_clamp;
|
||||||
|
SGPropertyNode_ptr _brightness;
|
||||||
|
bool _visible;
|
||||||
|
bool _antialiased;
|
||||||
|
float _r, _g, _b, _a, _cl;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _HUD_H
|
#endif // _HUD_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue