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., 675 Mass Ave, Cambridge, MA 02139, 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 "globals.hxx"
50 #include "fg_props.hxx"
54 static const int fontsize = 19;
55 static const char fontname[] = "default.txf";
56 static const char *progress_text = 0;
59 static SGTexture splash;
60 static fntTexFont font;
61 static fntRenderer info;
64 // Initialize the splash screen
65 void fgSplashInit ( const char *splash_texture ) {
68 SG_LOG( SG_GENERAL, SG_INFO, "Initializing splash screen" );
72 char* envp = ::getenv("FG_FONTS");
76 fontpath.set(globals->get_fg_root());
77 fontpath.append("Fonts");
79 SGPath path(fontpath);
80 path.append(fontname);
82 if (!font.load((char *)path.c_str())) {
83 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading font " << path.str() );
88 info.setPointSize(fontsize);
90 if (!fgGetBool("/sim/startup/splash-screen"))
95 SGPath tpath( globals->get_fg_root() );
96 if (splash_texture == NULL || !strcmp(splash_texture, "")) {
97 // load in the texture data
98 int num = (int)(sg_random() * 5.0 + 1.0);
100 snprintf(num_str, 4, "%d", num);
102 tpath.append( "Textures/Splash" );
103 tpath.concat( num_str );
104 tpath.concat( ".rgb" );
106 tpath.append( splash_texture );
108 splash.read_rgb_texture(tpath.c_str());
109 if (!splash.usable())
112 SGPath fg_tpath = tpath;
113 fg_tpath.concat( ".gz" );
115 splash.read_rgb_texture(fg_tpath.c_str());
116 if ( !splash.usable() )
118 SG_LOG( SG_GENERAL, SG_ALERT,
119 "Error in loading splash screen texture " << tpath.str() );
128 void fgSplashProgress ( const char *s )
135 // Update the splash screen with alpha specified from 0.0 to 1.0
136 void fgSplashUpdate ( float alpha ) {
137 int screen_width = fgGetInt("/sim/startup/xsize", 0);
138 int screen_height = fgGetInt("/sim/startup/ysize", 0);
140 if (!screen_width || !screen_height)
143 int size = screen_width < (screen_height - 5 * fontsize)
144 ? screen_width : screen_height - 5 * fontsize;
148 int xmin, ymin, xmax, ymax;
149 xmin = (screen_width - size) / 2;
152 ymin = (screen_height - size) / 2;
155 glMatrixMode(GL_PROJECTION);
158 gluOrtho2D(0, screen_width, 0, screen_height);
159 glMatrixMode(GL_MODELVIEW);
163 glDisable(GL_DEPTH_TEST);
164 glDisable(GL_LIGHTING);
166 // draw the background
167 glColor4f( 0.0, 0.0, 0.0, alpha );
169 glVertex2f(0.0, 0.0);
170 glVertex2f(screen_width, 0.0);
171 glVertex2f(screen_width, screen_height);
172 glVertex2f(0.0, screen_height);
176 if (fgGetBool("/sim/startup/splash-screen", true)) {
177 glEnable(GL_TEXTURE_2D);
179 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
181 glColor4f( 1.0, 1.0, 1.0, alpha );
183 glTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin);
184 glTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin);
185 glTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax);
186 glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax);
190 if (info.getFont() && progress_text && fgGetBool("/sim/startup/splash-progress", true)) {
191 glEnable(GL_ALPHA_TEST);
193 glAlphaFunc(GL_GREATER, 0.1f);
194 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
195 glDisable(GL_CULL_FACE);
197 float left, right, bot, top;
200 glColor4f(1.0, 0.9, 0.0, alpha);
201 font.getBBox(progress_text, fontsize, 0, &left, &right, &bot, &top);
202 info.start2f((screen_width - right) / 2.0, 10.0 - bot);
203 info.puts(progress_text);
205 const char *s = fgGetString("/sim/startup/splash-title", "");
206 font.getBBox(s, fontsize, 0, &left, &right, &bot, &top);
207 info.start2f((screen_width - right) / 2.0, screen_height - top - bot - 10.0);
212 glEnable(GL_DEPTH_TEST);
213 glEnable(GL_LIGHTING);
214 glDisable(GL_TEXTURE_2D);
216 glMatrixMode(GL_PROJECTION);
218 glMatrixMode(GL_MODELVIEW);