]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/splash.cxx
Just a gimmick: make background color configurable. Maybe some dark color
[flightgear.git] / src / Main / splash.cxx
index 7f07e291841def0dd1cf89f8498d8442d1ff8f26..334cd63aae55604e0f9c73d2e32f152ff9c47461 100644 (file)
 #  include <config.h>
 #endif
 
-#ifdef FG_MATH_EXCEPTION_CLASH
+#ifdef SG_MATH_EXCEPTION_CLASH
 #  include <math.h>
 #endif
 
-#ifdef HAVE_WINDOWS_H          
+#ifdef HAVE_WINDOWS_H
 #  include <windows.h>
 #endif
 
-#include <GL/glut.h>
-#include <XGL/xgl.h>
-
 #include <string.h>
 
-#include <Debug/logstream.hxx>
-#include <Main/options.hxx>
-#include <Math/fg_random.h>
-#include <Misc/fgpath.hxx>
-#include <Objects/texload.h>
+#include <plib/pu.h>
+#include <simgear/compiler.h>
 
-#include "splash.hxx"
-#include "views.hxx"
+#include SG_GLU_H
 
+#include <simgear/debug/logstream.hxx>
+#include <simgear/screen/texture.hxx>
+#include <simgear/math/sg_random.h>
+#include <simgear/misc/sg_path.hxx>
 
-static GLuint splash_texid;
-static GLubyte *splash_texbuf;
+#include <GUI/new_gui.hxx>
 
+#include "globals.hxx"
+#include "fg_props.hxx"
+#include "splash.hxx"
+#include "fg_os.hxx"
+#include "renderer.hxx"
 
-// Initialize the splash screen
-void fgSplashInit ( void ) {
-    int width, height;
-
-    FG_LOG( FG_GENERAL, FG_INFO, "Initializing splash screen" );
-#ifdef GL_VERSION_1_1
-    xglGenTextures(1, &splash_texid);
-    xglBindTexture(GL_TEXTURE_2D, splash_texid);
-#elif GL_EXT_texture_object
-    xglGenTexturesEXT(1, &splash_texid);
-    xglBindTextureEXT(GL_TEXTURE_2D, splash_texid);
-#else
-#  error port me
-#endif
+static const int fontsize = 19;
+static const char fontname[] = "default.txf";
+static const char *progress_text = 0;
 
-    xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-    xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);   
-    xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
-    // load in the texture data
-    int num = (int)(fg_random() * 4.0 + 1.0);
-    char num_str[256];
-    sprintf(num_str, "%d", num);
+static SGTexture splash;
+static fntTexFont font;
+static fntRenderer info;
 
-    FGPath tpath( current_options.get_fg_root() );
-    tpath.append( "Textures/Splash" );
-    tpath.concat( num_str );
-    tpath.concat( ".rgb" );
 
-    if ( (splash_texbuf = 
-         read_rgb_texture(tpath.c_str(), &width, &height)) == NULL )
+// 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() );
+    if (splash_texture == NULL || !strcmp(splash_texture, "")) {
+        // load in the texture data
+        int num = (int)(sg_random() * 5.0 + 1.0);
+        char num_str[5];
+        snprintf(num_str, 4, "%d", num);
+
+        tpath.append( "Textures/Splash" );
+        tpath.concat( num_str );
+        tpath.concat( ".rgb" );
+    } else
+        tpath.append( splash_texture );
+
+    splash.read_rgb_texture(tpath.c_str());
+    if (!splash.usable())
     {
-       // Try compressed
-       FGPath fg_tpath = tpath;
-       fg_tpath.concat( ".gz" );
-       if ( (splash_texbuf = 
-             read_rgb_texture(fg_tpath.c_str(), &width, &height)) == NULL )
-       {
-           FG_LOG( FG_GENERAL, FG_ALERT, 
-                   "Error in loading splash screen texture " << tpath.str() );
-           exit(-1);
-       } 
-    } 
-
-    xglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, 
-                  GL_UNSIGNED_BYTE, (GLvoid *)(splash_texbuf) );
+        // 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);
+        }
+    }
+
+    splash.select();
 }
 
 
