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