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