]> git.mxchange.org Git - flightgear.git/blob - src/Main/splash.cxx
Move the texture loader to SimGear
[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 GLUT_H
38
39 #include <string.h>
40
41 #include <simgear/debug/logstream.hxx>
42 #include <simgear/math/sg_random.h>
43 #include <simgear/misc/sg_path.hxx>
44 #include <simgear/misc/texture.hxx>
45
46 #include "globals.hxx"
47 #include "fg_props.hxx"
48 #include "splash.hxx"
49
50
51 static SGTexture splash;
52
53
54 // Initialize the splash screen
55 void fgSplashInit ( void ) {
56     SG_LOG( SG_GENERAL, SG_INFO, "Initializing splash screen" );
57
58     splash.bind();
59
60     // load in the texture data
61     int num = (int)(sg_random() * 4.0 + 1.0);
62     char num_str[256];
63     sprintf(num_str, "%d", num);
64
65     SGPath tpath( globals->get_fg_root() );
66     tpath.append( "Textures/Splash" );
67     tpath.concat( num_str );
68     tpath.concat( ".rgb" );
69
70     splash.read_rgb_texture(tpath.c_str());
71     if (!splash.usable())
72     {
73         // Try compressed
74         SGPath fg_tpath = tpath;
75         fg_tpath.concat( ".gz" );
76
77         splash.read_rgb_texture(fg_tpath.c_str());
78         if ( !splash.usable() )
79         {
80             SG_LOG( SG_GENERAL, SG_ALERT, 
81                     "Error in loading splash screen texture " << tpath.str() );
82             exit(-1);
83         } 
84     } 
85
86     splash.select();
87 }
88
89
90 // Update the splash screen with progress specified from 0.0 to 1.0
91 void fgSplashUpdate ( double progress, float alpha ) {
92     int xmin, ymin, xmax, ymax;
93     int xsize = 480;
94     int ysize = 380;
95
96     if ( !fgGetInt("/sim/startup/xsize")
97          || !fgGetInt("/sim/startup/ysize") ) {
98         return;
99     }
100
101     xmin = (fgGetInt("/sim/startup/xsize") - xsize) / 2;
102     xmax = xmin + xsize;
103
104     ymin = (fgGetInt("/sim/startup/ysize") - ysize) / 2;
105     ymax = ymin + ysize;
106
107     glMatrixMode(GL_PROJECTION);
108     glPushMatrix();
109     glLoadIdentity();
110     gluOrtho2D(0, fgGetInt("/sim/startup/xsize"),
111                0, fgGetInt("/sim/startup/ysize"));
112     glMatrixMode(GL_MODELVIEW);
113     glPushMatrix();
114     glLoadIdentity();
115
116     glDisable(GL_DEPTH_TEST);
117     glDisable(GL_LIGHTING);
118
119     // draw the background
120     glColor4f( 0.0, 0.0, 0.0, alpha );
121     glBegin(GL_POLYGON);
122     glVertex2f(0.0, 0.0);
123     glVertex2f(fgGetInt("/sim/startup/xsize"), 0.0);
124     glVertex2f(fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize"));
125     glVertex2f(0.0, fgGetInt("/sim/startup/ysize")); 
126     glEnd();
127
128     // now draw the logo
129     glEnable(GL_TEXTURE_2D);
130     splash.bind();
131     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
132
133     glColor4f( 1.0, 1.0, 1.0, alpha );
134     glBegin(GL_POLYGON);
135     glTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin);
136     glTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin);
137     glTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax);
138     glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax); 
139     glEnd();
140
141     glutSwapBuffers();
142
143     glEnable(GL_DEPTH_TEST);
144     glEnable(GL_LIGHTING);
145     glDisable(GL_TEXTURE_2D);
146
147     glMatrixMode(GL_PROJECTION);
148     glPopMatrix();
149     glMatrixMode(GL_MODELVIEW);
150     glPopMatrix();
151 }
152
153