-// Update the splash screen with progress specified from 0.0 to 1.0
-void fgSplashUpdate ( double progress ) {
-    int xmin, ymin, xmax, ymax;
-    int xsize = 480;
-    int ysize = 380;
-
-    xmin = (current_view.get_winWidth() - xsize) / 2;
-    xmax = xmin + xsize;
+void fgSplashProgress ( const char *s )
+{
+    progress_text = s;
+    fgRequestRedraw();
+}
 
-    ymin = (current_view.get_winHeight() - ysize) / 2;
-    ymax = ymin + ysize;
 
-    // first clear the screen;
-    xglClearColor(0.0, 0.0, 0.0, 1.0);
-    xglClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
+// 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);
 
-    // now draw the logo
-    xglMatrixMode(GL_PROJECTION);
-    xglPushMatrix();
-    xglLoadIdentity();
-    gluOrtho2D(0, current_view.get_winWidth(), 0, current_view.get_winHeight());
-    xglMatrixMode(GL_MODELVIEW);
-    xglPushMatrix();
-    xglLoadIdentity();
-
-    xglDisable(GL_DEPTH_TEST);
-    xglDisable(GL_LIGHTING);
-    xglEnable(GL_TEXTURE_2D);
-#ifdef GL_VERSION_1_1
-    xglBindTexture(GL_TEXTURE_2D, splash_texid);
-#elif GL_EXT_texture_object
-    xglBindTextureEXT(GL_TEXTURE_2D, splash_texid);
-#else
-#  error port me
-#endif
-    xglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
+    if (!screen_width || !screen_height)
+        return;
 
-    xglBegin(GL_POLYGON);
-    xglTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin);
-    xglTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin);
-    xglTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax);
-    xglTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax); 
-    xglEnd();
+    globals->get_renderer()->resize(screen_width, screen_height);
+    int size = screen_width < (screen_height - 5 * fontsize)
+            ? screen_width : screen_height - 5 * fontsize;
+    if (size > 512)
+        size = 512;
 
-    xglutSwapBuffers();
-
-    xglEnable(GL_DEPTH_TEST);
-    xglEnable(GL_LIGHTING);
-    xglDisable(GL_TEXTURE_2D);
+    int xmin, ymin, xmax, ymax;
+    xmin = (screen_width - size) / 2;
+    xmax = xmin + size;
+
+    ymin = (screen_height - size) / 2;
+    ymax = ymin + size;
+
+    glMatrixMode(GL_PROJECTION);
+    glPushMatrix();
+    glLoadIdentity();
+    gluOrtho2D(0, screen_width, 0, screen_height);
+    glMatrixMode(GL_MODELVIEW);
+    glPushMatrix();
+    glLoadIdentity();
+
+    glDisable(GL_DEPTH_TEST);
+    glDisable(GL_LIGHTING);
+
+    // draw the background
+    FGColor c(0.0, 0.0, 0.0);
+    c.merge(fgGetNode("/sim/gui/colors/splash-screen"));
+    glColor4f(c.red(), c.green(), c.blue(), alpha );
+    glBegin(GL_POLYGON);
+    glVertex2f(0.0, 0.0);
+    glVertex2f(screen_width, 0.0);
+    glVertex2f(screen_width, screen_height);
+    glVertex2f(0.0, screen_height);
+    glEnd();
 
-    xglMatrixMode(GL_PROJECTION);
-    xglPopMatrix();
-    xglMatrixMode(GL_MODELVIEW);
-    xglPopMatrix();
+    // now draw the logo
+    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();
+    }
+
+    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-font"));
+        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);
+    glDisable(GL_TEXTURE_2D);
+
+    glMatrixMode(GL_PROJECTION);
+    glPopMatrix();
+    glMatrixMode(GL_MODELVIEW);
+    glPopMatrix();
 }