R: [Plib-devel] commandline conversion program
Brought to you by:
sjbaker
From: Paolo L. <p.l...@ci...> - 2005-01-10 09:13:25
|
> -----Messaggio originale----- > Da: pli...@li... > [mailto:pli...@li...] Per conto di > br...@sa... > Inviato: domenica 9 gennaio 2005 20.20 > A: pli...@li... > Oggetto: Re: [Plib-devel] commandline conversion program > > > > > You need to understand how non-visible OpenGL rendering > contexts work. > > Ok, pbuffers it will be.... No need to go to pbuffers for a windowless Ogl context. In GLUT one can glutCreateWindow(), so having the Ogl context, yet the window will not been show until the first redraw, that one coudn't ever do. As an example just look at the loadmaker utility source code that I copied below: /* LODMaker - a simple command-line utility that takes in a set of 3d model files as arguments (with accompanying distances). It outputs a .ssg file containing a tree with a ssgRangeSelector and the model ssgEntities. "Why would such a util be useful?" you ask. It's useful because it allows PLIB users to add level-of-detail models to their scenes *without any changes to their code*. Instead of loading an ordinary model file, the author just uses the .ssg file. Bam, instant lod-enabled scene. Author: Andrew Sampson (ads4260 AT rit.edu, dinosaur AT epix.net) Web site: http://citybuilder.sf.net , http://kludge3d.sf.net Date: July, 2003 This program is released under the GNU GPL. For more details on what this implies, see http://www.gnu.org */ #include <GL/glut.h> #include <stdio.h> #include <stdlib.h> #include <plib/ssg.h> #define LOD_DIST_MIN 0.0 #define LOD_DIST_MAX 10000.0 #define LOD_DIST_INFINITY 1000000.0 #define MAX_LODS 6 void usage( int argc, char **argv ) { printf( "Usage: %s outputfile modelname distance [modelname distance] ...\n", argv[0] ); printf( "\twhere modelname is the name of a model to load, and \n" ); printf( "\tdistance is the distance beyond which the model should not be shown\n" ); printf( "\tThe resulting SSG file will be stored in outputfile.\n" ); printf( "\tUp to %i model-distance pairs may be listed.\n", MAX_LODS ); printf( "\tModel files will be searched for in ./models, and \n" "\ttexture files will be searched for in ./images\n" ); } void initWindow ( int w, int h ) { int fake_argc = 1 ; char *fake_argv[3] ; fake_argv[0] = "lodmaker"; fake_argv[1] = "LODmaker - ignore this window"; fake_argv[2] = NULL ; glutInitWindowPosition ( 0, 0 ) ; glutInitWindowSize ( w, h ) ; glutInit ( &fake_argc, fake_argv ) ; glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ) ; glutCreateWindow ( fake_argv[1] ) ; } int main( int argc, char **argv ) { ssgEntity *models[MAX_LODS]; int numLods = 0; int i; float lodDist; float lodDists[MAX_LODS+1]; ssgLoaderOptions *loader_opts = new ssgLoaderOptions(); if( argc < 4 || argc > (MAX_LODS*2) + 2 ) { usage( argc, argv ); exit( 0 ); } initWindow ( 64, 64 ); ssgInit(); ssgModelPath ( "models" ) ; ssgTexturePath ( "images" ) ; lodDists[0] = 0.0; /* load files */ for( i = 2; i < argc; i+=2 ) { models[numLods] = ssgLoad( argv[i], NULL ); if( models[numLods] == NULL ) { printf( "Bad file; barfed on file %s\n", argv[i] ); exit( 1 ); } lodDist = atof(argv[i+1]); //strtof( argv[i+1], NULL ); if( !(lodDist > LOD_DIST_MIN && lodDist < LOD_DIST_MAX ) ) { printf( "lod dist must be between %f and %f\n", LOD_DIST_MIN, LOD_DIST_MAX ); exit( 1 ); } lodDists[numLods+1] = lodDist; numLods++; } if( numLods > MAX_LODS ) { printf( "whup... that shouldn't happen\n" ); exit( 1 ); } /* set up scene graph and range selector */ ssgRoot *root = new ssgRoot(); ssgRangeSelector *rangeSel = new ssgRangeSelector(); root->addKid( rangeSel ); for( i = 0; i < numLods; i++ ) { rangeSel->addKid( models[i] ); } // since numLods+1 is specified, nothing beyond the last range will be drawn rangeSel->setRanges( lodDists, numLods+1 ); if( ssgSaveSSG( argv[1], root ) ) { printf( "combined model successfully written to file '%s'\n", argv[1] ); } else { printf( "failed to write combined model to file '%s'\n", argv[1] ); } ssgDelete( root ); return 0; } Greetings - Paolo |