From: curt Date: Wed, 17 Jun 1998 21:36:39 +0000 (+0000) Subject: Load and manage multiple textures defined in the Materials library. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=24c78e81468510d226c11e5adead165993c62aaf;p=flightgear.git 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. --- diff --git a/Scenery/material.cxx b/Scenery/material.cxx index fda7716ba..b86b3e844 100644 --- a/Scenery/material.cxx +++ b/Scenery/material.cxx @@ -40,7 +40,7 @@ #include
#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 = ¤t_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. diff --git a/Scenery/material.hxx b/Scenery/material.hxx index 83a05a6fe..a5611c506 100644 --- a/Scenery/material.hxx +++ b/Scenery/material.hxx @@ -46,19 +46,22 @@ extern "C" void *memmove(void *, const void *, size_t); extern "C" void *memset(void *, int, size_t); #endif -#include // STL associative "array" #include // Standard C++ string library +#include // 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. diff --git a/Scenery/obj.cxx b/Scenery/obj.cxx index 4243d5595..5db17f004 100644 --- a/Scenery/obj.cxx +++ b/Scenery/obj.cxx @@ -40,8 +40,8 @@ extern "C" void *memmove(void *, const void *, size_t); extern "C" void *memset(void *, int, size_t); #endif -#include // STL #include // Standard C++ library +#include // STL #include #include @@ -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 = ¤t_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. diff --git a/Scenery/scenery.cxx b/Scenery/scenery.cxx index a668c1f92..858c8f6a5 100644 --- a/Scenery/scenery.cxx +++ b/Scenery/scenery.cxx @@ -41,9 +41,10 @@ #include #include
-#include -#include -#include + +#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 = ¤t_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 = ¤t_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. diff --git a/Scenery/tilemgr.cxx b/Scenery/tilemgr.cxx index a97b4cf8f..2762a20a2 100644 --- a/Scenery/tilemgr.cxx +++ b/Scenery/tilemgr.cxx @@ -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. //