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;
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());
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() );
108 void fgSplashProgress ( const char *s )
115 // Update the splash screen with alpha specified from 0.0 to 1.0
116 void fgSplashUpdate ( float alpha ) {
117 const int EMPTYSPACE = 80;
119 int screen_width = fgGetInt("/sim/startup/xsize", 0);
120 int screen_height = fgGetInt("/sim/startup/ysize", 0);
122 if (!screen_width || !screen_height)
125 globals->get_renderer()->resize(screen_width, screen_height);
126 int size = screen_width < (screen_height - EMPTYSPACE)
127 ? screen_width : screen_height - EMPTYSPACE;
131 int xmin, ymin, xmax, ymax;
132 xmin = (screen_width - size) / 2;
135 ymin = (screen_height - size) / 2;
138 glMatrixMode(GL_PROJECTION);
141 gluOrtho2D(0, screen_width, 0, screen_height);
142 glViewport(0, 0, screen_width, screen_height);
143 glMatrixMode(GL_MODELVIEW);
147 glDisable(GL_DEPTH_TEST);
148 glDisable(GL_LIGHTING);
149 glDisable(GL_CULL_FACE);
151 // draw the background
152 FGColor c(0.0, 0.0, 0.0);
153 c.merge(style->getNode("colors/splash-screen"));
154 glColor4f(c.red(), c.green(), c.blue(), alpha );
156 glVertex2f(0.0, 0.0);
157 glVertex2f(screen_width, 0.0);
158 glVertex2f(screen_width, screen_height);
159 glVertex2f(0.0, screen_height);
162 glEnable(GL_ALPHA_TEST);
164 glAlphaFunc(GL_GREATER, 0.1f);
165 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
168 if (fgGetBool("/sim/startup/splash-screen", true)) {
169 glEnable(GL_TEXTURE_2D);
171 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
173 glColor4f( 1.0, 1.0, 1.0, alpha );
175 glTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin);
176 glTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin);
177 glTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax);
178 glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax);
180 glDisable(GL_TEXTURE_2D);
183 if (progress_text && fgGetBool("/sim/startup/splash-progress", true)) {
184 puFont *fnt = globals->get_fontcache()->get(style->getNode("fonts/splash"));
186 FGColor c(1.0, 0.9, 0.0);
187 c.merge(style->getNode("colors/splash-font"));
188 glColor4f(c.red(), c.green(), c.blue(), alpha);
190 float height = fnt->getStringHeight("/M$");
191 float descender = fnt->getStringDescender();
192 float width = fnt->getFloatStringWidth(progress_text);
193 fnt->drawString(progress_text, int((screen_width - width) / 2), int(10 + descender));
195 const char *title = fgGetString("/sim/startup/splash-title", "");
196 width = fnt->getFloatStringWidth(title);
197 fnt->drawString(title, int((screen_width - width) / 2), int(screen_height - 10 - height));
200 glEnable(GL_DEPTH_TEST);
201 glEnable(GL_LIGHTING);
203 glMatrixMode(GL_PROJECTION);
205 glMatrixMode(GL_MODELVIEW);