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