]> git.mxchange.org Git - flightgear.git/blob - src/Main/splash.cxx
Fix my mailing address by replacing it with my web page.
[flightgear.git] / src / Main / splash.cxx
1 // splash.cxx -- draws the initial splash screen
2 //
3 // Written by Curtis Olson, started July 1998.  (With a little looking
4 // at Freidemann's panel code.) :-)
5 //
6 // Copyright (C) 1997  Michele F. America  - nomimarketing@mail.telepac.pt
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23
24
25 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28
29 #ifdef SG_MATH_EXCEPTION_CLASH
30 #  include <math.h>
31 #endif
32
33 #ifdef HAVE_WINDOWS_H          
34 #  include <windows.h>
35 #endif
36
37 #include <string.h>
38
39 #include <simgear/compiler.h>
40
41 #include SG_GLU_H
42
43 #include <simgear/debug/logstream.hxx>
44 #include <simgear/screen/texture.hxx>
45 #include <simgear/math/sg_random.h>
46 #include <simgear/misc/sg_path.hxx>
47
48 #include "globals.hxx"
49 #include "fg_props.hxx"
50 #include "splash.hxx"
51 #include "fg_os.hxx"
52
53
54
55 static SGTexture splash;
56
57
58 // Initialize the splash screen
59 void fgSplashInit ( const char *splash_texture ) {
60     SG_LOG( SG_GENERAL, SG_INFO, "Initializing splash screen" );
61
62     splash.bind();
63
64     SGPath tpath( globals->get_fg_root() );
65     if (splash_texture == NULL || !strcmp(splash_texture, "")) {
66         // load in the texture data
67         int num = (int)(sg_random() * 5.0 + 1.0);
68         char num_str[5];
69         snprintf(num_str, 4, "%d", num);
70
71         tpath.append( "Textures/Splash" );
72         tpath.concat( num_str );
73         tpath.concat( ".rgb" );
74     } else
75         tpath.append( splash_texture );
76
77     splash.read_rgb_texture(tpath.c_str());
78     if (!splash.usable())
79     {
80         // Try compressed
81         SGPath fg_tpath = tpath;
82         fg_tpath.concat( ".gz" );
83
84         splash.read_rgb_texture(fg_tpath.c_str());
85         if ( !splash.usable() )
86         {
87             SG_LOG( SG_GENERAL, SG_ALERT, 
88                     "Error in loading splash screen texture " << tpath.str() );
89             exit(-1);
90         } 
91     } 
92
93     splash.select();
94 }
95
96
97 // Update the splash screen with progress specified from 0.0 to 1.0
98 void fgSplashUpdate ( double progress, float alpha ) {
99     int xmin, ymin, xmax, ymax;
100     int xsize = 512;
101     int ysize = 512;
102
103     if ( !fgGetInt("/sim/startup/xsize")
104          || !fgGetInt("/sim/startup/ysize") ) {
105         return;
106     }
107
108     xmin = (fgGetInt("/sim/startup/xsize") - xsize) / 2;
109     xmax = xmin + xsize;
110
111     ymin = (fgGetInt("/sim/startup/ysize") - ysize) / 2;
112     ymax = ymin + ysize;
113
114     glMatrixMode(GL_PROJECTION);
115     glPushMatrix();
116     glLoadIdentity();
117     gluOrtho2D(0, fgGetInt("/sim/startup/xsize"),
118                0, fgGetInt("/sim/startup/ysize"));
119     glMatrixMode(GL_MODELVIEW);
120     glPushMatrix();
121     glLoadIdentity();
122
123     glDisable(GL_DEPTH_TEST);
124     glDisable(GL_LIGHTING);
125
126     // draw the background
127     glColor4f( 0.0, 0.0, 0.0, alpha );
128     glBegin(GL_POLYGON);
129     glVertex2f(0.0, 0.0);
130     glVertex2f(fgGetInt("/sim/startup/xsize"), 0.0);
131     glVertex2f(fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize"));
132     glVertex2f(0.0, fgGetInt("/sim/startup/ysize")); 
133     glEnd();
134
135     // now draw the logo
136     glEnable(GL_TEXTURE_2D);
137     splash.bind();
138     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
139
140     glColor4f( 1.0, 1.0, 1.0, alpha );
141     glBegin(GL_POLYGON);
142     glTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin);
143     glTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin);
144     glTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax);
145     glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax); 
146     glEnd();
147
148     glEnable(GL_DEPTH_TEST);
149     glEnable(GL_LIGHTING);
150     glDisable(GL_TEXTURE_2D);
151
152     glMatrixMode(GL_PROJECTION);
153     glPopMatrix();
154     glMatrixMode(GL_MODELVIEW);
155     glPopMatrix();
156 }
157
158