]> git.mxchange.org Git - flightgear.git/commitdiff
Load and manage multiple textures defined in the Materials library.
authorcurt <curt>
Wed, 17 Jun 1998 21:36:39 +0000 (21:36 +0000)
committercurt <curt>
Wed, 17 Jun 1998 21:36:39 +0000 (21:36 +0000)
Boost max material fagments for each material property to 800.
Multiple texture support when rendering.

Scenery/material.cxx
Scenery/material.hxx
Scenery/obj.cxx
Scenery/scenery.cxx
Scenery/tilemgr.cxx

index fda7716ba0504d4f5bc48c0b0d0e5ad66cd7aa8d..b86b3e8449c203da1edb911303571ec591ca08aa 100644 (file)
@@ -40,7 +40,7 @@
 #include <Main/options.hxx>
 
 #include "material.hxx"
-
+#include "texload.h"
 
 // global material management class
 fgMATERIAL_MGR material_mgr;
@@ -73,25 +73,27 @@ int fgMATERIAL_MGR::load_lib ( void ) {
     fgMATERIAL m;
     fgOPTIONS *o;
     char material_name[256];
-    char path[256], fgpath[256];
+    char mpath[256], fg_mpath[256], tpath[256], fg_tpath[256];
     char line[256], *line_ptr;
+    GLubyte *texbuf;
     fgFile f;
+    int width, height;
 
     o = &current_options;
 
     // build the path name to the material db
-    path[0] = '\0';
-    strcat(path, o->fg_root);
-    strcat(path, "/Scenery/");
-    strcat(path, "Materials");
-    strcpy(fgpath, path);
-    strcat(fgpath, ".gz");
+    mpath[0] = '\0';
+    strcat(mpath, o->fg_root);
+    strcat(mpath, "/Scenery/");
+    strcat(mpath, "Materials");
+    strcpy(fg_mpath, mpath);
+    strcat(fg_mpath, ".gz");
 
     // first try "path.gz"
-    if ( (f = fgopen(fgpath, "rb")) == NULL ) {
+    if ( (f = fgopen(fg_mpath, "rb")) == NULL ) {
         // next try "path"    
-        if ( (f = fgopen(path, "rb")) == NULL ) {
-            fgPrintf(FG_GENERAL, FG_EXIT, "Cannot open file: %s\n", path);
+        if ( (f = fgopen(mpath, "rb")) == NULL ) {
+            fgPrintf(FG_GENERAL, FG_EXIT, "Cannot open file: %s\n", mpath);
         }       
     }
 
@@ -133,6 +135,43 @@ int fgMATERIAL_MGR::load_lib ( void ) {
            }
            // printf("texture name = %s\n", line_ptr);
            sscanf(line_ptr, "%s\n", m.texture_name);
+
+           // create the texture object and bind it
+           xglGenTextures(1, &m.texture_id);
+           xglBindTexture(GL_TEXTURE_2D, m.texture_id);
+
+           // set the texture parameters for this texture
+           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 ) ;
+
+           /* load in the texture data */
+           tpath[0] = '\0';
+           strcat(tpath, o->fg_root);
+           strcat(tpath, "/Textures/");
+           strcat(tpath, m.texture_name);
+           strcat(tpath, ".rgb");
+
+           // Try uncompressed
+           if ( (texbuf = read_rgb_texture(tpath, &width, &height)) == NULL ) {
+               // Try compressed
+               strcpy(fg_tpath, tpath);
+               strcat(fg_tpath, ".gz");
+               if ( (texbuf = read_rgb_texture(fg_tpath, &width, &height)) 
+                    == NULL ) {
+                   fgPrintf( FG_GENERAL, FG_EXIT, 
+                             "Error in loading texture %s\n", tpath );
+                   return(0);
+               } 
+           } 
+
+           xglTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0,
+                         GL_RGB, GL_UNSIGNED_BYTE, texbuf);
+
        } else if ( strncmp(line_ptr, "ambient", 7) == 0 ) {
            line_ptr += 7;
            while ( ( (line_ptr[0] == ' ') || (line_ptr[0] == '\t') || 
@@ -209,6 +248,11 @@ fgMATERIAL_MGR::~fgMATERIAL_MGR ( void ) {
 
 
 // $Log$
+// Revision 1.5  1998/06/17 21:36:39  curt
+// Load and manage multiple textures defined in the Materials library.
+// Boost max material fagments for each material property to 800.
+// Multiple texture support when rendering.
+//
 // Revision 1.4  1998/06/12 00:58:04  curt
 // Build only static libraries.
 // Declare memmove/memset for Sloaris.
index 83a05a6fe46eb3b70b0500cff2d0380ca06d9bd4..a5611c506aaee10a66ffdacc00430e7d5750fa3d 100644 (file)
@@ -46,19 +46,22 @@ extern "C" void *memmove(void *, const void *, size_t);
 extern "C" void *memset(void *, int, size_t);
 #endif
 
-#include <map>             // STL associative "array"
 #include <string>          // Standard C++ string library
+#include <map>             // STL associative "array"
 
 #include "tile.hxx"
 
 
-#define FG_MAX_MATERIAL_FRAGS 400
+#define FG_MAX_MATERIAL_FRAGS 800
 
 
 // Material property class
 class fgMATERIAL {
 
 public:
+    // OpenGL texture name
+    GLuint texture_id;
+
     // file name of texture
     char texture_name[256];
 
@@ -113,6 +116,11 @@ extern fgMATERIAL_MGR material_mgr;
 
 
 // $Log$
+// Revision 1.8  1998/06/17 21:36:39  curt
+// Load and manage multiple textures defined in the Materials library.
+// Boost max material fagments for each material property to 800.
+// Multiple texture support when rendering.
+//
 // Revision 1.7  1998/06/12 00:58:04  curt
 // Build only static libraries.
 // Declare memmove/memset for Sloaris.
index 4243d5595d1da10007459eb6df9b0f8f49d20a0a..5db17f004f8ab460494999079d4aa0fbcfda3ef0 100644 (file)
@@ -40,8 +40,8 @@ extern "C" void *memmove(void *, const void *, size_t);
 extern "C" void *memset(void *, int, size_t);
 #endif
 
-#include <map>     // STL
 #include <string>  // Standard C++ library
+#include <map>     // STL
 
 #include <Debug/fg_debug.h>
 #include <Include/fg_constants.h>
@@ -115,7 +115,6 @@ int fgObjLoad(char *path, fgTILE *tile) {
     fgFile f;
     int in_fragment, in_faces, ncount, vncount, n1, n2, n3, n4;
     int last1, last2, odd;
-    int i;
 
     o = &current_options;
 
@@ -436,6 +435,11 @@ int fgObjLoad(char *path, fgTILE *tile) {
 
 
 // $Log$
+// Revision 1.14  1998/06/17 21:36:40  curt
+// Load and manage multiple textures defined in the Materials library.
+// Boost max material fagments for each material property to 800.
+// Multiple texture support when rendering.
+//
 // Revision 1.13  1998/06/12 00:58:05  curt
 // Build only static libraries.
 // Declare memmove/memset for Sloaris.
index a668c1f9293d8b9491018343a5cada40bfed947f..858c8f6a5a0254747d18629f41aad478581ca24b 100644 (file)
 
 #include <Debug/fg_debug.h>
 #include <Main/options.hxx>
-#include <Scenery/obj.hxx>
-#include <Scenery/scenery.hxx>
-#include <Scenery/texload.h>
+
+#include "obj.hxx"
+#include "scenery.hxx"
+// #include "texload.h"
 
 
 /* Temporary hack until we get a better texture management system running */
@@ -57,14 +58,15 @@ struct fgSCENERY scenery;
 /* Initialize the Scenery Management system */
 int fgSceneryInit( void ) {
     fgOPTIONS *o;
-    char path[1024], fgpath[1024];
-    GLubyte *texbuf;
-    int width, height;
+    // char path[1024], fgpath[1024];
+    // GLubyte *texbuf;
+    // int width, height;
 
     o = &current_options;
 
     fgPrintf(FG_TERRAIN, FG_INFO, "Initializing scenery subsystem\n");
 
+#ifdef 0
     /* set the default terrain detail level */
     // scenery.terrain_skip = 6;
 
@@ -88,7 +90,7 @@ int fgSceneryInit( void ) {
 
     xglTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0,
                  GL_RGB, GL_UNSIGNED_BYTE, texbuf);
-
+#endif // 0
     return(1);
 }
 
@@ -97,7 +99,7 @@ int fgSceneryInit( void ) {
  * build the proper structures. */
 void fgSceneryUpdate(double lon, double lat, double elev) {
     fgOPTIONS *o;
-    double max_radius;
+    // double max_radius;
     char path[1024];
 
     o = &current_options;
@@ -123,9 +125,14 @@ void fgSceneryRender( void ) {
 
 
 /* $Log$
-/* Revision 1.4  1998/05/13 18:26:40  curt
-/* Root path info moved to fgOPTIONS.
+/* Revision 1.5  1998/06/17 21:36:41  curt
+/* Load and manage multiple textures defined in the Materials library.
+/* Boost max material fagments for each material property to 800.
+/* Multiple texture support when rendering.
 /*
+ * Revision 1.4  1998/05/13 18:26:40  curt
+ * Root path info moved to fgOPTIONS.
+ *
  * Revision 1.3  1998/05/07 23:15:20  curt
  * Fixed a glTexImage2D() usage bug where width and height were mis-swapped.
  * Added support for --tile-radius=n option.
index a97b4cf8faede2314bfc6e979fa2a58fa396e90f..2762a20a2ef2707edaec18060f8c7df8906fd446 100644 (file)
@@ -305,7 +305,7 @@ void fgTileMgrRender( void ) {
     fgMATERIAL *mtl_ptr;
     list < fgFRAGMENT > :: iterator current;
     list < fgFRAGMENT > :: iterator last;
-    int i, j, size;
+    int i, size;
     int index;
     int culled = 0;
     int drawn = 0;
@@ -432,7 +432,9 @@ void fgTileMgrRender( void ) {
 
        size = mtl_ptr->list_size;
        if ( size > 0 ) {
-           if ( ! o->textures ) {
+           if ( o->textures ) {
+               xglBindTexture(GL_TEXTURE_2D, mtl_ptr->texture_id);
+           } else {
                xglMaterialfv (GL_FRONT, GL_AMBIENT, mtl_ptr->ambient);
                xglMaterialfv (GL_FRONT, GL_DIFFUSE, mtl_ptr->diffuse);
            }
@@ -472,6 +474,11 @@ void fgTileMgrRender( void ) {
 
 
 // $Log$
+// Revision 1.20  1998/06/17 21:36:42  curt
+// Load and manage multiple textures defined in the Materials library.
+// Boost max material fagments for each material property to 800.
+// Multiple texture support when rendering.
+//
 // Revision 1.19  1998/06/08 17:57:54  curt
 // Working first pass at material proporty sorting.
 //