]> git.mxchange.org Git - flightgear.git/blob - src/Main/splash.cxx
27481659d1e6a1ca8cd08636300793768224d69a
[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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 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 <plib/pu.h>
40 #include <simgear/compiler.h>
41
42 #include SG_GLU_H
43
44 #include <simgear/debug/logstream.hxx>
45 #include <simgear/screen/texture.hxx>
46 #include <simgear/math/sg_random.h>
47 #include <simgear/misc/sg_path.hxx>
48
49 #include <GUI/new_gui.hxx>
50
51 #include "globals.hxx"
52 #include "fg_props.hxx"
53 #include "splash.hxx"
54 #include "fg_os.hxx"
55 #include "renderer.hxx"
56
57 static const char *progress_text = 0;
58 static SGTexture splash;
59
60
61 // Initialize the splash screen
62 void fgSplashInit ( const char *splash_texture ) {
63     fgRequestRedraw();
64
65     SG_LOG( SG_GENERAL, SG_INFO, "Initializing splash screen" );
66
67     if (!fgGetBool("/sim/startup/splash-screen"))
68         return;
69
70     splash.bind();
71
72     SGPath tpath( globals->get_fg_root() );
73     if (splash_texture == NULL || !strcmp(splash_texture, "")) {
74         // load in the texture data
75         int num = (int)(sg_random() * 5.0 + 1.0);
76         char num_str[5];
77         snprintf(num_str, 4, "%d", num);
78
79         tpath.append( "Textures/Splash" );
80         tpath.concat( num_str );
81         tpath.concat( ".rgb" );
82     } else
83         tpath.append( splash_texture );
84
85     splash.read_rgb_texture(tpath.c_str());
86     if (!splash.usable())
87     {
88         // Try compressed
89         SGPath fg_tpath = tpath;
90         fg_tpath.concat( ".gz" );
91
92         splash.read_rgb_texture(fg_tpath.c_str());
93         if ( !splash.usable() )
94         {
95             SG_LOG( SG_GENERAL, SG_ALERT,
96                     "Error in loading splash screen texture " << tpath.str() );
97             exit(-1);
98         }
99     }
100
101     splash.select();
102 }
103
104
105 void fgSplashProgress ( const char *s )
106 {
107     progress_text = s;
108     fgRequestRedraw();
109 }
110
111
112 // Update the splash screen with alpha specified from 0.0 to 1.0
113 void fgSplashUpdate ( float alpha ) {
114     const int EMPTYSPACE = 80;
115
116     int screen_width = fgGetInt("/sim/startup/xsize", 0);
117     int screen_height = fgGetInt("/sim/startup/ysize", 0);
118
119     if (!screen_width || !screen_height)
120         return;
121
122     globals->get_renderer()->resize(screen_width, screen_height);
123     int size = screen_width < (screen_height - EMPTYSPACE)
124             ? screen_width : screen_height - EMPTYSPACE;
125     if (size > 512)
126         size = 512;
127
128     int xmin, ymin, xmax, ymax;
129     xmin = (screen_width - size) / 2;
130     xmax = xmin + size;
131
132     ymin = (screen_height - size) / 2;
133     ymax = ymin + size;
134
135     glMatrixMode(GL_PROJECTION);
136     glPushMatrix();
137     glLoadIdentity();
138     gluOrtho2D(0, screen_width, 0, screen_height);
139     glMatrixMode(GL_MODELVIEW);
140     glPushMatrix();
141     glLoadIdentity();
142
143     glDisable(GL_DEPTH_TEST);
144     glDisable(GL_LIGHTING);
145
146     // draw the background
147     FGColor c(0.0, 0.0, 0.0);
148     c.merge(fgGetNode("/sim/gui/style/colors/splash-screen"));
149     glColor4f(c.red(), c.green(), c.blue(), alpha );
150     glBegin(GL_POLYGON);
151     glVertex2f(0.0, 0.0);
152     glVertex2f(screen_width, 0.0);
153     glVertex2f(screen_width, screen_height);
154     glVertex2f(0.0, screen_height);
155     glEnd();
156
157     // now draw the logo
158     if (fgGetBool("/sim/startup/splash-screen", true)) {
159         glEnable(GL_TEXTURE_2D);
160         splash.bind();
161         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
162
163         glColor4f( 1.0, 1.0, 1.0, alpha );
164         glBegin(GL_POLYGON);
165         glTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin);
166         glTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin);
167         glTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax);
168         glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax);
169         glEnd();
170     }
171
172     if (progress_text && fgGetBool("/sim/startup/splash-progress", true)) {
173         glEnable(GL_ALPHA_TEST);
174         glEnable(GL_BLEND);
175         glAlphaFunc(GL_GREATER, 0.1f);
176         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
177         glDisable(GL_CULL_FACE);
178
179         puFont *fnt = globals->get_fontcache()->get(fgGetNode("/sim/gui/style/fonts/splash"));
180
181         glDisable(GL_TEXTURE_2D);
182         FGColor c(1.0, 0.9, 0.0);
183         c.merge(fgGetNode("/sim/gui/style/colors/splash-font"));
184         glColor4f(c.red(), c.green(), c.blue(), alpha);
185
186         float height = fnt->getStringHeight("/M");
187         float descender = fnt->getStringDescender();
188         float width = fnt->getFloatStringWidth(progress_text);
189         fnt->drawString(progress_text, int((screen_width - width) / 2.0), int(10 + descender));
190
191         const char *title = fgGetString("/sim/startup/splash-title", "");
192         width = fnt->getFloatStringWidth(title);
193         fnt->drawString(title, int((screen_width - width) / 2), int(screen_height - 10 - height));
194     }
195
196     glEnable(GL_DEPTH_TEST);
197     glEnable(GL_LIGHTING);
198     glDisable(GL_TEXTURE_2D);
199
200     glMatrixMode(GL_PROJECTION);
201     glPopMatrix();
202     glMatrixMode(GL_MODELVIEW);
203     glPopMatrix();
204 }
205
206