]> git.mxchange.org Git - flightgear.git/blob - Scenery/scenery.cxx
Playing around with texture coordinates.
[flightgear.git] / Scenery / scenery.cxx
1 /* -*- Mode: C++ -*-
2  *
3  * scenery.c -- data structures and routines for managing scenery.
4  *
5  * Written by Curtis Olson, started May 1997.
6  *
7  * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  * $Id$
24  * (Log is kept at end of this file)
25  **************************************************************************/
26
27
28 #ifdef HAVE_CONFIG_H
29 #  include <config.h>
30 #endif
31
32 #ifdef HAVE_WINDOWS_H
33 #  include <windows.h>
34 #endif
35
36 #include <GL/glut.h>
37 #include <XGL/xgl.h>
38
39 #include <stdio.h>
40 #include <string.h>
41
42 #include <Debug/fg_debug.h>
43 #include <Include/general.h>
44 #include <Scenery/obj.hxx>
45 #include <Scenery/scenery.hxx>
46 #include <Scenery/texload.h>
47
48
49 /* Temporary hack until we get a better texture management system running */
50 GLint area_texture;
51
52
53 /* Shared structure to hold current scenery parameters */
54 struct fgSCENERY scenery;
55
56
57 /* Initialize the Scenery Management system */
58 int fgSceneryInit( void ) {
59     fgGENERAL *g;
60     char path[1024], fgpath[1024];
61     GLubyte *texbuf;
62     int width, height;
63
64     g = &general;
65
66     fgPrintf(FG_TERRAIN, FG_INFO, "Initializing scenery subsystem\n");
67
68     /* set the default terrain detail level */
69     // scenery.terrain_skip = 6;
70
71     /* temp: load in a demo texture */
72     path[0] = '\0';
73     strcat(path, g->root_dir);
74     strcat(path, "/Textures/");
75     strcat(path, "desert.rgb");
76
77     // Try uncompressed
78     if ( (texbuf = read_rgb_texture(path, &width, &height)) == NULL ) {
79         // Try compressed
80         strcpy(fgpath, path);
81         strcat(fgpath, ".gz");
82         if ( (texbuf = read_rgb_texture(fgpath, &width, &height)) == NULL ) {
83             fgPrintf( FG_GENERAL, FG_EXIT, "Error in loading texture %s\n",
84                       path );
85             return(0);
86         } 
87     } 
88
89     xglTexImage2D(GL_TEXTURE_2D, 0, 3, height, width, 0,
90                   GL_RGB, GL_UNSIGNED_BYTE, texbuf);
91
92     return(1);
93 }
94
95
96 /* Tell the scenery manager where we are so it can load the proper data, and
97  * build the proper structures. */
98 void fgSceneryUpdate(double lon, double lat, double elev) {
99     fgGENERAL *g;
100     double max_radius;
101     char path[1024];
102
103     g = &general;
104
105     /* a hardcoded hack follows */
106
107     /* this routine should parse the file, and make calls back to the
108      * scenery management system to build the appropriate structures */
109     path[0] = '\0';
110     strcat(path, g->root_dir);
111     strcat(path, "/Scenery/");
112     strcat(path, "mesa-e.obj");
113
114     // fgPrintf(FG_TERRAIN, FG_DEBUG, "  Loading Scenery: %s\n", path);
115
116     // area_terrain = fgObjLoad(path, &scenery.center, &max_radius);
117 }
118
119
120 /* Render out the current scene */
121 void fgSceneryRender( void ) {
122 }
123
124
125 /* $Log$
126 /* Revision 1.2  1998/05/02 01:52:16  curt
127 /* Playing around with texture coordinates.
128 /*
129  * Revision 1.1  1998/04/30 12:35:30  curt
130  * Added a command line rendering option specify smooth/flat shading.
131  *
132  * Revision 1.42  1998/04/28 21:43:27  curt
133  * Wrapped zlib calls up so we can conditionally comment out zlib support.
134  *
135  * Revision 1.41  1998/04/24 00:51:08  curt
136  * Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
137  * Tweaked the scenery file extentions to be "file.obj" (uncompressed)
138  * or "file.obz" (compressed.)
139  *
140  * Revision 1.40  1998/04/18 04:14:06  curt
141  * Moved fg_debug.c to it's own library.
142  *
143  * Revision 1.39  1998/04/08 23:30:07  curt
144  * Adopted Gnu automake/autoconf system.
145  *
146  * Revision 1.38  1998/04/03 22:11:37  curt
147  * Converting to Gnu autoconf system.
148  *
149  * Revision 1.37  1998/03/23 21:23:05  curt
150  * Debugging output tweaks.
151  *
152  * Revision 1.36  1998/03/14 00:30:50  curt
153  * Beginning initial terrain texturing experiments.
154  *
155  * Revision 1.35  1998/01/31 00:43:26  curt
156  * Added MetroWorks patches from Carmen Volpe.
157  *
158  * Revision 1.34  1998/01/27 03:26:43  curt
159  * Playing with new fgPrintf command.
160  *
161  * Revision 1.33  1998/01/19 19:27:17  curt
162  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
163  * This should simplify things tremendously.
164  *
165  * Revision 1.32  1998/01/19 18:40:37  curt
166  * Tons of little changes to clean up the code and to remove fatal errors
167  * when building with the c++ compiler.
168  *
169  * Revision 1.31  1998/01/13 00:23:11  curt
170  * Initial changes to support loading and management of scenery tiles.  Note,
171  * there's still a fair amount of work left to be done.
172  *
173  * Revision 1.30  1998/01/07 03:22:29  curt
174  * Moved astro stuff to .../Src/Astro/
175  *
176  * Revision 1.29  1997/12/30 20:47:52  curt
177  * Integrated new event manager with subsystem initializations.
178  *
179  * Revision 1.28  1997/12/15 23:55:02  curt
180  * Add xgl wrappers for debugging.
181  * Generate terrain normals on the fly.
182  *
183  * Revision 1.27  1997/12/12 21:41:30  curt
184  * More light/material property tweaking ... still a ways off.
185  *
186  * Revision 1.26  1997/12/12 19:52:58  curt
187  * Working on lightling and material properties.
188  *
189  * Revision 1.25  1997/12/10 22:37:51  curt
190  * Prepended "fg" on the name of all global structures that didn't have it yet.
191  * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
192  *
193  * Revision 1.24  1997/12/08 22:51:18  curt
194  * Enhanced to handle ccw and cw tri-stripe winding.  This is a temporary
195  * admission of defeat.  I will eventually go back and get all the stripes
196  * wound the same way (ccw).
197  *
198  * Revision 1.23  1997/11/25 19:25:37  curt
199  * Changes to integrate Durk's moon/sun code updates + clean up.
200  *
201  * Revision 1.22  1997/10/28 21:00:22  curt
202  * Changing to new terrain format.
203  *
204  * Revision 1.21  1997/10/25 03:24:24  curt
205  * Incorporated sun, moon, and star positioning code contributed by Durk Talsma.
206  *
207  * Revision 1.20  1997/10/25 03:18:27  curt
208  * Incorporated sun, moon, and planet position and rendering code contributed
209  * by Durk Talsma.
210  *
211  * Revision 1.19  1997/09/05 14:17:30  curt
212  * More tweaking with stars.
213  *
214  * Revision 1.18  1997/09/05 01:35:59  curt
215  * Working on getting stars right.
216  *
217  * Revision 1.17  1997/08/29 17:55:27  curt
218  * Worked on properly aligning the stars.
219  *
220  * Revision 1.16  1997/08/27 21:32:29  curt
221  * Restructured view calculation code.  Added stars.
222  *
223  * Revision 1.15  1997/08/27 03:30:32  curt
224  * Changed naming scheme of basic shared structures.
225  *
226  * Revision 1.14  1997/08/25 20:27:24  curt
227  * Merged in initial HUD and Joystick code.
228  *
229  * Revision 1.13  1997/08/22 21:34:41  curt
230  * Doing a bit of reorganizing and house cleaning.
231  *
232  * Revision 1.12  1997/08/19 23:55:08  curt
233  * Worked on better simulating real lighting.
234  *
235  * Revision 1.11  1997/08/13 20:24:22  curt
236  * Changed default detail level.
237  *
238  * Revision 1.10  1997/08/06 00:24:30  curt
239  * Working on correct real time sun lighting.
240  *
241  * Revision 1.9  1997/08/04 17:08:11  curt
242  * Testing cvs on IRIX 6.x
243  *
244  * Revision 1.8  1997/07/18 23:41:27  curt
245  * Tweaks for building with Cygnus Win32 compiler.
246  *
247  * Revision 1.7  1997/07/16 20:04:52  curt
248  * Minor tweaks to aid Win32 port.
249  *
250  * Revision 1.6  1997/07/14 16:26:05  curt
251  * Testing/playing -- placed objects randomly across the entire terrain.
252  *
253  * Revision 1.5  1997/07/11 03:23:19  curt
254  * Solved some scenery display/orientation problems.  Still have a positioning
255  * (or transformation?) problem.
256  *
257  * Revision 1.4  1997/07/11 01:30:03  curt
258  * More tweaking of terrian floor.
259  *
260  * Revision 1.3  1997/06/29 21:16:50  curt
261  * More twiddling with the Scenery Management system.
262  *
263  * Revision 1.2  1997/06/27 20:03:37  curt
264  * Working on Makefile structure.
265  *
266  * Revision 1.1  1997/06/27 02:26:30  curt
267  * Initial revision.
268  *
269  */