1 // splash.cxx -- draws the initial splash screen
3 // Written by Curtis Olson, started July 1998. (With a little looking
4 // at Freidemann's panel code.) :-)
6 // Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
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.
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.
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.
29 #ifdef SG_MATH_EXCEPTION_CLASH
40 #include <simgear/compiler.h>
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>
49 #include <GUI/new_gui.hxx>
51 #include "globals.hxx"
52 #include "fg_props.hxx"
55 #include "renderer.hxx"
57 static const char *progress_text = 0;
58 static SGTexture *splash = new SGTexture;
59 SGPropertyNode_ptr style = 0;
62 // Initialize the splash screen
63 void fgSplashInit ( const char *splash_texture ) {
66 SG_LOG( SG_GENERAL, SG_INFO, "Initializing splash screen" );
68 style = fgGetNode("/sim/gui/style[0]", true);
70 if (!fgGetBool("/sim/startup/splash-screen"))
75 SGPath tpath( globals->get_fg_root() );
76 if (splash_texture == NULL || !strcmp(splash_texture, "")) {
77 // load in the texture data
78 int num = (int)(sg_random() * 5.0 + 1.0);
80 snprintf(num_str, 4, "%d", num);
82 tpath.append( "Textures/Splash" );
83 tpath.concat( num_str );
84 tpath.concat( ".rgb" );
86 tpath.append( splash_texture );
88 splash->read_rgba_texture(tpath.c_str());
89 if (!splash->usable())
92 SGPath fg_tpath = tpath;
93 fg_tpath.concat( ".gz" );
95 splash->read_rgba_texture(fg_tpath.c_str());
96 if ( !splash->usable() )
98 SG_LOG( SG_GENERAL, SG_ALERT,
99 "Error in loading splash screen texture " << tpath.str() );
115 void fgSplashProgress ( const char *s )
122 // Update the splash screen with alpha specified from 0.0 to 1.0
123 void fgSplashUpdate ( float alpha ) {
124 const int EMPTYSPACE = 80;
126 int screen_width = fgGetInt("/sim/startup/xsize", 0);
127 int screen_height = fgGetInt("/sim/startup/ysize", 0);
129 if (!screen_width || !screen_height)
132 globals->get_renderer()->resize(screen_width, screen_height);
133 int size = screen_width < (screen_height - EMPTYSPACE)
134 ? screen_width : screen_height - EMPTYSPACE;
138 int xmin, ymin, xmax, ymax;
139 xmin = (screen_width - size) / 2;
142 ymin = (screen_height - size) / 2;
145 glMatrixMode(GL_PROJECTION);
148 gluOrtho2D(0, screen_width, 0, screen_height);
149 glViewport(0, 0, screen_width, screen_height);
150 glMatrixMode(GL_MODELVIEW);
154 glDisable(GL_DEPTH_TEST);
155 glDisable(GL_LIGHTING);
156 glDisable(GL_CULL_FACE);
158 // draw the background
159 FGColor c(0.0, 0.0, 0.0);
160 c.merge(style->getNode("colors/splash-screen"));
161 glColor4f(c.red(), c.green(), c.blue(), alpha );
163 glVertex2f(0.0, 0.0);
164 glVertex2f(screen_width, 0.0);
165 glVertex2f(screen_width, screen_height);
166 glVertex2f(0.0, screen_height);
169 glEnable(GL_ALPHA_TEST);
171 glAlphaFunc(GL_GREATER, 0.1f);
172 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
175 if (fgGetBool("/sim/startup/splash-screen", true)) {
176 glEnable(GL_TEXTURE_2D);
178 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
180 glColor4f( 1.0, 1.0, 1.0, alpha );
182 glTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin);
183 glTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin);
184 glTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax);
185 glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax);
187 glDisable(GL_TEXTURE_2D);
190 if (progress_text && fgGetBool("/sim/startup/splash-progress", true)) {
191 puFont *fnt = globals->get_fontcache()->get(style->getNode("fonts/splash"));
193 FGColor c(1.0, 0.9, 0.0);
194 c.merge(style->getNode("colors/splash-font"));
195 glColor4f(c.red(), c.green(), c.blue(), alpha);
197 float height = fnt->getStringHeight("/M$");
198 float descender = fnt->getStringDescender();
199 float width = fnt->getFloatStringWidth(progress_text);
200 fnt->drawString(progress_text, int((screen_width - width) / 2), int(10 + descender));
202 const char *title = fgGetString("/sim/startup/splash-title", "");
203 width = fnt->getFloatStringWidth(title);
204 fnt->drawString(title, int((screen_width - width) / 2), int(screen_height - 10 - height));
207 glEnable(GL_DEPTH_TEST);
208 glEnable(GL_LIGHTING);
210 glMatrixMode(GL_PROJECTION);
212 glMatrixMode(GL_MODELVIEW);