[Plib-cvs] plib/src/ssg ssgLoadBGL.cxx,NONE,1.1 ssgLoadMDL_BGLTexture.cxx,NONE,1.1 ssg.cxx,1.48,1.49
Brought to you by:
sjbaker
From: Sebastian U. <ud...@us...> - 2002-06-07 23:11:41
|
Update of /cvsroot/plib/plib/src/ssg In directory usw-pr-cvs1:/tmp/cvs-serv27739/src/ssg Modified Files: ssg.cxx ssg.dsp ssg.h ssgDList.cxx ssgLoadBMP.cxx ssgLoadMDL.cxx ssgLoadMDL.h ssgconf.h Added Files: ssgLoadBGL.cxx ssgLoadMDL_BGLTexture.cxx Log Message: Juergen Marquardt: Introduced BGL loader --- NEW FILE: ssgLoadBGL.cxx --- /* PLIB - A Suite of Portable Game Libraries Copyright (C) 2001 Steve Baker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information visit http://plib.sourceforge.net [...2199 lines suppressed...] } // end of bgl "object header opcode" while loop fclose(fp); DEBUGPRINT("\n" << vertex_array_->getNum() << " vertices\n"); return model_; } #else ssgEntity *ssgLoadBGL(const char *fname, const ssgLoaderOptions *options) { return NULL ; } #endif --- NEW FILE: ssgLoadMDL_BGLTexture.cxx --- /* PLIB - A Suite of Portable Game Libraries Copyright (C) 2001 Steve Baker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information visit http://plib.sourceforge.net $Id: ssgLoadMDL_BGLTexture.cxx,v 1.1 2002/06/07 23:11:38 ude Exp $ */ #include "ssgLocal.h" #include "ssgMSFSPalette.h" #ifdef SSG_LOAD_MDL_BGL_TEXTURE_SUPPORTED // This really simple (raw paletted) format is used by older MSFS for textures bool ssgLoadMDLTexture ( const char *fname, ssgTextureInfo* info ) { FILE *tfile; int index = 0; if ( (tfile = fopen(fname, "rb")) == NULL) { char *p = strrchr(fname,'_'); if (p != 0) { *p = '\0'; p++; index = atoi (p); if ( (tfile = fopen(fname, "rb")) == NULL) { ulSetError( UL_WARNING, "ssgLoadTexture: Failed to load '%s'.", fname ); return false ; } p--; *p = '_'; } else { ulSetError( UL_WARNING, "ssgLoadTexture: Failed to load '%s'.", fname ); return false ; } } fseek(tfile, 0, SEEK_END); unsigned long file_length = ftell(tfile); if (file_length != 65536) { // this is not a MSFS-formatted texture, so it's probably a BMP fclose(tfile); return ssgLoadBMP( fname, info ); } else { fseek(tfile, 0, SEEK_SET); unsigned char *texels = new unsigned char[256 * 256 * 4]; int c = 0; for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { unsigned char b; fread(&b, 1, 1, tfile); texels[c++] = fsTexPalette[b*4 ]; texels[c++] = fsTexPalette[b*4 + 1]; texels[c++] = fsTexPalette[b*4 + 2]; texels[c++] = (b<index)?0:255; } } fclose(tfile); if ( info != NULL ) { info -> width = 256 ; info -> height = 256 ; info -> depth = 4 ; info -> alpha = TRUE ; //?? } return ssgMakeMipMaps ( texels, 256, 256, 4 ) ; } } #else bool ssgLoadMDLTexture ( const char *fname, ssgTextureInfo* info ) { ulSetError ( UL_WARNING, "ssgLoadTexture: '%s' - MDL/BGL Texture support not configured", fname ) ; return false ; } #endif Index: ssg.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/ssg/ssg.cxx,v retrieving revision 1.48 retrieving revision 1.49 diff -u -d -r1.48 -r1.49 --- ssg.cxx 21 Apr 2002 03:53:29 -0000 1.48 +++ ssg.cxx 7 Jun 2002 23:11:38 -0000 1.49 @@ -146,6 +146,7 @@ #ifdef SSG_LOAD_MDL_SUPPORTED ssgAddModelFormat ( ".mdl", ssgLoadMDL , NULL ) ; + ssgAddModelFormat ( ".bgl", ssgLoadBGL , NULL ) ; #endif #ifdef SSG_LOAD_TGA_SUPPORTED @@ -190,6 +191,9 @@ ssgAddTextureFormat ( ".iaf" , ssgLoadMDLTexture ) ; ssgAddTextureFormat ( ".jaf" , ssgLoadMDLTexture ) ; ssgAddTextureFormat ( ".kaf" , ssgLoadMDLTexture ) ; + ssgAddTextureFormat ( ".pat" , ssgLoadMDLTexture ) ; + ssgAddTextureFormat ( ".r8" , ssgLoadMDLTexture ) ; + ssgAddTextureFormat ( ".naz" , ssgLoadMDLTexture ) ; #endif } Index: ssg.dsp =================================================================== RCS file: /cvsroot/plib/plib/src/ssg/ssg.dsp,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- ssg.dsp 17 Jan 2002 16:13:21 -0000 1.36 +++ ssg.dsp 7 Jun 2002 23:11:38 -0000 1.37 @@ -186,6 +186,10 @@ # End Source File # Begin Source File +SOURCE=.\ssgLoadBGL.cxx +# End Source File +# Begin Source File + SOURCE=.\ssgLoadBMP.cxx # End Source File # Begin Source File @@ -215,6 +219,10 @@ # Begin Source File SOURCE=.\ssgLoadmd2.cxx +# End Source File +# Begin Source File + +SOURCE=.\ssgLoadMDL_BGLTexture.cxx # End Source File # Begin Source File Index: ssg.h =================================================================== RCS file: /cvsroot/plib/plib/src/ssg/ssg.h,v retrieving revision 1.132 retrieving revision 1.133 diff -u -d -r1.132 -r1.133 --- ssg.h 23 Mar 2002 15:06:44 -0000 1.132 +++ ssg.h 7 Jun 2002 23:11:38 -0000 1.133 @@ -2627,7 +2627,7 @@ ssgEntity *ssgLoadOBJ ( const char *fname, const ssgLoaderOptions *options = NULL ) ; ssgEntity *ssgLoadMD2 ( const char *fname, const ssgLoaderOptions *options = NULL ) ; ssgEntity *ssgLoadMDL ( const char *fname, const ssgLoaderOptions *options = NULL ) ; -//ssgEntity *ssgLoadBGL ( const char *fname, const ssgLoaderOptions *options = NULL ) ; +ssgEntity *ssgLoadBGL ( const char *fname, const ssgLoaderOptions *options = NULL ) ; ssgEntity *ssgLoadX ( const char *fname, const ssgLoaderOptions *options = NULL ) ; ssgEntity *ssgLoadFLT ( const char *fname, const ssgLoaderOptions *options = NULL ) ; ssgEntity *ssgLoadM ( const char *fname, const ssgLoaderOptions *options = NULL ) ; Index: ssgDList.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/ssg/ssgDList.cxx,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- ssgDList.cxx 7 Nov 2001 23:51:09 -0000 1.7 +++ ssgDList.cxx 7 Jun 2002 23:11:38 -0000 1.8 @@ -125,7 +125,8 @@ } ; -#define MAX_DLIST 4096 +#define MAX_DLIST 8192 +//4096 //2048 static int next_dlist = 0 ; Index: ssgLoadBMP.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/ssg/ssgLoadBMP.cxx,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- ssgLoadBMP.cxx 23 Mar 2002 15:06:45 -0000 1.9 +++ ssgLoadBMP.cxx 7 Jun 2002 23:11:38 -0000 1.10 @@ -123,6 +123,8 @@ bool ssgLoadBMP ( const char *fname, ssgTextureInfo* info ) { int w, h, bpp ; + int index=0; + bool old_format = false; RGBA pal [ 256 ] ; BMPHeader bmphdr ; @@ -133,9 +135,25 @@ if ( ( curr_image_fd = fopen ( curr_image_fname, "rb" ) ) == NULL ) { - perror ( "ssgLoadTexture" ) ; - ulSetError ( UL_WARNING, "ssgLoadTexture: Failed to open '%s' for reading.", curr_image_fname ) ; - return false ; + char *p = strrchr(curr_image_fname,'_'); + if (p != 0) { + *p = '\0'; + p++; + index = atoi (p); + old_format = true; + if ( ( curr_image_fd = fopen(curr_image_fname, "rb")) == NULL) { + perror ( "ssgLoadTexture" ) ; + ulSetError( UL_WARNING, "ssgLoadTexture: Failed to load '%s' for reading.", curr_image_fname ); + return false ; + } + p--; + *p = '_'; + } + else { + perror ( "ssgLoadTexture" ) ; + ulSetError( UL_WARNING, "ssgLoadTexture: Failed to open '%s' for reading.", curr_image_fname ); + return false ; + } } /* @@ -172,7 +190,7 @@ bmphdr.YPelsPerMeter = readInt () ; bmphdr.ClrUsed = readInt () ; bmphdr.ClrImportant = readInt () ; - + w = bmphdr.Width ; h = bmphdr.Height ; bpp = bmphdr.Planes * bmphdr.BitCount ; @@ -210,7 +228,20 @@ /* According to BMP specs, this fourth value is not really alpha value but just a filler byte, so it is ignored for now. */ pal[i].a = readByte () ; - //if ( pal[i].a != 255 ) isOpaque = FALSE ; + if (old_format == true) { + pal[i].a = (i<index)?0:255; + + } +/* + if ( (pal[i].r == pal[i].g) && (pal[i].r == pal[i].b) ) { + if (pal[i].r == 0) + pal[i].a = 0; + if (pal[i].r == 0x18) + pal[i].a = 0x18; + isOpaque = FALSE ; + } +*/ +// if ( (i>1) && (pal[i].a != pal[i-1].a) ) isOpaque = FALSE ; if ( pal[i].r != pal[i].g || pal[i].g != pal[i].b ) isMonochrome = FALSE ; @@ -243,6 +274,10 @@ if ( bpp == 8 ) { + for ( int i = 1 ; i < w * h ; i++ ) { + if (pal[data[i]].a != pal[data[i-1]].a) isOpaque = FALSE ; + } + if ( isMonochrome ) z = isOpaque ? 1 : 2 ; else @@ -309,7 +344,7 @@ info -> width = w ; info -> height = h ; info -> depth = z ; - info -> alpha = ( z == 4 ) ; + info -> alpha = ( isOpaque == FALSE ) ; } return ssgMakeMipMaps ( image, w, h, z ) ; Index: ssgLoadMDL.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/ssg/ssgLoadMDL.cxx,v retrieving revision 1.35 retrieving revision 1.36 diff -u -d -r1.35 -r1.36 --- ssgLoadMDL.cxx 9 Mar 2002 20:01:47 -0000 1.35 +++ ssgLoadMDL.cxx 7 Jun 2002 23:11:38 -0000 1.36 @@ -42,7 +42,6 @@ #ifdef SSG_LOAD_MDL_SUPPORTED #include "ssgLoadMDL.h" -#include "ssgMSFSPalette.h" #define DEF_SHININESS 50 @@ -1477,54 +1476,8 @@ delete curr_norm_; DEBUGPRINT("\n" << vertex_array_->getNum() << " vertices\n"); - - return model_; -} -// This really simple (raw paletted) format is used by older MSFS for textures -bool ssgLoadMDLTexture ( const char *fname, ssgTextureInfo* info ) -{ - FILE *tfile; - if ( (tfile = fopen(fname, "rb")) == NULL) { - ulSetError( UL_WARNING, "ssgLoadTexture: Failed to load '%s'.", fname ); - return false ; - } - - fseek(tfile, 0, SEEK_END); - unsigned long file_length = ftell(tfile); - - if (file_length != 65536) { - // this is not a MSFS-formatted texture, so it's probably a BMP - fclose(tfile); - return ssgLoadBMP( fname, info ); - } else { - fseek(tfile, 0, SEEK_SET); - - unsigned char *texels = new unsigned char[256 * 256 * 4]; - int c = 0; - for (int y = 0; y < 256; y++) { - for (int x = 0; x < 256; x++) { - unsigned char b; - fread(&b, 1, 1, tfile); - texels[c++] = fsTexPalette[b*4 ]; - texels[c++] = fsTexPalette[b*4 + 1]; - texels[c++] = fsTexPalette[b*4 + 2]; - texels[c++] = fsTexPalette[b*4 + 3]; - } - } - - fclose(tfile); - - if ( info != NULL ) - { - info -> width = 256 ; - info -> height = 256 ; - info -> depth = 4 ; - info -> alpha = FALSE ; //?? - } - - return ssgMakeMipMaps ( texels, 256, 256, 4 ) ; - } + return model_; } @@ -1534,14 +1487,6 @@ ssgEntity *ssgLoadMDL(const char *fname, const ssgLoaderOptions *options) { return NULL ; -} - - -bool ssgLoadMDLTexture ( const char *fname, ssgTextureInfo* info ) -{ - ulSetError ( UL_WARNING, - "ssgLoadTexture: '%s' - MDL support not configured", fname ) ; - return false ; } Index: ssgLoadMDL.h =================================================================== RCS file: /cvsroot/plib/plib/src/ssg/ssgLoadMDL.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- ssgLoadMDL.h 7 Nov 2001 23:51:10 -0000 1.4 +++ ssgLoadMDL.h 7 Jun 2002 23:11:38 -0000 1.5 @@ -245,7 +245,7 @@ { 0x02, "BGL_NOOP" , 2 }, { 0x03, "BGL_CASE" , -1 }, { 0x04, "RESERVED 0x04" , 2 }, - { 0x05, "BGL_SURFACE" , 2 }, + { 0x05, "BGL_SURFACE - Area" , 2 }, { 0x06, "BGL_SPNT" , 8 }, { 0x07, "BGL_CPNT" , 8 }, { 0x08, "BLG_CLOSURE" , 2 }, @@ -274,7 +274,7 @@ { 0x1f, "RESERVED 0x1f" , 4 }, { 0x20, "BGL_FACET_TMAP" , -1 }, { 0x21, "BGL_IFIN3" , 22 }, - { 0x22, "BGL_RETURN" , 2 }, + { 0x22, "BGL_RETURN - Return" , 2 }, { 0x23, "BGL_CALL" , 4 }, { 0x24, "BGL_IFIN1" , 10 }, { 0x25, "BGL_SEPARATION_PLANE" , 14 }, @@ -290,8 +290,8 @@ { 0x2f, "BGL_SCALE" , 32 }, { 0x30, "OBSOLETE 0x30" , 4 }, { 0x31, "BGL_RESROW" , 18 }, - { 0x32, "BGL_ADDOBJ" , 4 }, - { 0x33, "BGL_INSTANCE" , 10 }, + { 0x32, "BGL_ADDOBJ - PerspectiveCall", 4 }, + { 0x33, "BGL_INSTANCE - RotatedCall", 10 }, { 0x34, "BGL_SUPER_SCALE" , 10 }, { 0x35, "BGL_PNTROW" , 16 }, { 0x36, "OBSOLETE 0x36" , -1 }, @@ -358,8 +358,8 @@ { 0x73, "BGL_IFINBOXP" , 16 }, { 0x74, "BGL_ADDCAT" , 6 }, { 0x75, "BGL_ADDMNT" , 4 }, - { 0x76, "BGL_BGL" , 2 }, - { 0x77, "BGL_SCALE_AGL" , 32 }, + { 0x76, "BGL_BGL - Perspective", 2 }, + { 0x77, "BGL_SCALE_AGL - RefPoint", 32 }, { 0x78, "BGL_ROAD_CONTW" , 10 }, { 0x79, "BGL_RIVER_CONTW" , 10 }, { 0x7a, "BGL_GFACET_TMAP" , -1 }, Index: ssgconf.h =================================================================== RCS file: /cvsroot/plib/plib/src/ssg/ssgconf.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ssgconf.h 7 Nov 2001 23:51:10 -0000 1.5 +++ ssgconf.h 7 Jun 2002 23:11:38 -0000 1.6 @@ -49,5 +49,7 @@ #define SSG_LOAD_TGA_SUPPORTED #define SSG_LOAD_BMP_SUPPORTED #define SSG_LOAD_MDL_SUPPORTED +#define SSG_LOAD_BGL_SUPPORTED +#define SSG_LOAD_MDL_BGL_TEXTURE_SUPPORTED #endif |