/* This is a record containing global housekeeping information */
-struct fgGENERAL general;
+fgGENERAL general;
/* view parameters */
static GLfloat win_ratio = 1.0;
/* set lighting parameters */
xglLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_ambient );
xglLightfv(GL_LIGHT0, GL_DIFFUSE, l->scene_diffuse );
+ /* texture parameters */
+ xglEnable( GL_TEXTURE_2D );
+ xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ) ;
+ xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ) ;
+ xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) ;
+ xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ GL_LINEAR /* GL_LINEAR_MIPMAP_LINEAR */ ) ;
+ xglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
+ xglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
+
fgTileMgrRender();
- /* fgSceneryRender(); */
+
+ xglDisable( GL_TEXTURE_2D );
/* display HUD */
if( show_hud ) {
#endif
/* $Log$
-/* Revision 1.65 1998/03/09 22:45:57 curt
-/* Minor tweaks for building on sparc platform.
+/* Revision 1.66 1998/03/14 00:31:20 curt
+/* Beginning initial terrain texturing experiments.
/*
+ * Revision 1.65 1998/03/09 22:45:57 curt
+ * Minor tweaks for building on sparc platform.
+ *
* Revision 1.64 1998/02/20 00:16:23 curt
* Thursday's tweaks.
*
static int fg_DebugSem = 1;
-fgDebugClass fg_DebugClass = FG_ALL; // Need visibility for
+fgDebugClass fg_DebugClass = FG_NONE; // Need visibility for
fgDebugPriority fg_DebugPriority = FG_INFO; // command line processing.
static fgDebugCallback fg_DebugCallback = NULL;
/* $Log$
-/* Revision 1.9 1998/03/09 22:44:58 curt
-/* Modified so that you can specify FG_DEBUGCLASS ***or*** FG_DEBUG_PRIORITY
+/* Revision 1.10 1998/03/14 00:31:21 curt
+/* Beginning initial terrain texturing experiments.
/*
+ * Revision 1.9 1998/03/09 22:44:58 curt
+ * Modified so that you can specify FG_DEBUGCLASS ***or*** FG_DEBUG_PRIORITY
+ *
* Revision 1.8 1998/03/09 22:11:00 curt
* Processed through the format-o-matic.
*
/* General house keeping initializations */
int fgInitGeneral( void ) {
- struct fgGENERAL *g;
+ fgGENERAL *g;
g = &general;
FG_Longitude = ( -110.6642444 ) * DEG_TO_RAD;
FG_Latitude = ( 33.3528917 ) * DEG_TO_RAD;
FG_Runway_altitude = (3234.5 + 300);
- FG_Altitude = FG_Runway_altitude + 3.758099;
+ FG_Altitude = FG_Runway_altitude + 3.758099 + 30000;
// Initial Position at (E81) Superior, AZ
// FG_Longitude = ( -111.1270650 ) * DEG_TO_RAD;
// Initial Position: Somewhere near the Grand Canyon
// FG_Longitude = ( -112.5 ) * DEG_TO_RAD;
// FG_Latitude = ( 36.5 ) * DEG_TO_RAD;
- // FG_Runway_altitude = 5000.0;
+ // FG_Runway_altitude = 8000.0;
// FG_Altitude = FG_Runway_altitude + 3.758099;
// Initial Position: (GCN) Grand Canyon Airport, AZ
// FG_Altitude = FG_Runway_altitude + 3.758099;
// Test Position
- FG_Longitude = ( -122.1469647 ) * DEG_TO_RAD;
- FG_Latitude = ( 35.9523539 ) * DEG_TO_RAD;
- FG_Runway_altitude = 2000.0;
- FG_Altitude = FG_Runway_altitude + 3.758099;
+ // FG_Longitude = ( -122.1469647 ) * DEG_TO_RAD;
+ // FG_Latitude = ( 35.9523539 ) * DEG_TO_RAD;
+ // FG_Runway_altitude = 2000.0;
+ // FG_Altitude = FG_Runway_altitude + 3.758099;
// A random test position
// FG_Longitude = ( 88128.00 / 3600.0 ) * DEG_TO_RAD;
fgSkyInit();
// Initialize the Scenery Management subsystem
+ if ( fgSceneryInit() ) {
+ // Scenery initialized ok.
+ } else {
+ fgPrintf( FG_GENERAL, FG_EXIT, "Error in Scenery initialization!\n" );
+ }
+
+
if( fgTileMgrInit() ) {
// Load the local scenery data
fgTileMgrUpdate();
/* $Log$
-/* Revision 1.50 1998/03/09 22:46:19 curt
-/* Minor tweaks.
+/* Revision 1.51 1998/03/14 00:31:22 curt
+/* Beginning initial terrain texturing experiments.
/*
+ * Revision 1.50 1998/03/09 22:46:19 curt
+ * Minor tweaks.
+ *
* Revision 1.49 1998/02/23 19:07:59 curt
* Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
* calculation code between sun display, and other FG sections that use this
-/**************************************************************************
+/* -*- Mode: C++ -*-
+ *
* obj.c -- routines to handle WaveFront .obj format files.
*
* Written by Curtis Olson, started October 1997.
#include <GL/glut.h>
#include <XGL/xgl.h>
+#include <Include/fg_constants.h>
#include <Main/fg_debug.h>
#include <Math/mat3.h>
+#include <Math/fg_random.h>
#include <Scenery/obj.h>
#include <Scenery/scenery.h>
}
+#define FG_TEX_CONSTANT 64.0
+
+float calc_lon(double x, double y, double z) {
+ float tmp;
+ tmp = (RAD_TO_DEG*atan2(y, x)) * FG_TEX_CONSTANT;
+
+ // printf("lon = %.2f\n", (float)tmp);
+ return (float)tmp;
+}
+
+
+float calc_lat(double x, double y, double z) {
+ float tmp;
+
+ tmp = (90.0 - RAD_TO_DEG*atan2( sqrt(x*x + y*y), z )) * FG_TEX_CONSTANT;
+
+ // printf("lat = %.2f\n", (float)tmp);
+ return (float)tmp;
+}
+
+
/* Load a .obj file and generate the GL call list */
GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
char line[256], winding_str[256];
double approx_normal[3], normal[3], scale;
double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
+ GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
GLint tile;
FILE *f;
int first, ncount, vncount, n1, n2, n3, n4;
tile = xglGenLists(1);
xglNewList(tile, GL_COMPILE);
+ /*
+ xglTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+ xglTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+ xglTexGenfv(GL_S, GL_OBJECT_PLANE, sgenparams);
+ xglTexGenfv(GL_T, GL_OBJECT_PLANE, sgenparams);
+ // xglTexGenfv(GL_S, GL_SPHERE_MAP, 0);
+ // xglTexGenfv(GL_T, GL_SPHERE_MAP, 0);
+ xglEnable(GL_TEXTURE_GEN_S);
+ xglEnable(GL_TEXTURE_GEN_T);
+ */
+
first = 1;
ncount = 1;
vncount = 1;
if ( use_per_vertex_norms ) {
MAT3_SCALE_VEC(normal, normals[n1], scale);
xglNormal3dv(normal);
+ xglTexCoord2f(calc_lon(nodes[n1][0], nodes[n1][1], nodes[n1][2]), calc_lat(nodes[n1][0], nodes[n1][1], nodes[n1][2]));
xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
MAT3_SCALE_VEC(normal, normals[n2], scale);
xglNormal3dv(normal);
+ xglTexCoord2f(calc_lon(nodes[n2][0], nodes[n2][1], nodes[n2][2]), calc_lat(nodes[n2][0], nodes[n2][1], nodes[n2][2]));
xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
MAT3_SCALE_VEC(normal, normals[n3], scale);
xglNormal3dv(normal);
+ xglTexCoord2f(calc_lon(nodes[n3][0], nodes[n3][1], nodes[n3][2]), calc_lat(nodes[n3][0], nodes[n3][1], nodes[n3][2]));
xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]);
} else {
if ( odd ) {
MAT3_SCALE_VEC(normal, approx_normal, scale);
xglNormal3dv(normal);
+ xglTexCoord2f(calc_lon(nodes[n1][0], nodes[n1][1], nodes[n1][2]), calc_lat(nodes[n1][0], nodes[n1][1], nodes[n1][2]));
xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
+ xglTexCoord2f(calc_lon(nodes[n2][0], nodes[n2][1], nodes[n2][2]), calc_lat(nodes[n2][0], nodes[n2][1], nodes[n2][2]));
xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
+ xglTexCoord2f(calc_lon(nodes[n3][0], nodes[n3][1], nodes[n3][2]), calc_lat(nodes[n3][0], nodes[n3][1], nodes[n3][2]));
xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]);
}
MAT3_SCALE_VEC(normal, approx_normal, scale);
}
xglNormal3dv(normal);
+ xglTexCoord2f(calc_lon(nodes[n4][0], nodes[n4][1], nodes[n4][2]), calc_lat(nodes[n4][0], nodes[n4][1], nodes[n4][2]));
xglVertex3d(nodes[n4][0], nodes[n4][1], nodes[n4][2]);
odd = 1 - odd;
sscanf(line, "f %d %d %d\n", &n1, &n2, &n3);
xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
+ xglTexCoord2f(calc_lon(nodes[n1][0], nodes[n1][1], nodes[n1][2]), calc_lat(nodes[n1][0], nodes[n1][1], nodes[n1][2]));
xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
xglNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]);
+ xglTexCoord2f(calc_lon(nodes[n2][0], nodes[n2][1], nodes[n2][2]), calc_lat(nodes[n2][0], nodes[n2][1], nodes[n2][2]));
xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
-
+
xglNormal3d(normals[n3][0], normals[n3][1], normals[n3][2]);
+ xglTexCoord2f(calc_lon(nodes[n3][0], nodes[n3][1], nodes[n3][2]), calc_lat(nodes[n3][0], nodes[n3][1], nodes[n3][2]));
xglVertex3d(nodes[n3][0], nodes[n3][1], nodes[n3][2]);
} else if ( line[0] == 'q' ) {
/* continue a triangle strip */
xglNormal3dv(normal);
}
+ xglTexCoord2f(calc_lon(nodes[n1][0], nodes[n1][1], nodes[n1][2]), calc_lat(nodes[n1][0], nodes[n1][1], nodes[n1][2]));
xglVertex3d(nodes[n1][0], nodes[n1][1], nodes[n1][2]);
-
+
odd = 1 - odd;
last1 = last2;
last2 = n1;
xglNormal3dv(normal);
}
+ xglTexCoord2f(calc_lon(nodes[n2][0], nodes[n2][1], nodes[n2][2]), calc_lat(nodes[n2][0], nodes[n2][1], nodes[n2][2]));
xglVertex3d(nodes[n2][0], nodes[n2][1], nodes[n2][2]);
odd = 1 -odd;
xglEnd();
*/
+ // xglDisable(GL_TEXTURE_GEN_S);
+ // xglDisable(GL_TEXTURE_GEN_T);
+
xglFrontFace ( GL_CCW );
xglEndList();
/* $Log$
-/* Revision 1.24 1998/02/09 21:30:18 curt
-/* Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
+/* Revision 1.25 1998/03/14 00:30:50 curt
+/* Beginning initial terrain texturing experiments.
/*
+ * Revision 1.24 1998/02/09 21:30:18 curt
+ * Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
+ *
* Revision 1.23 1998/02/09 15:07:52 curt
* Minor tweaks.
*
-/**************************************************************************
+/* -*- Mode: C++ -*-
+ *
* scenery.c -- data structures and routines for managing scenery.
*
* Written by Curtis Olson, started May 1997.
#include <Main/fg_debug.h>
#include <Scenery/obj.h>
#include <Scenery/scenery.h>
+#include <Scenery/texload.h>
-/* Temporary hack until we get the scenery management system running */
-GLint area_terrain;
+/* Temporary hack until we get a better texture management system running */
+GLint area_texture;
/* Shared structure to hold current scenery parameters */
/* Initialize the Scenery Management system */
-void fgSceneryInit( void ) {
+int fgSceneryInit( void ) {
+ fgGENERAL *g;
+ char path[1024];
+ GLubyte *texbuf;
+ int width, height;
+
+ g = &general;
+
fgPrintf(FG_TERRAIN, FG_INFO, "Initializing scenery subsystem\n");
/* set the default terrain detail level */
- scenery.terrain_skip = 6;
+ // scenery.terrain_skip = 6;
+
+ /* temp: load in a demo texture */
+ path[0] = '\0';
+ strcat(path, g->root_dir);
+ strcat(path, "/Textures/");
+ strcat(path, "desert.rgb");
+
+ if ( (texbuf = read_rgb_texture(path, &width, &height)) == NULL ) {
+ fgPrintf( FG_GENERAL, FG_EXIT, "Error in loading textures!\n" );
+ return(0);
+ }
+
+ /* xglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, height, width, 0,
+ GL_LUMINANCE, GL_UNSIGNED_BYTE, texbuf); */
+ xglTexImage2D(GL_TEXTURE_2D, 0, 3, height, width, 0,
+ GL_RGB, GL_UNSIGNED_BYTE, texbuf);
+
+ return(1);
}
/* Tell the scenery manager where we are so it can load the proper data, and
* build the proper structures. */
void fgSceneryUpdate(double lon, double lat, double elev) {
- struct fgGENERAL *g;
+ fgGENERAL *g;
double max_radius;
char path[1024];
strcat(path, "/Scenery/");
strcat(path, "mesa-e.obj");
- fgPrintf(FG_TERRAIN, FG_DEBUG, " Loading Scenery: %s\n", path);
+ // fgPrintf(FG_TERRAIN, FG_DEBUG, " Loading Scenery: %s\n", path);
- area_terrain = fgObjLoad(path, &scenery.center, &max_radius);
+ // area_terrain = fgObjLoad(path, &scenery.center, &max_radius);
}
/* Render out the current scene */
void fgSceneryRender( void ) {
- static GLfloat terrain_color[4] = { 0.6, 0.8, 0.4, 1.0 };
- static GLfloat terrain_ambient[4];
- static GLfloat terrain_diffuse[4];
- int i;
-
- for ( i = 0; i < 4; i++ ) {
- terrain_ambient[i] = terrain_color[i] * 0.5;
- terrain_diffuse[i] = terrain_color[i];
- }
-
- xglMaterialfv(GL_FRONT, GL_AMBIENT, terrain_ambient);
- xglMaterialfv(GL_FRONT, GL_DIFFUSE, terrain_diffuse);
-
- xglCallList(area_terrain);
}
/* $Log$
-/* Revision 1.35 1998/01/31 00:43:26 curt
-/* Added MetroWorks patches from Carmen Volpe.
+/* Revision 1.36 1998/03/14 00:30:50 curt
+/* Beginning initial terrain texturing experiments.
/*
+ * Revision 1.35 1998/01/31 00:43:26 curt
+ * Added MetroWorks patches from Carmen Volpe.
+ *
* Revision 1.34 1998/01/27 03:26:43 curt
* Playing with new fgPrintf command.
*
/* Initialize the Scenery Management system */
-void fgSceneryInit( void );
+int fgSceneryInit( void );
/* Tell the scenery manager where we are so it can load the proper data, and
/* $Log$
-/* Revision 1.17 1998/02/20 00:16:24 curt
-/* Thursday's tweaks.
+/* Revision 1.18 1998/03/14 00:30:51 curt
+/* Beginning initial terrain texturing experiments.
/*
+ * Revision 1.17 1998/02/20 00:16:24 curt
+ * Thursday's tweaks.
+ *
* Revision 1.16 1998/01/27 00:48:03 curt
* Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
* system and commandline/config file processing code.
-/**************************************************************************
+/* -*- Mode: C++ -*-
+ *
* tilemgr.c -- routines to handle dynamic management of scenery tiles
*
* Written by Curtis Olson, started January 1998.
void fgTileMgrRender( void ) {
fgFLIGHT *f;
struct fgBUCKET p;
- static GLfloat terrain_color[4] = { 0.6, 0.8, 0.4, 1.0 };
- static GLfloat terrain_ambient[4];
- static GLfloat terrain_diffuse[4];
struct fgCartesianPoint local_ref;
GLint display_list;
int i;
f = current_aircraft.flight;
- for ( i = 0; i < 4; i++ ) {
- terrain_ambient[i] = terrain_color[i] * 0.5;
- terrain_diffuse[i] = terrain_color[i];
- }
-
- xglMaterialfv(GL_FRONT, GL_AMBIENT, terrain_ambient);
- xglMaterialfv(GL_FRONT, GL_DIFFUSE, terrain_diffuse);
-
/* Find current translation offset */
fgBucketFind(FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, &p);
index = fgTileCacheExists(&p);
/* $Log$
-/* Revision 1.19 1998/02/20 00:16:25 curt
-/* Thursday's tweaks.
+/* Revision 1.20 1998/03/14 00:30:51 curt
+/* Beginning initial terrain texturing experiments.
/*
+ * Revision 1.19 1998/02/20 00:16:25 curt
+ * Thursday's tweaks.
+ *
* Revision 1.18 1998/02/19 13:05:54 curt
* Incorporated some HUD tweaks from Michelle America.
* Tweaked the sky's sunset/rise colors.