Fix the energy gauge display for jumps
From ETRacer
Developped with source code release v0.4
The gauge display is broken in release 0.4 : when you press the jump key, you just dont see your jump energy increase in the round-shaped gauge display.
The gauge is always empty ! Damnit...
To fix this, you have to edit the source file (hud.cpp) where the function to display the gauge is defined. It's a very simple modification to apply, as you will see below :-).
Here is the part of the source code which draws the gauge :
//In hud.cpp
//==============
#define ENERGY_GAUGE_BOTTOM 3.0
#define ENERGY_GAUGE_CENTER_X 71.0
#define ENERGY_GAUGE_CENTER_Y 55.0
#define SPEEDBAR_OUTER_RADIUS ( ENERGY_GAUGE_CENTER_X )
#define SPEEDBAR_BASE_ANGLE 225
#define SPEEDBAR_MAX_ANGLE 45
#define SPEEDBAR_GREEN_MAX_SPEED ( MAX_PADDLING_SPEED * M_PER_SEC_TO_KM_PER_H )
#define SPEEDBAR_YELLOW_MAX_SPEED 100
#define SPEEDBAR_RED_MAX_SPEED 160
#define SPEEDBAR_GREEN_FRACTION 0.5
#define SPEEDBAR_YELLOW_FRACTION 0.25
#define SPEEDBAR_RED_FRACTION 0.25
#define SPEED_UNITS_Y_OFFSET 4.0
static GLfloat energy_background_color[] = { 0.2, 0.2, 0.2, 0.5 };
static GLfloat energy_foreground_color[] = { 0.54, 0.59, 1.0, 0.5 };
static GLfloat speedbar_background_color[] = { 0.2, 0.2, 0.2, 0.5 };
static GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 };
void
HUD::initGauge()
{
const char *binding;
binding = "gauge_energy_mask";
if ( !get_texture_binding( binding, &m_energymaskTex ) ) {
print_warning( IMPORTANT_WARNING,
"Couldn't get texture for binding %s", binding );
}
binding = "gauge_speed_mask";
if ( !get_texture_binding( binding, &m_speedmaskTex ) ) {
print_warning( IMPORTANT_WARNING,
"Couldn't get texture for binding %s", binding );
}
binding = "gauge_outline";
if ( !get_texture_binding( binding, &m_outlineTex ) ) {
print_warning( IMPORTANT_WARNING,
"Couldn't get texture for binding %s", binding );
}
}
void
HUD::gauge(const int i, const double speed, const double energy)
{
GLfloat xplane[4] = { 1.0/m_element[i].size, 0.0, 0.0, 0.0 };
GLfloat yplane[4] = { 0.0, 1.0/m_element[i].size, 0.0, 0.0 };
double y;
double speedbar_frac;
//the gauge bar needs it's own mode
//we reset the mode at the end of the function
set_gl_options( GAUGE_BARS );
glTexGenfv( GL_S, GL_OBJECT_PLANE, xplane );
glTexGenfv( GL_T, GL_OBJECT_PLANE, yplane );
glPushMatrix();
{
glTranslatef( getparam_x_resolution() - m_element[i].width,
0,
0 );
glColor4fv( energy_background_color );
glBindTexture( GL_TEXTURE_2D, m_energymaskTex );
y = ENERGY_GAUGE_BOTTOM + energy * m_element[i].height;
glBegin( GL_QUADS );
{
glVertex2f( 0.0, y );
glVertex2f( m_element[i].size, y );
glVertex2f( m_element[i].size, m_element[i].size );
glVertex2f( 0.0, m_element[i].size );
}
glEnd();
glColor4fv( energy_foreground_color );
glBegin( GL_QUADS );
{
glVertex2f( 0.0, 0.0 );
glVertex2f( m_element[i].size, 0.0 );
glVertex2f( m_element[i].size, y );
glVertex2f( 0.0, y );
}
glEnd();
/* Calculate the fraction of the speed bar to fill */
speedbar_frac = 0.0;
if ( speed > SPEEDBAR_GREEN_MAX_SPEED ) {
speedbar_frac = SPEEDBAR_GREEN_FRACTION;
if ( speed > SPEEDBAR_YELLOW_MAX_SPEED ) {
speedbar_frac += SPEEDBAR_YELLOW_FRACTION;
if ( speed > SPEEDBAR_RED_MAX_SPEED ) {
speedbar_frac += SPEEDBAR_RED_FRACTION;
} else {
speedbar_frac +=
( speed - SPEEDBAR_YELLOW_MAX_SPEED ) /
( SPEEDBAR_RED_MAX_SPEED - SPEEDBAR_YELLOW_MAX_SPEED ) *
SPEEDBAR_RED_FRACTION;
}
} else {
speedbar_frac +=
( speed - SPEEDBAR_GREEN_MAX_SPEED ) /
( SPEEDBAR_YELLOW_MAX_SPEED - SPEEDBAR_GREEN_MAX_SPEED ) *
SPEEDBAR_YELLOW_FRACTION;
}
} else {
speedbar_frac += speed/SPEEDBAR_GREEN_MAX_SPEED *
SPEEDBAR_GREEN_FRACTION;
}
glColor4fv( speedbar_background_color );
glBindTexture( GL_TEXTURE_2D, m_speedmaskTex );
draw_partial_tri_fan( 1.0 );
glColor4fv( white );
draw_partial_tri_fan( MIN( 1.0, speedbar_frac ) );
glColor4fv( white );
glBindTexture( GL_TEXTURE_2D, m_outlineTex );
glBegin( GL_QUADS );
{
glVertex2f( 0.0, 0.0 );
glVertex2f( m_element[i].size, 0.0 );
glVertex2f( m_element[i].size, m_element[i].size );
glVertex2f( 0.0, m_element[i].size );
}
glEnd();
}
glPopMatrix();
//we reset this because all other elements need TEXFONT
set_gl_options( TEXFONT );
}
The gauge itself is actually drawn using two adjacent textured quads, each of a different color (bg color and fg color, fg color representing the "filling" of the gauge with energy). The texture is extracted from gaugeenergymask.png, and is stored as gauge_energy_mask in the code.
The current colors for the gauge, respectively dark grey for the background and lighter grey-blue, have their opacity both set to 0.5, which means both colors are translucent, so that the end-user of the game cant clearly make out the difference between the two parts of the gauge (filling and background). In order to make the difference clearer, we set the opacity of the foreground color to 1.0 (rendering it more opaque).
Here is the code modification I developped, in order to have a more usable gauge :
//In hud.cpp
//==============
//...
//ORIGINAL
static GLfloat energy_background_color[] = { 0.2, 0.2, 0.2, 0.5 };
static GLfloat energy_foreground_color[] = { 0.54, 0.59, 1.0, 0.5 };
//MODIFIED
static GLfloat energy_background_color[] = { 0.2, 0.2, 0.2, 0.5 };
static GLfloat energy_foreground_color[] = { 0.54, 0.59, 1.0, 1.0 };
Now the gauge is working fine, thanks !!
And of course I cant resist the pleasure of posting a snapshot of the coolest downhill penguin racing game in town !


