]> git.mxchange.org Git - flightgear.git/blob - src/Objects/newmat.hxx
Attempt to fix a segfault on exit, although I don't think this quite
[flightgear.git] / src / Objects / newmat.hxx
1 // newmat.hxx -- class to handle material properties
2 //
3 // Written by Curtis Olson, started May 1998.
4 //
5 // Copyright (C) 1998 - 2000  Curtis L. Olson  - curt@flightgear.org
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifndef _NEWMAT_HXX
25 #define _NEWMAT_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32 #ifdef HAVE_CONFIG_H
33 #  include <config.h>
34 #endif
35
36 #ifdef HAVE_WINDOWS_H
37 #  include <windows.h>
38 #endif
39
40 #include <plib/sg.h>
41 #include <plib/ssg.h>
42
43 #include <simgear/compiler.h>
44
45 #include <GL/glut.h>
46
47 #include STL_STRING      // Standard C++ string library
48
49 SG_USING_STD(string);
50
51
52 // MSVC++ 6.0 kuldge - Need forward declaration of friends.
53 class FGNewMat;
54 istream& operator >> ( istream& in, FGNewMat& m );
55
56 // Material property class
57 class FGNewMat {
58
59 private:
60
61     // names
62     string material_name;
63     string texture_name;
64
65     // pointers to ssg states
66     ssgStateSelector *state;
67     ssgSimpleState *textured;
68     ssgSimpleState *nontextured;
69
70     // alpha texture?
71     int alpha;
72
73     // texture size
74     double xsize, ysize;
75
76     // wrap texture?
77     int wrapu, wrapv;
78
79     // use mipmapping?
80     int mipmap;
81
82     // coverage of night lighting.  This number is specifically the
83     // amount of area coverage we give a single light.  The size of a
84     // triangle is divided by this number and that is the number of
85     // lights assigned to that triangle.  Lower numbers mean more
86     // dense light ocverage.
87     double light_coverage;
88
89     // material properties
90     sgVec4 ambient, diffuse, specular, emission;
91
92     // true if texture loading deferred, and not yet loaded
93     bool texture_loaded;
94
95 public:
96
97     // Constructor
98     FGNewMat ( void );
99     FGNewMat ( const string& name );
100     FGNewMat ( const string &mat_name, const string &tex_name );
101
102     // Destructor
103     ~FGNewMat ( void );
104
105     friend istream& operator >> ( istream& in, FGNewMat& m );
106
107     // void load_texture( const string& root );
108     void build_ssg_state( GLenum shade_model, bool texture_default,
109                           bool defer_tex_load = false );
110     void set_ssg_state( ssgSimpleState *s );
111
112     inline string get_material_name() const { return material_name; }
113     inline void set_material_name( const string& n ) { material_name = n; }
114
115     inline string get_texture_name() const { return texture_name; }
116     inline const char *get_texture_name_c_str() const {
117         return texture_name.c_str();
118     }
119     inline void set_texture_name( const string& n ) { texture_name = n; }
120
121     inline ssgSimpleState *get_textured() { return textured; }
122
123     inline double get_xsize() const { return xsize; }
124     inline double get_ysize() const { return ysize; }
125     inline void set_xsize( double x ) { xsize = x; }
126     inline void set_ysize( double y ) { ysize = y; }
127
128     inline float *get_ambient() { return ambient; }
129     inline float *get_diffuse() { return diffuse; }
130     inline float *get_specular() { return specular; }
131     inline float *get_emission() { return emission; }
132     inline void set_ambient( sgVec4 a ) { sgCopyVec4( ambient, a ); }
133     inline void set_diffuse( sgVec4 d ) { sgCopyVec4( diffuse, d ); }
134     inline void set_specular( sgVec4 s ) { sgCopyVec4( specular, s ); }
135     inline void set_emission( sgVec4 e ) { sgCopyVec4( emission, e ); }
136
137     inline bool get_texture_loaded() const { return texture_loaded; }
138     inline void set_texture_loaded( bool val ) { texture_loaded = val; }
139
140     inline double get_light_coverage () const { return light_coverage; }
141     inline void set_light_coverage (double coverage) {
142         light_coverage = coverage;
143     }
144
145     inline ssgStateSelector *get_state() const { return state; }
146
147     void dump_info();
148 };
149
150
151 #endif // _NEWMAT_HXX 
152
153