]> git.mxchange.org Git - flightgear.git/commitdiff
Beginning initial terrain texturing experiments.
authorcurt <curt>
Sat, 14 Mar 1998 00:30:50 +0000 (00:30 +0000)
committercurt <curt>
Sat, 14 Mar 1998 00:30:50 +0000 (00:30 +0000)
Main/GLUTmain.c
Main/fg_debug.c
Main/fg_init.c
Scenery/obj.c
Scenery/scenery.c
Scenery/scenery.h
Scenery/tilemgr.c

index 52045c314acefc9f5af534211c57e1a16247bdf5..8cfebaed00b7e85113a0aee33def0c81b8ae0864 100644 (file)
@@ -69,7 +69,7 @@
 
 
 /* This is a record containing global housekeeping information */
-struct fgGENERAL general;
+fgGENERAL general;
 
 /* view parameters */
 static GLfloat win_ratio = 1.0;
@@ -404,8 +404,19 @@ static void fgRenderFrame( void ) {
     /* 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 ) {
@@ -800,9 +811,12 @@ extern "C" {
 #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.
  *
index 4ea83bfb1d9bca6e168edc2c1eba1864d30df49c..8c1e8f1c5dc90ab49ddec63b70f50597a517649c 100644 (file)
@@ -35,7 +35,7 @@
 
 
 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;
 
@@ -265,9 +265,12 @@ int fgPrintf( fgDebugClass dbg_class, fgDebugPriority prio, char *fmt, ... ) {
 
 
 /* $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.
  *
index 2acdc8e97b0efdcc8a88e2085cddbcf9543db9ed..c919e19ec9b0b3a33ae15708397a4d964f1eb4ab 100644 (file)
@@ -60,7 +60,7 @@ extern const char *default_root;
 /* General house keeping initializations */
 
 int fgInitGeneral( void ) {
-    struct fgGENERAL *g;
+    fgGENERAL *g;
 
     g = &general;
 
@@ -136,7 +136,7 @@ int fgInitSubsystems( void ) {
     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;
@@ -196,7 +196,7 @@ int fgInitSubsystems( void ) {
     // 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
@@ -233,10 +233,10 @@ int fgInitSubsystems( void ) {
     // 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;
@@ -339,6 +339,13 @@ int fgInitSubsystems( void ) {
     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();
@@ -399,9 +406,12 @@ int fgInitSubsystems( void ) {
 
 
 /* $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
index f11c38736c5e6c666cd9299a04b306da4bca9c41..5d3e1b2b21a13bdd78824ff7266f22884eb159bc 100644 (file)
@@ -1,4 +1,5 @@
-/**************************************************************************
+/* -*- 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>
 
@@ -63,11 +66,33 @@ void calc_normal(double p1[3], double p2[3], double p3[3], double normal[3])
 }
 
 
+#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;
@@ -83,6 +108,17 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
     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;
@@ -182,14 +218,17 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
            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 ) {
@@ -200,8 +239,11 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
                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]);
            }
 
@@ -217,6 +259,7 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
                    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;
@@ -239,12 +282,15 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
            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 */
@@ -270,8 +316,9 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
                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;
@@ -294,6 +341,7 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
                    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;
@@ -323,6 +371,9 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
     xglEnd();
     */
 
+    // xglDisable(GL_TEXTURE_GEN_S);
+    // xglDisable(GL_TEXTURE_GEN_T);
+
     xglFrontFace ( GL_CCW );
 
     xglEndList();
@@ -339,9 +390,12 @@ GLint fgObjLoad(char *path, struct fgCartesianPoint *ref, double *radius) {
 
 
 /* $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.
  *
index 1753d69b7edce4e825a6684f85514a9626a6a436..fa1e81d4de5f982c379b002643fc8d20955c781b 100644 (file)
@@ -1,4 +1,5 @@
-/**************************************************************************
+/* -*- 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 */
@@ -49,18 +51,43 @@ struct fgSCENERY scenery;
 
 
 /* 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];
 
@@ -75,35 +102,24 @@ void fgSceneryUpdate(double lon, double lat, double elev) {
     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.
  *
index 84cba5f6b829f96ed8faea4ae35f6e97ec7f2d95..8c59439508074a78826182537016b9cc9be3a887 100644 (file)
@@ -50,7 +50,7 @@ extern struct fgSCENERY scenery;
 
 
 /* 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
@@ -66,9 +66,12 @@ void fgSceneryRender( void );
 
 
 /* $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.
index da9cb9f56d6c66bd15ccd7691c546085c0b09ff6..0097634324c8b218fa44c764eba21e5ec74a1379 100644 (file)
@@ -1,4 +1,5 @@
-/**************************************************************************
+/* -*- Mode: C++ -*-
+ *
  * tilemgr.c -- routines to handle dynamic management of scenery tiles
  *
  * Written by Curtis Olson, started January 1998.
@@ -180,9 +181,6 @@ int fgTileMgrUpdate( void ) {
 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;
@@ -190,14 +188,6 @@ void fgTileMgrRender( void ) {
 
     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);
@@ -225,9 +215,12 @@ void fgTileMgrRender( void ) {
 
 
 /* $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.