]> git.mxchange.org Git - flightgear.git/blob - src/Main/splash.cxx
Initial revision
[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 FG_MATH_EXCEPTION_CLASH
30 #  include <math.h>
31 #endif
32
33 #ifdef HAVE_WINDOWS_H          
34 #  include <windows.h>
35 #endif
36
37 #include <GL/glut.h>
38 #include <XGL/xgl.h>
39
40 #include <string.h>
41
42 #include <Debug/logstream.hxx>
43 #include <Main/options.hxx>
44 #include <Math/fg_random.h>
45 #include <Misc/fgpath.hxx>
46 #include <Objects/texload.h>
47
48 #include "splash.hxx"
49 #include "views.hxx"
50
51
52 static GLuint splash_texid;
53 static GLubyte *splash_texbuf;
54
55
56 // Initialize the splash screen
57 void fgSplashInit ( void ) {
58     int width, height;
59
60     FG_LOG( FG_GENERAL, FG_INFO, "Initializing splash screen" );
61 #ifdef GL_VERSION_1_1
62     xglGenTextures(1, &splash_texid);
63     xglBindTexture(GL_TEXTURE_2D, splash_texid);
64 #elif GL_EXT_texture_object
65     xglGenTexturesEXT(1, &splash_texid);
66     xglBindTextureEXT(GL_TEXTURE_2D, splash_texid);
67 #else
68 #  error port me
69 #endif
70
71     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
72     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);   
73     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
74     xglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
75
76     // load in the texture data
77     int num = (int)(fg_random() * 4.0 + 1.0);
78     char num_str[256];
79     sprintf(num_str, "%d", num);
80
81     FGPath tpath( current_options.get_fg_root() );
82     tpath.append( "Textures/Splash" );
83     tpath.concat( num_str );
84     tpath.concat( ".rgb" );
85
86     if ( (splash_texbuf = 
87           read_rgb_texture(tpath.c_str(), &width, &height)) == NULL )
88     {
89         // Try compressed
90         FGPath fg_tpath = tpath;
91         fg_tpath.concat( ".gz" );
92         if ( (splash_texbuf = 
93               read_rgb_texture(fg_tpath.c_str(), &width, &height)) == NULL )
94         {
95             FG_LOG( FG_GENERAL, FG_ALERT, 
96                     "Error in loading splash screen texture " << tpath.str() );
97             exit(-1);
98         } 
99     } 
100
101     xglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, 
102                    GL_UNSIGNED_BYTE, (GLvoid *)(splash_texbuf) );
103 }
104
105
106 // Update the splash screen with progress specified from 0.0 to 1.0
107 void fgSplashUpdate ( double progress ) {
108     int xmin, ymin, xmax, ymax;
109     int xsize = 480;
110     int ysize = 380;
111
112     xmin = (current_view.get_winWidth() - xsize) / 2;
113     xmax = xmin + xsize;
114
115     ymin = (current_view.get_winHeight() - ysize) / 2;
116     ymax = ymin + ysize;
117
118     // first clear the screen;
119     xglClearColor(0.0, 0.0, 0.0, 1.0);
120     xglClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
121
122     // now draw the logo
123     xglMatrixMode(GL_PROJECTION);
124     xglPushMatrix();
125     xglLoadIdentity();
126     gluOrtho2D(0, current_view.get_winWidth(), 0, current_view.get_winHeight());
127     xglMatrixMode(GL_MODELVIEW);
128     xglPushMatrix();
129     xglLoadIdentity();
130
131     xglDisable(GL_DEPTH_TEST);
132     xglDisable(GL_LIGHTING);
133     xglEnable(GL_TEXTURE_2D);
134 #ifdef GL_VERSION_1_1
135     xglBindTexture(GL_TEXTURE_2D, splash_texid);
136 #elif GL_EXT_texture_object
137     xglBindTextureEXT(GL_TEXTURE_2D, splash_texid);
138 #else
139 #  error port me
140 #endif
141     xglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
142
143     xglBegin(GL_POLYGON);
144     xglTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin);
145     xglTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin);
146     xglTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax);
147     xglTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax); 
148     xglEnd();
149
150     xglutSwapBuffers();
151
152     xglEnable(GL_DEPTH_TEST);
153     xglEnable(GL_LIGHTING);
154     xglDisable(GL_TEXTURE_2D);
155
156     xglMatrixMode(GL_PROJECTION);
157     xglPopMatrix();
158     xglMatrixMode(GL_MODELVIEW);
159     xglPopMatrix();
160 }
161
162