]> git.mxchange.org Git - flightgear.git/blob - src/Main/splash.cxx
- implement progress information (enabled by default; can be turned off via
[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., 675 Mass Ave, Cambridge, MA 02139, 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 "globals.hxx"
50 #include "fg_props.hxx"
51 #include "splash.hxx"
52 #include "fg_os.hxx"
53
54 static const int fontsize = 19;
55 static const char fontname[] = "default.txf";
56 static const char *text = 0;
57
58
59 static SGTexture splash;
60 static fntTexFont font;
61 static fntRenderer info;
62
63
64 // Initialize the splash screen
65 void fgSplashInit ( const char *splash_texture ) {
66     fgRequestRedraw();
67
68     if (!fgGetBool("/sim/startup/splash-screen"))
69         return;
70
71     SG_LOG( SG_GENERAL, SG_INFO, "Initializing splash screen" );
72
73
74     SGPath fontpath;
75     char* envp = ::getenv("FG_FONTS");
76     if (envp != NULL) {
77         fontpath.set(envp);
78     } else {
79         fontpath.set(globals->get_fg_root());
80         fontpath.append("Fonts");
81     }
82     SGPath path(fontpath);
83     path.append(fontname);
84
85     font.load((char *)path.c_str());
86
87     info.setFont(&font);
88     info.setPointSize(fontsize);
89
90
91     splash.bind();
92
93     SGPath tpath( globals->get_fg_root() );
94     if (splash_texture == NULL || !strcmp(splash_texture, "")) {
95         // load in the texture data
96         int num = (int)(sg_random() * 5.0 + 1.0);
97         char num_str[5];
98         snprintf(num_str, 4, "%d", num);
99
100         tpath.append( "Textures/Splash" );
101         tpath.concat( num_str );
102         tpath.concat( ".rgb" );
103     } else
104         tpath.append( splash_texture );
105
106     splash.read_rgb_texture(tpath.c_str());
107     if (!splash.usable())
108     {
109         // Try compressed
110         SGPath fg_tpath = tpath;
111         fg_tpath.concat( ".gz" );
112
113         splash.read_rgb_texture(fg_tpath.c_str());
114         if ( !splash.usable() )
115         {
116             SG_LOG( SG_GENERAL, SG_ALERT,
117                     "Error in loading splash screen texture " << tpath.str() );
118             exit(-1);
119         }
120     }
121
122     splash.select();
123 }
124
125
126 void fgSplashProgress ( const char *s )
127 {
128     text = s;
129     fgRequestRedraw();
130 }
131
132
133 // Update the splash screen with alpha specified from 0.0 to 1.0
134 void fgSplashUpdate ( float alpha ) {
135     int screen_width = fgGetInt("/sim/startup/xsize", 0);
136     int screen_height = fgGetInt("/sim/startup/ysize", 0);
137
138     if (!screen_width || !screen_height)
139         return;
140
141     int size = screen_width < (screen_height - 5 * fontsize)
142             ? screen_width : screen_height - 5 * fontsize;
143     if (size > 512)
144         size = 512;
145
146     int xmin, ymin, xmax, ymax;
147     xmin = (screen_width - size) / 2;
148     xmax = xmin + size;
149
150     ymin = (screen_height - size) / 2;
151     ymax = ymin + size;
152
153     glMatrixMode(GL_PROJECTION);
154     glPushMatrix();
155     glLoadIdentity();
156     gluOrtho2D(0, screen_width, 0, screen_height);
157     glMatrixMode(GL_MODELVIEW);
158     glPushMatrix();
159     glLoadIdentity();
160
161     glDisable(GL_DEPTH_TEST);
162     glDisable(GL_LIGHTING);
163
164     // draw the background
165     glColor4f( 0.0, 0.0, 0.0, alpha );
166     glBegin(GL_POLYGON);
167     glVertex2f(0.0, 0.0);
168     glVertex2f(screen_width, 0.0);
169     glVertex2f(screen_width, screen_height);
170     glVertex2f(0.0, screen_height);
171     glEnd();
172
173     // now draw the logo
174     if (fgGetBool("/sim/startup/splash-screen", true)) {
175         glEnable(GL_TEXTURE_2D);
176         splash.bind();
177         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
178
179         glColor4f( 1.0, 1.0, 1.0, alpha );
180         glBegin(GL_POLYGON);
181         glTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin);
182         glTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin);
183         glTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax);
184         glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax);
185         glEnd();
186     }
187
188     if (text && fgGetBool("/sim/startup/splash-progress", true)) {
189         glEnable(GL_ALPHA_TEST);
190         glEnable(GL_BLEND);
191         glAlphaFunc(GL_GREATER, 0.1f);
192         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
193         glDisable(GL_CULL_FACE);
194
195         float left, right, bot, top;
196
197         info.begin();
198         glColor3f(1.0, 0.9, 0.0);
199         font.getBBox(text, fontsize, 0, &left, &right, &bot, &top);
200         info.start2f((screen_width - right) / 2.0, 10.0 - bot);
201         info.puts(text);
202
203         const char *s = fgGetString("/sim/startup/splash-title", "");
204         font.getBBox(s, fontsize, 0, &left, &right, &bot, &top);
205         info.start2f((screen_width - right) / 2.0, screen_height - top - bot - 10.0);
206         info.puts(s);
207         info.end();
208     }
209
210     glEnable(GL_DEPTH_TEST);
211     glEnable(GL_LIGHTING);
212     glDisable(GL_TEXTURE_2D);
213
214     glMatrixMode(GL_PROJECTION);
215     glPopMatrix();
216     glMatrixMode(GL_MODELVIEW);
217     glPopMatrix();
218 }
219
220