X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Fsplash.cxx;h=f33baf3e10d6ab206d2f375ef6c2cab59be4a4ef;hb=1c3e2d4942fe74dac43f1f6af542f9de7d4825db;hp=a316e3b827eab549ede7c48542553d938c6bcaec;hpb=4214cd6c10e8e90577673b4a11b6451248b3c6ee;p=flightgear.git diff --git a/src/Main/splash.cxx b/src/Main/splash.cxx index a316e3b82..f33baf3e1 100644 --- a/src/Main/splash.cxx +++ b/src/Main/splash.cxx @@ -30,12 +30,13 @@ # include #endif -#ifdef HAVE_WINDOWS_H +#ifdef HAVE_WINDOWS_H # include #endif #include +#include #include #include SG_GLU_H @@ -45,20 +46,52 @@ #include #include +#include + #include "globals.hxx" #include "fg_props.hxx" #include "splash.hxx" #include "fg_os.hxx" +static const int fontsize = 19; +static const char fontname[] = "default.txf"; +static const char *progress_text = 0; static SGTexture splash; +static fntTexFont font; +static fntRenderer info; // Initialize the splash screen void fgSplashInit ( const char *splash_texture ) { + fgRequestRedraw(); + SG_LOG( SG_GENERAL, SG_INFO, "Initializing splash screen" ); + + SGPath fontpath; + char* envp = ::getenv("FG_FONTS"); + if (envp != NULL) { + fontpath.set(envp); + } else { + fontpath.set(globals->get_fg_root()); + fontpath.append("Fonts"); + } + SGPath path(fontpath); + path.append(fontname); + + if (!font.load((char *)path.c_str())) { + SG_LOG( SG_GENERAL, SG_ALERT, "Error loading font " << path.str() ); + return; + } + + info.setFont(&font); + info.setPointSize(fontsize); + + if (!fgGetBool("/sim/startup/splash-screen")) + return; + splash.bind(); SGPath tpath( globals->get_fg_root() ); @@ -77,45 +110,54 @@ void fgSplashInit ( const char *splash_texture ) { splash.read_rgb_texture(tpath.c_str()); if (!splash.usable()) { - // Try compressed - SGPath fg_tpath = tpath; - fg_tpath.concat( ".gz" ); + // Try compressed + SGPath fg_tpath = tpath; + fg_tpath.concat( ".gz" ); splash.read_rgb_texture(fg_tpath.c_str()); - if ( !splash.usable() ) - { - SG_LOG( SG_GENERAL, SG_ALERT, - "Error in loading splash screen texture " << tpath.str() ); - exit(-1); - } - } + if ( !splash.usable() ) + { + SG_LOG( SG_GENERAL, SG_ALERT, + "Error in loading splash screen texture " << tpath.str() ); + exit(-1); + } + } splash.select(); } -// Update the splash screen with progress specified from 0.0 to 1.0 -void fgSplashUpdate ( double progress, float alpha ) { - int xmin, ymin, xmax, ymax; - int xsize = 512; - int ysize = 512; +void fgSplashProgress ( const char *s ) +{ + progress_text = s; + fgRequestRedraw(); +} - if ( !fgGetInt("/sim/startup/xsize") - || !fgGetInt("/sim/startup/ysize") ) { - return; - } - xmin = (fgGetInt("/sim/startup/xsize") - xsize) / 2; - xmax = xmin + xsize; +// Update the splash screen with alpha specified from 0.0 to 1.0 +void fgSplashUpdate ( float alpha ) { + int screen_width = fgGetInt("/sim/startup/xsize", 0); + int screen_height = fgGetInt("/sim/startup/ysize", 0); + + if (!screen_width || !screen_height) + return; + + int size = screen_width < (screen_height - 5 * fontsize) + ? screen_width : screen_height - 5 * fontsize; + if (size > 512) + size = 512; + + int xmin, ymin, xmax, ymax; + xmin = (screen_width - size) / 2; + xmax = xmin + size; - ymin = (fgGetInt("/sim/startup/ysize") - ysize) / 2; - ymax = ymin + ysize; + ymin = (screen_height - size) / 2; + ymax = ymin + size; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); - gluOrtho2D(0, fgGetInt("/sim/startup/xsize"), - 0, fgGetInt("/sim/startup/ysize")); + gluOrtho2D(0, screen_width, 0, screen_height); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); @@ -127,23 +169,50 @@ void fgSplashUpdate ( double progress, float alpha ) { glColor4f( 0.0, 0.0, 0.0, alpha ); glBegin(GL_POLYGON); glVertex2f(0.0, 0.0); - glVertex2f(fgGetInt("/sim/startup/xsize"), 0.0); - glVertex2f(fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize")); - glVertex2f(0.0, fgGetInt("/sim/startup/ysize")); + glVertex2f(screen_width, 0.0); + glVertex2f(screen_width, screen_height); + glVertex2f(0.0, screen_height); glEnd(); // now draw the logo - glEnable(GL_TEXTURE_2D); - splash.bind(); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + if (fgGetBool("/sim/startup/splash-screen", true)) { + glEnable(GL_TEXTURE_2D); + splash.bind(); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + glColor4f( 1.0, 1.0, 1.0, alpha ); + glBegin(GL_POLYGON); + glTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin); + glTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin); + glTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax); + glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax); + glEnd(); + } - glColor4f( 1.0, 1.0, 1.0, alpha ); - glBegin(GL_POLYGON); - glTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin); - glTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin); - glTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax); - glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax); - glEnd(); + if (info.getFont() && progress_text && fgGetBool("/sim/startup/splash-progress", true)) { + glEnable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glAlphaFunc(GL_GREATER, 0.1f); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_CULL_FACE); + + float left, right, bot, top; + + info.begin(); + FGColor c(1.0, 0.9, 0.0); + c.merge(fgGetNode("/sim/gui/colors/splash")); + glColor4f(c.red(), c.green(), c.blue(), alpha); + + font.getBBox(progress_text, fontsize, 0, &left, &right, &bot, &top); + info.start2f((screen_width - right) / 2.0, 10.0 - bot); + info.puts(progress_text); + + const char *s = fgGetString("/sim/startup/splash-title", ""); + font.getBBox(s, fontsize, 0, &left, &right, &bot, &top); + info.start2f((screen_width - right) / 2.0, screen_height - top - bot - 10.0); + info.puts(s); + info.end(); + } glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING);