1
0
Fork 0

Norman Vine contributed code to do anti-aliases HUD lines.

However, this tanks my voodoo2 frame rates so it the code is disabled for now.
This commit is contained in:
curt 2000-05-11 19:17:02 +00:00
parent 109088a84e
commit a74e205930
3 changed files with 285 additions and 302 deletions

View file

@ -78,6 +78,9 @@ fgTextList HUD_TextList;
fgLineList HUD_LineList; fgLineList HUD_LineList;
fgLineList HUD_StippleLineList; fgLineList HUD_StippleLineList;
float hud_trans_alpha = 0.5f;
void fgHUDalphaInit( void );
class locRECT { class locRECT {
public: public:
RECT rect; RECT rect;
@ -654,6 +657,7 @@ int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
// } // }
// while( HIptr ); // while( HIptr );
fgHUDalphaInit();
return 0; // For now. Later we may use this for an error code. return 0; // For now. Later we may use this for an error code.
} }
@ -1021,148 +1025,107 @@ int brightness = pHUDInstr->get_brightness();
pHUDInstr->SetBrightness( brightness ); pHUDInstr->SetBrightness( brightness );
} }
#if 0
// fgUpdateHUD
//
// Performs a once around the list of calls to instruments installed in
// the HUD object with requests for redraw. Kinda. It will when this is
// all C++.
//
void fgUpdateHUD( void ) {
int brightness;
// int day_night_sw = current_aircraft.controls->day_night_switch;
int day_night_sw = global_day_night_switch;
int hud_displays = HUD_deque.size();
instr_item *pHUDInstr;
float line_width;
if( !hud_displays ) { // Trust everyone, but ALWAYS cut the cards! #define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
return;
static puDialogBox *HUDalphaDialog;
static puFrame *HUDalphaFrame;
static puText *HUDalphaDialogMessage;
static puText *HUDalphaTitle;
static puText *HUDalphaText;
static puOneShot *HUDalphaOkButton;
static puSlider *HUDalphaHS0;
static puFont HUDalphaLegendFont;
static puFont HUDalphaLabelFont;
static char SliderText[1][ 8 ];
static void alpha_adj( puObject *hs ) {
float val ;
hs-> getValue ( &val ) ;
fgAP_CLAMP ( val, 0.1, 1.0 ) ;
// printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
hud_trans_alpha = val;
sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
HUDalphaText -> setLabel ( SliderText[ 0 ] ) ;
} }
HUD_TextList.erase(); void fgHUDalphaAdjust( puObject * ) {
HUD_LineList.erase(); FG_PUSH_PUI_DIALOG( HUDalphaDialog );
// HUD_StippleLineList.erase();
pHUDInstr = HUD_deque[0];
brightness = pHUDInstr->get_brightness();
// brightness = HUD_deque.at(0)->get_brightness();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, 640, 0, 480);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glColor3f(1.0, 1.0, 1.0);
glIndexi(7);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
// We can do translucency, so why not. :-)
// glEnable ( GL_BLEND ) ;
// glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
if( day_night_sw == DAY) {
switch (brightness) {
case BRT_LIGHT:
// glColor4f (0.1, 0.9, 0.1, 0.75);
glColor3f (0.1, 0.9, 0.1);
break;
case BRT_MEDIUM:
// glColor4f (0.1, 0.7, 0.0, 0.75);
glColor3f (0.1, 0.7, 0.0);
break;
case BRT_DARK:
// glColor4f (0.0, 0.6, 0.0, 0.75);
glColor3f(0.0, 0.6, 0.0);
break;
case BRT_BLACK:
// glColor4f( 0.0, 0.0, 0.0, 0.75);
glColor3f( 0.0, 0.0, 0.0);
break;
default:;
}
}
else {
if( day_night_sw == NIGHT) {
switch (brightness) {
case BRT_LIGHT:
// glColor4f (0.9, 0.1, 0.1, 0.75);
glColor3f (0.9, 0.1, 0.1);
break;
case BRT_MEDIUM:
// glColor4f (0.7, 0.0, 0.1, 0.75);
glColor3f (0.7, 0.0, 0.1);
break;
case BRT_DARK:
default:
// glColor4f (0.6, 0.0, 0.0, 0.75);
glColor3f (0.6, 0.0, 0.0);
}
}
else { // Just in case default
// glColor4f (0.1, 0.9, 0.1, 0.75);
glColor3f (0.1, 0.9, 0.1);
}
} }
deque < instr_item * > :: iterator current = HUD_deque.begin(); static void goAwayHUDalphaAdjust (puObject *)
deque < instr_item * > :: iterator last = HUD_deque.end(); {
FG_POP_PUI_DIALOG( HUDalphaDialog );
for ( ; current != last; ++current ) {
pHUDInstr = *current;
if( pHUDInstr->enabled()) {
// fgPrintf( FG_COCKPIT, FG_DEBUG, "HUD Code %d Status %d\n",
// hud->code, hud->status );
pHUDInstr->draw();
// HUD_deque.at(i)->draw(); // Responsible for broken or fixed variants.
// No broken displays honored just now.
}
} }
char *gmt_str = get_formated_gmt_time(); // Done once at system initialization
HUD_TextList.add( fgText( 40, 10, gmt_str) ); void fgHUDalphaInit( void ) {
#ifdef FG_NETWORK_OLK // printf("fgAPAdjustInit\n");
if ( net_hud_display ) { #define HORIZONTAL FALSE
net_hud_update();
int DialogX = 40;
int DialogY = 100;
int DialogWidth = 230;
char Label[] = "HUD Alpha Adjust";
char *s;
int labelX = (DialogWidth / 2) -
(puGetStringWidth( puGetDefaultLabelFont(), Label ) / 2);
labelX -= 30; // KLUDGEY
int nSliders = 1;
int slider_x = 10;
int slider_y = 55;
int slider_width = 210;
int slider_title_x = 15;
int slider_value_x = 160;
float slider_delta = 0.05f;
puGetDefaultFonts ( &HUDalphaLegendFont, &HUDalphaLabelFont );
HUDalphaDialog = new puDialogBox ( DialogX, DialogY ); {
int horiz_slider_height = puGetStringHeight (HUDalphaLabelFont) +
puGetStringDescender (HUDalphaLabelFont) +
PUSTR_TGAP + PUSTR_BGAP + 5;
HUDalphaFrame = new puFrame ( 0, 0,
DialogWidth,
85 + nSliders * horiz_slider_height );
HUDalphaDialogMessage = new puText ( labelX,
52 + nSliders
* horiz_slider_height );
HUDalphaDialogMessage -> setDefaultValue ( Label );
HUDalphaDialogMessage -> getDefaultValue ( &s );
HUDalphaDialogMessage -> setLabel ( s );
HUDalphaHS0 = new puSlider ( slider_x, slider_y,
slider_width, HORIZONTAL ) ;
HUDalphaHS0-> setDelta ( slider_delta ) ;
HUDalphaHS0-> setValue ( hud_trans_alpha ) ;
HUDalphaHS0-> setCBMode ( PUSLIDER_DELTA ) ;
HUDalphaHS0-> setCallback ( alpha_adj ) ;
sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
HUDalphaTitle = new puText ( slider_title_x, slider_y ) ;
HUDalphaTitle-> setDefaultValue ( "MaxAlpha" ) ;
HUDalphaTitle-> getDefaultValue ( &s ) ;
HUDalphaTitle-> setLabel ( s ) ;
HUDalphaText = new puText ( slider_value_x, slider_y ) ;
HUDalphaText-> setLabel ( SliderText[ 0 ] ) ;
HUDalphaOkButton = new puOneShot ( 10, 10, 60, 50 );
HUDalphaOkButton-> setLegend ( gui_msg_OK );
HUDalphaOkButton-> makeReturnDefault ( TRUE );
HUDalphaOkButton-> setCallback ( goAwayHUDalphaAdjust );
} }
#endif FG_FINALIZE_PUI_DIALOG( HUDalphaDialog );
HUD_TextList.draw(); #undef HORIZONTAL
line_width = (current_options.get_xsize() > 1000) ? 1.0 : 0.5;
glLineWidth(line_width);
HUD_LineList.draw();
// glEnable(GL_LINE_STIPPLE);
// glLineStipple( 1, 0x00FF );
// HUD_StippleLineList.draw();
// glDisable(GL_LINE_STIPPLE);
// glDisable( GL_BLEND );
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
} }
#endif
// fgUpdateHUD // fgUpdateHUD
// //
@ -1205,57 +1168,59 @@ void fgUpdateHUD( void ) {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
// We can do translucency, so why not. :-) // #define ANTI_ALIAS_HUD
// glEnable ( GL_BLEND ) ; #ifdef ANTI_ALIAS_HUD
// glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; #define HUD_COLOR(r,g,b) glColor4f(r,g,b,hud_trans_alpha)
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
glLineWidth(1.5);
#else
#define HUD_COLOR(r,g,b) glColor3f(r,g,b)
glLineWidth(1.0);
#endif
if( day_night_sw == DAY) { if( day_night_sw == DAY) {
switch (brightness) { switch (brightness) {
case BRT_LIGHT: case BRT_LIGHT:
// glColor4f (0.1, 0.9, 0.1, 0.75); HUD_COLOR (0.1f, 0.9f, 0.1f);
glColor3f (0.1, 0.9, 0.1);
break; break;
case BRT_MEDIUM: case BRT_MEDIUM:
// glColor4f (0.1, 0.7, 0.0, 0.75); HUD_COLOR (0.1f, 0.7f, 0.0f);
glColor3f (0.1, 0.7, 0.0);
break; break;
case BRT_DARK: case BRT_DARK:
// glColor4f (0.0, 0.6, 0.0, 0.75); HUD_COLOR (0.0f, 0.6f, 0.0f);
glColor3f(0.0, 0.6, 0.0);
break; break;
case BRT_BLACK: case BRT_BLACK:
// glColor4f( 0.0, 0.0, 0.0, 0.75); HUD_COLOR( 0.0f, 0.0f, 0.0f);
glColor3f( 0.0, 0.0, 0.0);
break; break;
default:; default:
HUD_COLOR (0.1f, 0.9f, 0.1f);
} }
} }
else { else {
if( day_night_sw == NIGHT) { if( day_night_sw == NIGHT) {
switch (brightness) { switch (brightness) {
case BRT_LIGHT: case BRT_LIGHT:
// glColor4f (0.9, 0.1, 0.1, 0.75); HUD_COLOR (0.9f, 0.1f, 0.1f);
glColor3f (0.9, 0.1, 0.1);
break; break;
case BRT_MEDIUM: case BRT_MEDIUM:
// glColor4f (0.7, 0.0, 0.1, 0.75); HUD_COLOR (0.7f, 0.0f, 0.1f);
glColor3f (0.7, 0.0, 0.1);
break; break;
case BRT_DARK: case BRT_DARK:
default: default:
// glColor4f (0.6, 0.0, 0.0, 0.75); HUD_COLOR (0.6f, 0.0f, 0.0f);
glColor3f (0.6, 0.0, 0.0);
} }
} }
else { // Just in case default else { // Just in case default
// glColor4f (0.1, 0.9, 0.1, 0.75); HUD_COLOR (0.1f, 0.9f, 0.1f);
glColor3f (0.1, 0.9, 0.1);
} }
} }
@ -1319,8 +1284,6 @@ void fgUpdateHUD( void ) {
HUD_TextList.draw(); HUD_TextList.draw();
line_width = (current_options.get_xsize() > 1000) ? 1.0 : 0.5;
glLineWidth(line_width);
HUD_LineList.draw(); HUD_LineList.draw();
// glEnable(GL_LINE_STIPPLE); // glEnable(GL_LINE_STIPPLE);
@ -1328,7 +1291,12 @@ void fgUpdateHUD( void ) {
// HUD_StippleLineList.draw(); // HUD_StippleLineList.draw();
// glDisable(GL_LINE_STIPPLE); // glDisable(GL_LINE_STIPPLE);
// glDisable( GL_BLEND );
#ifdef ANTI_ALIAS_HUD
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
glLineWidth(1.0);
#endif
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);

View file

@ -308,6 +308,21 @@ public:
} }
glEnd(); glEnd();
} }
#if 0
void draw( void ) {
vector < fgLineSeg2D > :: iterator curSeg;
vector < fgLineSeg2D > :: iterator lastSeg;
curSeg = List.begin();
lastSeg = List.end();
glBegin(GL_LINES);
for ( ; curSeg != lastSeg; curSeg++ ) {
curSeg->draw();
}
glEnd();
}
#endif
}; };
class fgTextList { class fgTextList {

View file

@ -20,6 +20,7 @@
#include "hud.hxx" #include "hud.hxx"
#define DO_PANEL_HACK
//====================== Top of HudLadder Class ======================= //====================== Top of HudLadder Class =======================
HudLadder :: HudLadder( int x, HudLadder :: HudLadder( int x,
@ -92,41 +93,43 @@ HudLadder & HudLadder :: operator = ( const HudLadder & rhs )
void HudLadder :: draw( void ) void HudLadder :: draw( void )
{ {
float x_ini;
float x_end;
float y;
POINT centroid = get_centroid(); POINT centroid = get_centroid();
RECT box = get_location();
float half_span = box.right / 2.0;
float roll_value = current_ch2(); float roll_value = current_ch2();
float pitch_value = current_ch1() * RAD_TO_DEG;
vmin = pitch_value - (float)width_units/2.0;
vmax = pitch_value + (float)width_units/2.0;
glPushMatrix(); glPushMatrix();
glTranslatef( centroid.x, centroid.y, 0); glTranslatef( centroid.x, centroid.y, 0);
glScalef( current_options.get_fov()/55.0, 1.0, 1.0 ); // Alex's panel patch
// glScalef( current_options.get_fov()/55.0, 1.0, 1.0 );
glRotatef(roll_value * RAD_TO_DEG, 0.0, 0.0, 1.0); glRotatef(roll_value * RAD_TO_DEG, 0.0, 0.0, 1.0);
// Draw the target spot. // Draw the target spot.
#define CENTER_DIAMOND_SIZE 6.0 #define CENTER_DIAMOND_SIZE 6.0f
glBegin(GL_LINE_LOOP); glBegin(GL_LINE_LOOP);
glVertex2f( -CENTER_DIAMOND_SIZE, 0.0);
glVertex2f(0.0, CENTER_DIAMOND_SIZE);
glVertex2f( CENTER_DIAMOND_SIZE, 0.0); glVertex2f( CENTER_DIAMOND_SIZE, 0.0);
glVertex2f( 0.0, CENTER_DIAMOND_SIZE);
glVertex2f( -CENTER_DIAMOND_SIZE, 0.0);
glVertex2f( 0.0, -CENTER_DIAMOND_SIZE); glVertex2f( 0.0, -CENTER_DIAMOND_SIZE);
glEnd(); glEnd();
#undef CENTER_DIAMOND_SIZE
if(minimal) { if( minimal || ! div_units ) {
glPopMatrix(); glPopMatrix();
return; return;
} }
if( div_units ) { float x_ini;
float x_end;
float y;
float pitch_value = current_ch1() * RAD_TO_DEG;
vmin = pitch_value - (float)width_units * 0.5f;
vmax = pitch_value + (float)width_units * 0.5f;
RECT box = get_location();
float half_span = box.right * 0.5f ;
char TextLadder[8] ; char TextLadder[8] ;
float label_length ; float label_length ;
float label_height ; float label_height ;
@ -150,6 +153,7 @@ void HudLadder :: draw( void )
int i = FloatToInt(vmin); int i = FloatToInt(vmin);
if( !scr_hole ) { if( !scr_hole ) {
x_end = half_span;
for( ; i<last ; i++ ) { for( ; i<last ; i++ ) {
y = (((float)(i - pitch_value) * factor) + .5f); y = (((float)(i - pitch_value) * factor) + .5f);
@ -158,12 +162,12 @@ void HudLadder :: draw( void )
sprintf( TextLadder, "%d", i ); sprintf( TextLadder, "%d", i );
font->getBBox ( TextLadder, pointsize, italic, font->getBBox ( TextLadder, pointsize, italic,
&left, &right, &bot, &top ) ; &left, &right, &bot, &top ) ;
label_length = right - left; label_length = right - left;
label_length += text_offset; label_length += text_offset;
label_height = (top - bot)/2.0f; label_height = (top - bot) * 0.5f;
x_ini = -half_span; x_ini = -half_span;
x_end = half_span;
if( i >= 0 ) { if( i >= 0 ) {
// Make zero point wider on left // Make zero point wider on left
@ -181,10 +185,15 @@ void HudLadder :: draw( void )
Text( x_end+text_offset, y-label_height, TextLadder ); Text( x_end+text_offset, y-label_height, TextLadder );
} }
} }
} } else { // scr_hole != 0
else // if(scr_hole ) // Draw ladder with space in the middle of the lines
{ // Draw ladder with space in the middle of the lines float x_ini2;
float hole = (float)((scr_hole)/2.0f); float x_end2;
float hole = (float)((scr_hole)*0.5f);
x_end = -half_span + hole;
x_ini2 = half_span - hole;
for( ; i<last ; i++ ) { for( ; i<last ; i++ ) {
y = (((float)(i - pitch_value) * factor) + .5); y = (((float)(i - pitch_value) * factor) + .5);
@ -195,58 +204,49 @@ void HudLadder :: draw( void )
&left, &right, &bot, &top ) ; &left, &right, &bot, &top ) ;
label_length = right - left; label_length = right - left;
label_length += text_offset; label_length += text_offset;
label_height = (top - bot)/2.0f; label_height = (top - bot) * 0.5f;
// printf("l %f r %f b %f t %f\n",left, right, bot, top );
// Start by calculating the points and drawing the // Start by calculating the points and drawing the
// left side lines. // left side lines.
x_ini = -half_span; x_ini = -half_span;
x_end = -half_span + hole; x_end2 = half_span;
if( i >= 0 ) { if( i >= 0 ) {
// Make zero point wider on left // Make zero point wider on left
if( i == 0 ) if( i == 0 ) {
x_ini -= zero_offset; x_ini -= zero_offset;
x_end2 += zero_offset;
}
// Zero or above draw solid lines // Zero or above draw solid lines
Line(x_ini, y, x_end, y); Line(x_ini, y, x_end, y);
Line(x_ini2, y, x_end2, y);
} else { } else {
// Below zero draw dashed lines. // Below zero draw dashed lines.
StippleLine(x_ini, y, x_end, y); StippleLine(x_ini, y, x_end, y);
StippleLine(x_ini2, y, x_end2, y);
} }
// Calculate the location of the left side label using
// Now calculate the location of the left side label using
Text( x_ini-label_length, y-label_height, TextLadder ); Text( x_ini-label_length, y-label_height, TextLadder );
// Now calculate and draw the right side line location
x_ini = half_span - hole;
x_end = half_span;
if( i >= 0 ) {
if( i == 0 )
x_end += zero_offset;
// Zero or above draw solid lines
Line(x_ini, y, x_end, y);
} else {
// Below zero draw dashed lines.
StippleLine(x_ini, y, x_end, y);
}
// Calculate the location and draw the right side label // Calculate the location and draw the right side label
Text( x_end+text_offset, y-label_height, TextLadder ); Text( x_end2+text_offset, y-label_height, TextLadder );
} }
} }
} }
TextList.draw(); TextList.draw();
glLineWidth(0.2);
LineList.draw(); LineList.draw();
glEnable(GL_LINE_STIPPLE); glEnable(GL_LINE_STIPPLE);
#ifdef DO_PANEL_HACK
glLineStipple( 1, current_options.get_panel_status() ? 0x0F0F : 0x00FF );
#else
glLineStipple( 1, 0x00FF ); glLineStipple( 1, 0x00FF );
#endif
StippleLineList.draw( ); StippleLineList.draw( );
glDisable(GL_LINE_STIPPLE); glDisable(GL_LINE_STIPPLE);
}
// } // if(div_units)
glPopMatrix(); glPopMatrix();
} }