]> git.mxchange.org Git - flightgear.git/blob - Objects/obj.cxx
Tweaks for building with native SGI compilers.
[flightgear.git] / Objects / obj.cxx
1 // obj.cxx -- routines to handle "sorta" WaveFront .obj format files.
2 //
3 // Written by Curtis Olson, started October 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
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 // (Log is kept at end of this file)
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 <stdio.h>
34 #include <string.h>
35 #include <GL/glut.h>
36 #include <XGL/xgl.h>
37
38 // #if defined ( __sun__ )
39 // extern "C" void *memmove(void *, const void *, size_t);
40 // extern "C" void *memset(void *, int, size_t);
41 // #endif
42
43 #include <Include/compiler.h>
44
45 #include STL_STRING
46 #include <map>          // STL
47 #include <ctype.h>      // isdigit()
48
49 #include <Debug/logstream.hxx>
50 #include <Misc/fgstream.hxx>
51 #include <Include/fg_constants.h>
52 #include <Main/options.hxx>
53 #include <Math/mat3.h>
54 #include <Math/fg_random.h>
55 #include <Math/point3d.hxx>
56 #include <Math/polar3d.hxx>
57 #include <Misc/stopwatch.hxx>
58 #include <Scenery/tile.hxx>
59
60 #include "material.hxx"
61 #include "obj.hxx"
62
63 FG_USING_STD(string);
64
65
66 static double normals[MAX_NODES][3];
67
68
69 // given three points defining a triangle, calculate the normal
70 static void calc_normal(double p1[3], double p2[3], 
71                         double p3[3], double normal[3])
72 {
73     double v1[3], v2[3];
74     double temp;
75
76     v1[0] = p2[0] - p1[0]; v1[1] = p2[1] - p1[1]; v1[2] = p2[2] - p1[2];
77     v2[0] = p3[0] - p1[0]; v2[1] = p3[1] - p1[1]; v2[2] = p3[2] - p1[2];
78
79     MAT3cross_product(normal, v1, v2);
80     MAT3_NORMALIZE_VEC(normal,temp);
81
82     // fgPrintf( FG_TERRAIN, FG_DEBUG, "  Normal = %.2f %.2f %.2f\n", 
83     //           normal[0], normal[1], normal[2]);
84 }
85
86
87 #define FG_TEX_CONSTANT 69.0
88
89
90 // Calculate texture coordinates for a given point.
91 static Point3D calc_tex_coords(double *node, const Point3D& ref) {
92     Point3D cp;
93     Point3D pp;
94     // double tmplon, tmplat;
95
96     // cout << "-> " << node[0] << " " << node[1] << " " << node[2] << endl;
97     // cout << "-> " << ref.x() << " " << ref.y() << " " << ref.z() << endl;
98
99     cp = Point3D( node[0] + ref.x(),
100                   node[1] + ref.y(),
101                   node[2] + ref.z() );
102
103     pp = fgCartToPolar3d(cp);
104
105     // tmplon = pp.lon() * RAD_TO_DEG;
106     // tmplat = pp.lat() * RAD_TO_DEG;
107     // cout << tmplon << " " << tmplat << endl;
108
109     pp.setx( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.x(), 11.0) );
110     pp.sety( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.y(), 11.0) );
111
112     if ( pp.x() < 0.0 ) {
113         pp.setx( pp.x() + 11.0 );
114     }
115
116     if ( pp.y() < 0.0 ) {
117         pp.sety( pp.y() + 11.0 );
118     }
119
120     // cout << pp << endl;
121
122     return(pp);
123 }
124
125
126 // Load a .obj file and build the GL fragment list
127 int fgObjLoad( const string& path, fgTILE *t) {
128     fgFRAGMENT fragment;
129     Point3D pp;
130     double approx_normal[3], normal[3], scale;
131     // double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
132     // GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
133     GLint display_list;
134     int shading;
135     int in_fragment, in_faces, vncount, n1, n2, n3, n4;
136     int last1, last2, odd;
137     double (*nodes)[3];
138     Point3D center;
139
140     // printf("loading %s\n", path.c_str() );
141
142     // Attempt to open "path.gz" or "path"
143     fg_gzifstream in( path );
144     if ( ! in )
145     {
146         // Attempt to open "path.obj" or "path.obj.gz"
147         in.open( path + ".obj" );
148         if ( ! in )
149         {
150             FG_LOG( FG_TERRAIN, FG_ALERT, "Cannot open file: " << path );
151             return 0;
152         }
153     }
154
155     shading = current_options.get_shading();
156
157     in_fragment = 0;
158     t->ncount = 1;
159     vncount = 1;
160     t->bounding_radius = 0.0;
161     nodes = t->nodes;
162     center = t->center;
163
164     StopWatch stopwatch;
165     stopwatch.start();
166
167     // ignore initial comments and blank lines. (priming the pump)
168     in >> skipcomment;
169
170     while ( ! in.eof() )
171     {
172
173         string token;
174         in >> token;
175
176         // printf("token = %s\n", token.c_str() );
177
178         if ( token == "gbs" )
179         {
180             // reference point (center offset)
181             in >> t->center >> t->bounding_radius;
182             center = t->center;
183         }
184         else if ( token == "bs" )
185         {
186             // reference point (center offset)
187             in >> fragment.center;
188             in >> fragment.bounding_radius;
189         }
190         else if ( token == "vn" )
191         {
192             // vertex normal
193             if ( vncount < MAX_NODES ) {
194                 in >> normals[vncount][0]
195                    >> normals[vncount][1]
196                    >> normals[vncount][2];
197                 vncount++;
198             } else {
199                 FG_LOG( FG_TERRAIN, FG_ALERT, 
200                         "Read too many vertex normals ... dying :-(" );
201                 exit(-1);
202             }
203         }
204         else if ( token[0] == 'v' )
205         {
206             // node (vertex)
207             if ( t->ncount < MAX_NODES ) {
208                 in >> t->nodes[t->ncount][0]
209                    >> t->nodes[t->ncount][1]
210                    >> t->nodes[t->ncount][2];
211                 t->ncount++;
212             } else {
213                 FG_LOG( FG_TERRAIN, FG_ALERT, 
214                         "Read too many nodes ... dying :-(");
215                 exit(-1);
216             }
217         }
218         else if ( token == "usemtl" )
219         {
220             // material property specification
221
222             // this also signals the start of a new fragment
223             if ( in_fragment ) {
224                 // close out the previous structure and start the next
225                 xglEnd();
226                 xglEndList();
227                 // printf("xglEnd(); xglEndList();\n");
228
229                 // update fragment
230                 fragment.display_list = display_list;
231
232                 // push this fragment onto the tile's object list
233                 t->fragment_list.push_back(fragment);
234             } else {
235                 in_fragment = 1;
236             }
237
238             // printf("start of fragment (usemtl)\n");
239
240             display_list = xglGenLists(1);
241             xglNewList(display_list, GL_COMPILE);
242             // printf("xglGenLists(); xglNewList();\n");
243             in_faces = 0;
244
245             // reset the existing face list
246             // printf("cleaning a fragment with %d faces\n", 
247             //        fragment.faces.size());
248             fragment.init();
249
250             // scan the material line
251             string material;
252             in >> material;
253             fragment.tile_ptr = t;
254
255             // find this material in the properties list
256             if ( ! material_mgr.find( material, fragment.material_ptr )) {
257                 FG_LOG( FG_TERRAIN, FG_ALERT, 
258                         "Ack! unknown usemtl name = " << material 
259                         << " in " << path );
260             }
261
262             // initialize the fragment transformation matrix
263             /*
264             for ( i = 0; i < 16; i++ ) {
265                 fragment.matrix[i] = 0.0;
266             }
267             fragment.matrix[0] = fragment.matrix[5] =
268                 fragment.matrix[10] = fragment.matrix[15] = 1.0;
269             */
270         } else if ( token[0] == 't' ) {
271             // start a new triangle strip
272
273             n1 = n2 = n3 = n4 = 0;
274
275             // fgPrintf( FG_TERRAIN, FG_DEBUG, "    new tri strip = %s", line);
276             in >> n1 >> n2 >> n3;
277             fragment.add_face(n1, n2, n3);
278
279             // fgPrintf( FG_TERRAIN, FG_DEBUG, "(t) = ");
280
281             xglBegin(GL_TRIANGLE_STRIP);
282             // printf("xglBegin(tristrip) %d %d %d\n", n1, n2, n3);
283
284             odd = 1; 
285             scale = 1.0;
286
287             if ( shading ) {
288                 // Shading model is "GL_SMOOTH" so use precalculated
289                 // (averaged) normals
290                 MAT3_SCALE_VEC(normal, normals[n1], scale);
291                 xglNormal3dv(normal);
292                 pp = calc_tex_coords(nodes[n1], center);
293                 xglTexCoord2f(pp.lon(), pp.lat());
294                 // xglVertex3d(t->nodes[n1][0],t->nodes[n1][1],t->nodes[n1][2]);
295                 xglVertex3dv(nodes[n1]);                
296
297                 MAT3_SCALE_VEC(normal, normals[n2], scale);
298                 xglNormal3dv(normal);
299                 pp = calc_tex_coords(nodes[n2], center);
300                 xglTexCoord2f(pp.lon(), pp.lat());
301                 //xglVertex3d(t->nodes[n2][0],t->nodes[n2][1],t->nodes[n2][2]);
302                 xglVertex3dv(nodes[n2]);                                
303
304                 MAT3_SCALE_VEC(normal, normals[n3], scale);
305                 xglNormal3dv(normal);
306                 pp = calc_tex_coords(nodes[n3], center);
307                 xglTexCoord2f(pp.lon(), pp.lat());
308                 // xglVertex3d(t->nodes[n3][0],t->nodes[n3][1],t->nodes[n3][2]);
309                 xglVertex3dv(nodes[n3]);
310             } else {
311                 // Shading model is "GL_FLAT" so calculate per face
312                 // normals on the fly.
313                 if ( odd ) {
314                     calc_normal(nodes[n1], nodes[n2], 
315                                 nodes[n3], approx_normal);
316                 } else {
317                     calc_normal(nodes[n2], nodes[n1], 
318                                 nodes[n3], approx_normal);
319                 }
320                 MAT3_SCALE_VEC(normal, approx_normal, scale);
321                 xglNormal3dv(normal);
322
323                 pp = calc_tex_coords(nodes[n1], center);
324                 xglTexCoord2f(pp.lon(), pp.lat());
325                 // xglVertex3d(t->nodes[n1][0],t->nodes[n1][1],t->nodes[n1][2]);
326                 xglVertex3dv(nodes[n1]);                
327
328                 pp = calc_tex_coords(nodes[n2], center);
329                 xglTexCoord2f(pp.lon(), pp.lat());
330                 // xglVertex3d(t->nodes[n2][0],t->nodes[n2][1],t->nodes[n2][2]);
331                 xglVertex3dv(nodes[n2]);                
332
333                 pp = calc_tex_coords(nodes[n3], center);
334                 xglTexCoord2f(pp.lon(), pp.lat());
335                 // xglVertex3d(t->nodes[n3][0],t->nodes[n3][1],t->nodes[n3][2]);
336                 xglVertex3dv(nodes[n3]);                
337             }
338             // printf("some normals, texcoords, and vertices\n");
339
340             odd = 1 - odd;
341             last1 = n2;
342             last2 = n3;
343
344             // There can be three or four values 
345             char c;
346             while ( in.get(c) )
347             {
348                 if ( c == '\n' )
349                     break; // only the one
350
351                 if ( isdigit(c) )
352                 {
353                     in.putback(c);
354                     in >> n4;
355                     break;
356                 }
357             }
358
359             if ( n4 > 0 ) {
360                 fragment.add_face(n3, n2, n4);
361
362                 if ( shading ) {
363                     // Shading model is "GL_SMOOTH"
364                     MAT3_SCALE_VEC(normal, normals[n4], scale);
365                 } else {
366                     // Shading model is "GL_FLAT"
367                     calc_normal(nodes[n3], nodes[n2], nodes[n4], 
368                                 approx_normal);
369                     MAT3_SCALE_VEC(normal, approx_normal, scale);
370                 }
371                 xglNormal3dv(normal);
372                 pp = calc_tex_coords(nodes[n4], center);
373                 xglTexCoord2f(pp.lon(), pp.lat());
374                 // xglVertex3d(t->nodes[n4][0],t->nodes[n4][1],t->nodes[n4][2]);
375                 xglVertex3dv(nodes[n4]);                
376
377                 odd = 1 - odd;
378                 last1 = n3;
379                 last2 = n4;
380                 // printf("a normal, texcoord, and vertex (4th)\n");
381             }
382         } else if ( token[0] == 'f' ) {
383             // unoptimized face
384
385             if ( !in_faces ) {
386                 xglBegin(GL_TRIANGLES);
387                 // printf("xglBegin(triangles)\n");
388                 in_faces = 1;
389             }
390
391             // fgPrintf( FG_TERRAIN, FG_DEBUG, "new triangle = %s", line);*/
392             in >> n1 >> n2 >> n3;
393             fragment.add_face(n1, n2, n3);
394
395             // xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
396             xglNormal3dv(normals[n1]);
397             pp = calc_tex_coords(nodes[n1], center);
398             xglTexCoord2f(pp.lon(), pp.lat());
399             // xglVertex3d(t->nodes[n1][0], t->nodes[n1][1], t->nodes[n1][2]);
400             xglVertex3dv(nodes[n1]);
401
402             // xglNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]);
403             xglNormal3dv(normals[n2]);
404             pp = calc_tex_coords(nodes[n2], center);
405             xglTexCoord2f(pp.lon(), pp.lat());
406             // xglVertex3d(t->nodes[n2][0], t->nodes[n2][1], t->nodes[n2][2]);
407             xglVertex3dv(nodes[n2]);
408                 
409             // xglNormal3d(normals[n3][0], normals[n3][1], normals[n3][2]);
410             xglNormal3dv(normals[n3]);
411             pp = calc_tex_coords(nodes[n3], center);
412             xglTexCoord2f(pp.lon(), pp.lat());
413             // xglVertex3d(t->nodes[n3][0], t->nodes[n3][1], t->nodes[n3][2]);
414             xglVertex3dv(nodes[n3]);
415             // printf("some normals, texcoords, and vertices (tris)\n");
416         } else if ( token[0] == 'q' ) {
417             // continue a triangle strip
418             n1 = n2 = 0;
419
420             // fgPrintf( FG_TERRAIN, FG_DEBUG, "continued tri strip = %s ", 
421             //           line);
422             in >> n1;
423
424             // There can be one or two values 
425             char c;
426             while ( in.get(c) )
427             {
428                 if ( c == '\n' )
429                     break; // only the one
430
431                 if ( isdigit(c) )
432                 {
433                     in.putback(c);
434                     in >> n2;
435                     break;
436                 }
437             }
438             // fgPrintf( FG_TERRAIN, FG_DEBUG, "read %d %d\n", n1, n2);
439
440             if ( odd ) {
441                 fragment.add_face(last1, last2, n1);
442             } else {
443                 fragment.add_face(last2, last1, n1);
444             }
445
446             if ( shading ) {
447                 // Shading model is "GL_SMOOTH"
448                 MAT3_SCALE_VEC(normal, normals[n1], scale);
449             } else {
450                 // Shading model is "GL_FLAT"
451                 if ( odd ) {
452                     calc_normal(nodes[last1], nodes[last2], nodes[n1], 
453                                 approx_normal);
454                 } else {
455                     calc_normal(nodes[last2], nodes[last1], nodes[n1], 
456                                 approx_normal);
457                 }
458                 MAT3_SCALE_VEC(normal, approx_normal, scale);
459             }
460             xglNormal3dv(normal);
461
462             pp = calc_tex_coords(nodes[n1], center);
463             xglTexCoord2f(pp.lon(), pp.lat());
464             // xglVertex3d(t->nodes[n1][0], t->nodes[n1][1], t->nodes[n1][2]);
465             xglVertex3dv(nodes[n1]);
466             // printf("a normal, texcoord, and vertex (4th)\n");
467    
468             odd = 1 - odd;
469             last1 = last2;
470             last2 = n1;
471
472             if ( n2 > 0 ) {
473                 // fgPrintf( FG_TERRAIN, FG_DEBUG, " (cont)\n");
474
475                 if ( odd ) {
476                     fragment.add_face(last1, last2, n2);
477                 } else {
478                     fragment.add_face(last2, last1, n2);
479                 }
480
481                 if ( shading ) {
482                     // Shading model is "GL_SMOOTH"
483                     MAT3_SCALE_VEC(normal, normals[n2], scale);
484                 } else {
485                     // Shading model is "GL_FLAT"
486                     if ( odd ) {
487                         calc_normal(nodes[last1], nodes[last2], 
488                                     nodes[n2], approx_normal);
489                     } else {
490                         calc_normal(nodes[last2], nodes[last1], 
491                                     nodes[n2], approx_normal);
492                     }
493                     MAT3_SCALE_VEC(normal, approx_normal, scale);
494                 }
495                 xglNormal3dv(normal);
496                 
497                 pp = calc_tex_coords(nodes[n2], center);
498                 xglTexCoord2f(pp.lon(), pp.lat());
499                 // xglVertex3d(t->nodes[n2][0],t->nodes[n2][1],t->nodes[n2][2]);
500                 xglVertex3dv(nodes[n2]);                
501                 // printf("a normal, texcoord, and vertex (4th)\n");
502
503                 odd = 1 -odd;
504                 last1 = last2;
505                 last2 = n2;
506             }
507         } else {
508             FG_LOG( FG_TERRAIN, FG_WARN, "Unknown token in " 
509                     << path << " = " << token );
510         }
511
512         // eat comments and blank lines before start of while loop so
513         // if we are done with useful input it is noticed before hand.
514         in >> skipcomment;
515     }
516
517     if ( in_fragment ) {
518         // close out the previous structure and start the next
519         xglEnd();
520         xglEndList();
521         // printf("xglEnd(); xglEndList();\n");
522
523         // update fragment
524         fragment.display_list = display_list;
525         
526         // push this fragment onto the tile's object list
527         t->fragment_list.push_back(fragment);
528     }
529
530     // Draw normal vectors (for visually verifying normals)
531     /*
532     xglBegin(GL_LINES);
533     xglColor3f(0.0, 0.0, 0.0);
534     for ( i = 0; i < t->ncount; i++ ) {
535         xglVertex3d(t->nodes[i][0],
536                     t->nodes[i][1] ,
537                     t->nodes[i][2]);
538         xglVertex3d(t->nodes[i][0] + 500*normals[i][0],
539                     t->nodes[i][1] + 500*normals[i][1],
540                     t->nodes[i][2] + 500*normals[i][2]);
541     } 
542     xglEnd();
543     */   
544
545     stopwatch.stop();
546     FG_LOG( FG_TERRAIN, FG_INFO, 
547             "Loaded " << path << " in " 
548             << stopwatch.elapsedSeconds() << " seconds" );
549
550     // printf("end of tile\n");
551
552     return(1);
553 }
554
555
556 // $Log$
557 // Revision 1.12  1999/03/02 01:03:25  curt
558 // Tweaks for building with native SGI compilers.
559 //
560 // Revision 1.11  1999/02/26 22:09:59  curt
561 // Added initial support for native SGI compilers.
562 //
563 // Revision 1.10  1998/11/06 21:18:18  curt
564 // Converted to new logstream debugging facility.  This allows release
565 // builds with no messages at all (and no performance impact) by using
566 // the -DFG_NDEBUG flag.
567 //
568 // Revision 1.9  1998/11/06 14:47:06  curt
569 // Changes to track Bernie's updates to fgstream.
570 //
571 // Revision 1.8  1998/10/20 18:33:55  curt
572 // Tweaked texture coordinates, but we still have some problems. :-(
573 //
574 // Revision 1.7  1998/10/20 15:48:44  curt
575 // Removed an extraneous output message.
576 //
577 // Revision 1.6  1998/10/18 01:17:21  curt
578 // Point3D tweaks.
579 //
580 // Revision 1.5  1998/10/16 00:54:39  curt
581 // Converted to Point3D class.
582 //
583 // Revision 1.4  1998/09/15 01:35:07  curt
584 // cleaned up my fragment.num_faces hack :-) to use the STL (no need in
585 // duplicating work.)
586 // Tweaked fgTileMgrRender() do not calc tile matrix unless necessary.
587 // removed some unneeded stuff from fgTileMgrCurElev()
588 //
589 // Revision 1.3  1998/09/03 21:27:03  curt
590 // Fixed a serious bug caused by not-quite-correct comment/white space eating
591 // which resulted in mismatched glBegin() glEnd() pairs, incorrect display lists,
592 // and ugly display artifacts.
593 //
594 // Revision 1.2  1998/09/01 19:03:09  curt
595 // Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
596 //  - The new classes in libmisc.tgz define a stream interface into zlib.
597 //    I've put these in a new directory, Lib/Misc.  Feel free to rename it
598 //    to something more appropriate.  However you'll have to change the
599 //    include directives in all the other files.  Additionally you'll have
600 //    add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
601 //
602 //    The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
603 //    test so I've included the required changes in config.tgz.
604 //
605 //    There are a fair few changes to Simulator/Objects as I've moved
606 //    things around.  Loading tiles is quicker but thats not where the delay
607 //    is.  Tile loading takes a few tenths of a second per file on a P200
608 //    but it seems to be the post-processing that leads to a noticeable
609 //    blip in framerate.  I suppose its time to start profiling to see where
610 //    the delays are.
611 //
612 //    I've included a brief description of each archives contents.
613 //
614 // Lib/Misc/
615 //   zfstream.cxx
616 //   zfstream.hxx
617 //     C++ stream interface into zlib.
618 //     Taken from zlib-1.1.3/contrib/iostream/.
619 //     Minor mods for STL compatibility.
620 //     There's no copyright associated with these so I assume they're
621 //     covered by zlib's.
622 //
623 //   fgstream.cxx
624 //   fgstream.hxx
625 //     FlightGear input stream using gz_ifstream.  Tries to open the
626 //     given filename.  If that fails then filename is examined and a
627 //     ".gz" suffix is removed or appended and that file is opened.
628 //
629 //   stopwatch.hxx
630 //     A simple timer for benchmarking.  Not used in production code.
631 //     Taken from the Blitz++ project.  Covered by GPL.
632 //
633 //   strutils.cxx
634 //   strutils.hxx
635 //     Some simple string manipulation routines.
636 //
637 // Simulator/Airports/
638 //   Load airports database using fgstream.
639 //   Changed fgAIRPORTS to use set<> instead of map<>.
640 //   Added bool fgAIRPORTS::search() as a neater way doing the lookup.
641 //   Returns true if found.
642 //
643 // Simulator/Astro/
644 //   Modified fgStarsInit() to load stars database using fgstream.
645 //
646 // Simulator/Objects/
647 //   Modified fgObjLoad() to use fgstream.
648 //   Modified fgMATERIAL_MGR::load_lib() to use fgstream.
649 //   Many changes to fgMATERIAL.
650 //   Some changes to fgFRAGMENT but I forget what!
651 //
652 // Revision 1.1  1998/08/25 16:51:25  curt
653 // Moved from ../Scenery
654 //
655 // Revision 1.23  1998/08/20 15:16:43  curt
656 // obj.cxx: use more explicit parenthases.
657 // texload.[ch]: use const in function definitions where appropriate.
658 //
659 // Revision 1.22  1998/08/20 15:12:03  curt
660 // Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
661 // the need for "void" pointers and casts.
662 // Quick hack to count the number of scenery polygons that are being drawn.
663 //
664 // Revision 1.21  1998/08/12 21:13:04  curt
665 // material.cxx: don't load textures if they are disabled
666 // obj.cxx: optimizations from Norman Vine
667 // tile.cxx: minor tweaks
668 // tile.hxx: addition of num_faces
669 // tilemgr.cxx: minor tweaks
670 //
671 // Revision 1.20  1998/07/24 21:42:07  curt
672 // material.cxx: whups, double method declaration with no definition.
673 // obj.cxx: tweaks to avoid errors in SGI's CC.
674 // tile.cxx: optimizations by Norman Vine.
675 // tilemgr.cxx: optimizations by Norman Vine.
676 //
677 // Revision 1.19  1998/07/13 21:01:58  curt
678 // Wrote access functions for current fgOPTIONS.
679 //
680 // Revision 1.18  1998/07/12 03:18:27  curt
681 // Added ground collision detection.  This involved:
682 // - saving the entire vertex list for each tile with the tile records.
683 // - saving the face list for each fragment with the fragment records.
684 // - code to intersect the current vertical line with the proper face in
685 //   an efficient manner as possible.
686 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
687 //
688 // Revision 1.17  1998/07/08 14:47:21  curt
689 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
690 // polare3d.h renamed to polar3d.hxx
691 // fg{Cartesian,Polar}Point3d consolodated.
692 // Added some initial support for calculating local current ground elevation.
693 //
694 // Revision 1.16  1998/07/06 21:34:33  curt
695 // Added using namespace std for compilers that support this.
696 //
697 // Revision 1.15  1998/07/04 00:54:28  curt
698 // Added automatic mipmap generation.
699 //
700 // When rendering fragments, use saved model view matrix from associated tile
701 // rather than recalculating it with push() translate() pop().
702 //
703 // Revision 1.14  1998/06/17 21:36:40  curt
704 // Load and manage multiple textures defined in the Materials library.
705 // Boost max material fagments for each material property to 800.
706 // Multiple texture support when rendering.
707 //
708 // Revision 1.13  1998/06/12 00:58:05  curt
709 // Build only static libraries.
710 // Declare memmove/memset for Sloaris.
711 //
712 // Revision 1.12  1998/06/08 17:57:54  curt
713 // Working first pass at material proporty sorting.
714 //
715 // Revision 1.11  1998/06/06 01:09:31  curt
716 // I goofed on the log message in the last commit ... now fixed.
717 //
718 // Revision 1.10  1998/06/06 01:07:17  curt
719 // Increased per material fragment list size from 100 to 400.
720 // Now correctly draw viewable fragments in per material order.
721 //
722 // Revision 1.9  1998/06/05 22:39:54  curt
723 // Working on sorting by, and rendering by material properties.
724 //
725 // Revision 1.8  1998/06/05 18:19:18  curt
726 // Recognize file, file.gz, and file.obj as scenery object files.
727 //
728 // Revision 1.7  1998/05/24 02:49:09  curt
729 // Implimented fragment level view frustum culling.
730 //
731 // Revision 1.6  1998/05/23 14:09:20  curt
732 // Added tile.cxx and tile.hxx.
733 // Working on rewriting the tile management system so a tile is just a list
734 // fragments, and the fragment record contains the display list for that 
735 // fragment.
736 //
737 // Revision 1.5  1998/05/20 20:53:53  curt
738 // Moved global ref point and radius (bounding sphere info, and offset) to
739 // data file rather than calculating it on the fly.
740 // Fixed polygon winding problem in scenery generation stage rather than
741 // compensating for it on the fly.
742 // Made a fgTILECACHE class.
743 //
744 // Revision 1.4  1998/05/16 13:09:57  curt
745 // Beginning to add support for view frustum culling.
746 // Added some temporary code to calculate bouding radius, until the
747 //   scenery generation tools and scenery can be updated.
748 //
749 // Revision 1.3  1998/05/03 00:48:01  curt
750 // Updated texture coordinate fmod() parameter.
751 //
752 // Revision 1.2  1998/05/02 01:52:14  curt
753 // Playing around with texture coordinates.
754 //
755 // Revision 1.1  1998/04/30 12:35:28  curt
756 // Added a command line rendering option specify smooth/flat shading.
757 //
758 // Revision 1.35  1998/04/28 21:43:26  curt
759 // Wrapped zlib calls up so we can conditionally comment out zlib support.
760 //
761 // Revision 1.34  1998/04/28 01:21:42  curt
762 // Tweaked texture parameter calculations to keep the number smaller.  This
763 // avoids the "swimming" problem.
764 // Type-ified fgTIME and fgVIEW.
765 //
766 // Revision 1.33  1998/04/27 15:58:15  curt
767 // Screwing around with texture coordinate generation ... still needs work.
768 //
769 // Revision 1.32  1998/04/27 03:30:13  curt
770 // Minor transformation adjustments to try to keep scenery tiles closer to
771 // (0, 0, 0)  GLfloats run out of precision at the distances we need to model
772 // the earth, but we can do a bunch of pre-transformations using double math
773 // and then cast to GLfloat once everything is close in where we have less
774 // precision problems.
775 //
776 // Revision 1.31  1998/04/25 15:09:57  curt
777 // Changed "r" to "rb" in gzopen() options.  This fixes bad behavior in win32.
778 //
779 // Revision 1.30  1998/04/24 14:21:08  curt
780 // Added "file.obj.gz" support.
781 //
782 // Revision 1.29  1998/04/24 00:51:07  curt
783 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
784 // Tweaked the scenery file extentions to be "file.obj" (uncompressed)
785 // or "file.obz" (compressed.)
786 //
787 // Revision 1.28  1998/04/22 13:22:44  curt
788 // C++ - ifing the code a bit.
789 //
790 // Revision 1.27  1998/04/18 04:13:17  curt
791 // Added zlib on the fly decompression support for loading scenery objects.
792 //
793 // Revision 1.26  1998/04/03 22:11:36  curt
794 // Converting to Gnu autoconf system.
795 //
796 // Revision 1.25  1998/03/14 00:30:50  curt
797 // Beginning initial terrain texturing experiments.
798 //
799 // Revision 1.24  1998/02/09 21:30:18  curt
800 // Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
801 //
802 // Revision 1.23  1998/02/09 15:07:52  curt
803 // Minor tweaks.
804 //
805 // Revision 1.22  1998/02/01 03:39:54  curt
806 // Minor tweaks.
807 //
808 // Revision 1.21  1998/01/31 00:43:25  curt
809 // Added MetroWorks patches from Carmen Volpe.
810 //
811 // Revision 1.20  1998/01/29 00:51:39  curt
812 // First pass at tile cache, dynamic tile loading and tile unloading now works.
813 //
814 // Revision 1.19  1998/01/27 03:26:42  curt
815 // Playing with new fgPrintf command.
816 //
817 // Revision 1.18  1998/01/19 19:27:16  curt
818 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
819 // This should simplify things tremendously.
820 //
821 // Revision 1.17  1998/01/13 00:23:10  curt
822 // Initial changes to support loading and management of scenery tiles.  Note,
823 // there's still a fair amount of work left to be done.
824 //
825 // Revision 1.16  1997/12/30 23:09:40  curt
826 // Worked on winding problem without luck, so back to calling glFrontFace()
827 // 3 times for each scenery area.
828 //
829 // Revision 1.15  1997/12/30 20:47:51  curt
830 // Integrated new event manager with subsystem initializations.
831 //
832 // Revision 1.14  1997/12/30 01:38:46  curt
833 // Switched back to per vertex normals and smooth shading for terrain.
834 //
835 // Revision 1.13  1997/12/18 23:32:36  curt
836 // First stab at sky dome actually starting to look reasonable. :-)
837 //
838 // Revision 1.12  1997/12/17 23:13:47  curt
839 // Began working on rendering the sky.
840 //
841 // Revision 1.11  1997/12/15 23:55:01  curt
842 // Add xgl wrappers for debugging.
843 // Generate terrain normals on the fly.
844 //
845 // Revision 1.10  1997/12/12 21:41:28  curt
846 // More light/material property tweaking ... still a ways off.
847 //
848 // Revision 1.9  1997/12/12 19:52:57  curt
849 // Working on lightling and material properties.
850 //
851 // Revision 1.8  1997/12/10 01:19:51  curt
852 // Tweaks for verion 0.15 release.
853 //
854 // Revision 1.7  1997/12/08 22:51:17  curt
855 // Enhanced to handle ccw and cw tri-stripe winding.  This is a temporary
856 // admission of defeat.  I will eventually go back and get all the stripes
857 // wound the same way (ccw).
858 //
859 // Revision 1.6  1997/11/25 19:25:35  curt
860 // Changes to integrate Durk's moon/sun code updates + clean up.
861 //
862 // Revision 1.5  1997/11/15 18:16:39  curt
863 // minor tweaks.
864 //
865 // Revision 1.4  1997/11/14 00:26:49  curt
866 // Transform scenery coordinates earlier in pipeline when scenery is being
867 // created, not when it is being loaded.  Precalculate normals for each node
868 // as average of the normals of each containing polygon so Garoude shading is
869 // now supportable.
870 //
871 // Revision 1.3  1997/10/31 04:49:12  curt
872 // Tweaking vertex orders.
873 //
874 // Revision 1.2  1997/10/30 12:38:45  curt
875 // Working on new scenery subsystem.
876 //
877 // Revision 1.1  1997/10/28 21:14:54  curt
878 // Initial revision.
879
880