~ubuntu-branches/ubuntu/quantal/flightgear/quantal

« back to all changes in this revision

Viewing changes to src/Main/splash.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Ove Kaaven
  • Date: 2002-03-27 21:50:15 UTC
  • Revision ID: james.westby@ubuntu.com-20020327215015-0rvi3o8iml0a8s93
Tags: upstream-0.7.9
ImportĀ upstreamĀ versionĀ 0.7.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: splash.cxx,v 1.13 2001/05/15 20:30:40 curt Exp $
 
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 <GL/glut.h>
 
38
#include <GL/gl.h>
 
39
 
 
40
#include <string.h>
 
41
 
 
42
#include <simgear/debug/logstream.hxx>
 
43
#include <simgear/math/sg_random.h>
 
44
#include <simgear/misc/sg_path.hxx>
 
45
 
 
46
#include <Objects/texload.h>
 
47
 
 
48
#include "globals.hxx"
 
49
#include "fg_props.hxx"
 
50
#include "splash.hxx"
 
51
 
 
52
 
 
53
static GLuint splash_texid;
 
54
static GLubyte *splash_texbuf;
 
55
 
 
56
 
 
57
// Initialize the splash screen
 
58
void fgSplashInit ( void ) {
 
59
    int width, height;
 
60
 
 
61
    SG_LOG( SG_GENERAL, SG_INFO, "Initializing splash screen" );
 
62
#ifdef GL_VERSION_1_1
 
63
    glGenTextures(1, &splash_texid);
 
64
    glBindTexture(GL_TEXTURE_2D, splash_texid);
 
65
#elif GL_EXT_texture_object
 
66
    glGenTexturesEXT(1, &splash_texid);
 
67
    glBindTextureEXT(GL_TEXTURE_2D, splash_texid);
 
68
#else
 
69
#  error port me
 
70
#endif
 
71
 
 
72
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 
73
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);   
 
74
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 
75
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
76
 
 
77
    // load in the texture data
 
78
    int num = (int)(sg_random() * 4.0 + 1.0);
 
79
    char num_str[256];
 
80
    sprintf(num_str, "%d", num);
 
81
 
 
82
    SGPath tpath( globals->get_fg_root() );
 
83
    tpath.append( "Textures/Splash" );
 
84
    tpath.concat( num_str );
 
85
    tpath.concat( ".rgb" );
 
86
 
 
87
    if ( (splash_texbuf = 
 
88
          read_rgb_texture(tpath.c_str(), &width, &height)) == NULL )
 
89
    {
 
90
        // Try compressed
 
91
        SGPath fg_tpath = tpath;
 
92
        fg_tpath.concat( ".gz" );
 
93
        if ( (splash_texbuf = 
 
94
              read_rgb_texture(fg_tpath.c_str(), &width, &height)) == NULL )
 
95
        {
 
96
            SG_LOG( SG_GENERAL, SG_ALERT, 
 
97
                    "Error in loading splash screen texture " << tpath.str() );
 
98
            exit(-1);
 
99
        } 
 
100
    } 
 
101
 
 
102
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, 
 
103
                   GL_UNSIGNED_BYTE, (GLvoid *)(splash_texbuf) );
 
104
}
 
105
 
 
106
 
 
107
// Update the splash screen with progress specified from 0.0 to 1.0
 
108
void fgSplashUpdate ( double progress ) {
 
109
    int xmin, ymin, xmax, ymax;
 
110
    int xsize = 480;
 
111
    int ysize = 380;
 
112
 
 
113
    if ( !fgGetInt("/sim/startup/xsize")
 
114
         || !fgGetInt("/sim/startup/ysize") ) {
 
115
        return;
 
116
    }
 
117
 
 
118
    xmin = (fgGetInt("/sim/startup/xsize") - xsize) / 2;
 
119
    xmax = xmin + xsize;
 
120
 
 
121
    ymin = (fgGetInt("/sim/startup/ysize") - ysize) / 2;
 
122
    ymax = ymin + ysize;
 
123
 
 
124
    // first clear the screen;
 
125
    glClearColor(0.0, 0.0, 0.0, 1.0);
 
126
    glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
 
127
 
 
128
    // now draw the logo
 
129
    glMatrixMode(GL_PROJECTION);
 
130
    glPushMatrix();
 
131
    glLoadIdentity();
 
132
    gluOrtho2D(0, fgGetInt("/sim/startup/xsize"),
 
133
               0, fgGetInt("/sim/startup/ysize"));
 
134
    glMatrixMode(GL_MODELVIEW);
 
135
    glPushMatrix();
 
136
    glLoadIdentity();
 
137
 
 
138
    glDisable(GL_DEPTH_TEST);
 
139
    glDisable(GL_LIGHTING);
 
140
    glEnable(GL_TEXTURE_2D);
 
141
#ifdef GL_VERSION_1_1
 
142
    glBindTexture(GL_TEXTURE_2D, splash_texid);
 
143
#elif GL_EXT_texture_object
 
144
    glBindTextureEXT(GL_TEXTURE_2D, splash_texid);
 
145
#else
 
146
#  error port me
 
147
#endif
 
148
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
 
149
 
 
150
    glBegin(GL_POLYGON);
 
151
    glTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin);
 
152
    glTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin);
 
153
    glTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax);
 
154
    glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax); 
 
155
    glEnd();
 
156
 
 
157
    glutSwapBuffers();
 
158
 
 
159
    glEnable(GL_DEPTH_TEST);
 
160
    glEnable(GL_LIGHTING);
 
161
    glDisable(GL_TEXTURE_2D);
 
162
 
 
163
    glMatrixMode(GL_PROJECTION);
 
164
    glPopMatrix();
 
165
    glMatrixMode(GL_MODELVIEW);
 
166
    glPopMatrix();
 
167
}
 
168
 
 
169