]> git.mxchange.org Git - flightgear.git/blob - Simulator/Main/splash.cxx
Removed fg_config.h
[flightgear.git] / Simulator / 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 // (Log is kept at end of this file)
24
25
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 #ifdef HAVE_WINDOWS_H          
31 #  include <windows.h>
32 #endif
33
34 #include <GL/glut.h>
35 #include <XGL/xgl.h>
36
37 #include <string.h>
38
39 #include <Debug/logstream.hxx>
40 #include <Main/options.hxx>
41 #include <Math/fg_random.h>
42 #include <Objects/texload.h>
43
44 #include "splash.hxx"
45 #include "views.hxx"
46
47
48 static GLuint splash_texid;
49 static GLubyte *splash_texbuf;
50
51
52 // Initialize the splash screen
53 void fgSplashInit ( void ) {
54     string tpath, fg_tpath;
55     int width, height;
56
57     FG_LOG( FG_GENERAL, FG_INFO, "Initializing splash screen" );
58 #ifdef GL_VERSION_1_1
59     xglGenTextures(1, &splash_texid);
60     xglBindTexture(GL_TEXTURE_2D, splash_texid);
61 #elif GL_EXT_texture_object
62     xglGenTexturesEXT(1, &splash_texid);
63     xglBindTextureEXT(GL_TEXTURE_2D, splash_texid);
64 #else
65 #  error port me
66 #endif
67
68     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
69     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);   
70     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
71     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
72
73     // load in the texture data
74     int num = (int)(fg_random() * 4.0 + 1.0);
75     char num_str[256];
76     sprintf(num_str, "%d", num);
77     tpath = current_options.get_fg_root() + "/Textures/Splash";
78     tpath += num_str;
79     tpath += ".rgb";
80
81     if ( (splash_texbuf = 
82           read_rgb_texture(tpath.c_str(), &width, &height)) == NULL )
83     {
84         // Try compressed
85         fg_tpath = tpath + ".gz";
86         if ( (splash_texbuf = 
87               read_rgb_texture(fg_tpath.c_str(), &width, &height)) == NULL )
88         {
89             FG_LOG( FG_GENERAL, FG_ALERT, 
90                     "Error in loading splash screen texture " << tpath );
91             exit(-1);
92         } 
93     } 
94
95     xglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, 
96                    GL_UNSIGNED_BYTE, (GLvoid *)(splash_texbuf) );
97 }
98
99
100 // Update the splash screen with progress specified from 0.0 to 1.0
101 void fgSplashUpdate ( double progress ) {
102     int xmin, ymin, xmax, ymax;
103     int xsize = 480;
104     int ysize = 380;
105
106     xmin = (current_view.get_winWidth() - xsize) / 2;
107     xmax = xmin + xsize;
108
109     ymin = (current_view.get_winHeight() - ysize) / 2;
110     ymax = ymin + ysize;
111
112     // first clear the screen;
113     xglClearColor(0.0, 0.0, 0.0, 1.0);
114     xglClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
115
116     // now draw the logo
117     xglMatrixMode(GL_PROJECTION);
118     xglPushMatrix();
119     xglLoadIdentity();
120     gluOrtho2D(0, current_view.get_winWidth(), 0, current_view.get_winHeight());
121     xglMatrixMode(GL_MODELVIEW);
122     xglPushMatrix();
123     xglLoadIdentity();
124
125     xglDisable(GL_DEPTH_TEST);
126     xglDisable(GL_LIGHTING);
127     xglEnable(GL_TEXTURE_2D);
128 #ifdef GL_VERSION_1_1
129     xglBindTexture(GL_TEXTURE_2D, splash_texid);
130 #elif GL_EXT_texture_object
131     xglBindTextureEXT(GL_TEXTURE_2D, splash_texid);
132 #else
133 #  error port me
134 #endif
135     xglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
136
137     xglBegin(GL_POLYGON);
138     xglTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin);
139     xglTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin);
140     xglTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax);
141     xglTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax); 
142     xglEnd();
143
144     xglutSwapBuffers();
145
146     xglEnable(GL_DEPTH_TEST);
147     xglEnable(GL_LIGHTING);
148     xglDisable(GL_TEXTURE_2D);
149
150     xglMatrixMode(GL_PROJECTION);
151     xglPopMatrix();
152     xglMatrixMode(GL_MODELVIEW);
153     xglPopMatrix();
154 }
155
156
157 // $Log$
158 // Revision 1.1  1999/04/05 21:32:47  curt
159 // Initial revision
160 //
161 // Revision 1.10  1999/03/08 21:56:40  curt
162 // Added panel changes sent in by Friedemann.
163 // Added a splash screen randomization since we have several nice splash screens.
164 //
165 // Revision 1.9  1998/12/09 18:50:26  curt
166 // Converted "class fgVIEW" to "class FGView" and updated to make data
167 // members private and make required accessor functions.
168 //
169 // Revision 1.8  1998/11/16 14:00:05  curt
170 // Added pow() macro bug work around.
171 // Added support for starting FGFS at various resolutions.
172 // Added some initial serial port support.
173 // Specify default log levels in main().
174 //
175 // Revision 1.7  1998/11/06 21:18:14  curt
176 // Converted to new logstream debugging facility.  This allows release
177 // builds with no messages at all (and no performance impact) by using
178 // the -DFG_NDEBUG flag.
179 //
180 // Revision 1.6  1998/10/17 01:34:25  curt
181 // C++ ifying ...
182 //
183 // Revision 1.5  1998/09/26 13:17:29  curt
184 // Clear screen to "black" before drawing splash screen.
185 //
186 // Revision 1.4  1998/08/27 17:02:08  curt
187 // Contributions from Bernie Bright <bbright@c031.aone.net.au>
188 // - use strings for fg_root and airport_id and added methods to return
189 //   them as strings,
190 // - inlined all access methods,
191 // - made the parsing functions private methods,
192 // - deleted some unused functions.
193 // - propogated some of these changes out a bit further.
194 //
195 // Revision 1.3  1998/08/25 16:59:10  curt
196 // Directory reshuffling.
197 //
198 // Revision 1.2  1998/07/13 21:01:40  curt
199 // Wrote access functions for current fgOPTIONS.
200 //
201 // Revision 1.1  1998/07/06 02:42:36  curt
202 // Initial revision.
203 //
204