1
0
Fork 0
flightgear/src/Main/splash.cxx

164 lines
4.2 KiB
C++
Raw Normal View History

1998-07-06 02:42:36 +00:00
// splash.cxx -- draws the initial splash screen
//
// Written by Curtis Olson, started July 1998. (With a little looking
// at Freidemann's panel code.) :-)
//
// Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id$
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
2001-03-23 22:42:49 +00:00
#ifdef SG_MATH_EXCEPTION_CLASH
# include <math.h>
#endif
1998-07-06 02:42:36 +00:00
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
#include <string.h>
#include <simgear/compiler.h>
#include SG_GLU_H
2000-02-16 23:01:03 +00:00
#include <simgear/debug/logstream.hxx>
#include <simgear/screen/texture.hxx>
#include <simgear/math/sg_random.h>
#include <simgear/misc/sg_path.hxx>
1998-07-06 02:42:36 +00:00
#include "globals.hxx"
#include "fg_props.hxx"
1998-07-06 02:42:36 +00:00
#include "splash.hxx"
#include "fg_os.hxx"
1998-07-06 02:42:36 +00:00
2003-04-09 20:28:42 +00:00
static SGTexture splash;
1998-07-06 02:42:36 +00:00
// Initialize the splash screen
void fgSplashInit ( const char *splash_texture ) {
if (!fgGetBool("/sim/startup/splash-screen"))
return;
2001-03-24 06:03:11 +00:00
SG_LOG( SG_GENERAL, SG_INFO, "Initializing splash screen" );
1998-07-06 02:42:36 +00:00
2003-04-09 20:28:42 +00:00
splash.bind();
1998-07-06 02:42:36 +00:00
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 );
1998-07-06 02:42:36 +00:00
2003-04-09 20:28:42 +00:00
splash.read_rgb_texture(tpath.c_str());
if (!splash.usable())
{
1998-07-06 02:42:36 +00:00
// Try compressed
SGPath fg_tpath = tpath;
fg_tpath.concat( ".gz" );
2003-04-09 20:28:42 +00:00
splash.read_rgb_texture(fg_tpath.c_str());
if ( !splash.usable() )
{
2001-03-24 06:03:11 +00:00
SG_LOG( SG_GENERAL, SG_ALERT,
"Error in loading splash screen texture " << tpath.str() );
exit(-1);
1998-07-06 02:42:36 +00:00
}
}
2003-04-09 20:28:42 +00:00
splash.select();
1998-07-06 02:42:36 +00:00
}
// Update the splash screen with alpha specified from 0.0 to 1.0
void fgSplashUpdate ( float alpha ) {
1998-07-06 02:42:36 +00:00
int xmin, ymin, xmax, ymax;
int xsize = 512;
int ysize = 512;
1998-07-06 02:42:36 +00:00
if ( !fgGetInt("/sim/startup/xsize")
|| !fgGetInt("/sim/startup/ysize") ) {
1999-06-28 18:19:26 +00:00
return;
}
xmin = (fgGetInt("/sim/startup/xsize") - xsize) / 2;
1998-07-06 02:42:36 +00:00
xmax = xmin + xsize;
ymin = (fgGetInt("/sim/startup/ysize") - ysize) / 2;
1998-07-06 02:42:36 +00:00
ymax = ymin + ysize;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, fgGetInt("/sim/startup/xsize"),
0, fgGetInt("/sim/startup/ysize"));
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
1998-07-06 02:42:36 +00:00
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
// draw the background
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"));
glEnd();
// now draw the logo
if (fgGetBool("/sim/startup/splash-screen") && splash.usable()) {
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();
}
1998-07-06 02:42:36 +00:00
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
1998-07-06 02:42:36 +00:00
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
1998-07-06 02:42:36 +00:00
}