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