Chris Malley (cmalley++at++pixelzoom.com)
Wed, 30 Sep 1998 09:35:20 -0600
See attached sample program.
-Chris
-- Chris Malley PixelZoom, Inc. Voice: +1.303.494.8849 835 Orman Drive EMail: cmalley++at++pixelzoom.com Boulder CO 80303-2616
//------------------------------------------------------------------------------ // // THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" // AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, // INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR // FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL PIXELZOOM, INC. // BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, SPECIAL, INCIDENTAL, // INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER, // INCLUDING WITHOUT LIMITATION, LOSS OF PROFIT, LOSS OF USE, SAVINGS OR // REVENUE, OR THE CLAIMS OF THIRD PARTIES, WHETHER OR NOT PIXELZOOM, INC. // HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON // ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE // POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. // //----------------------------------------------------------------------------- // // pfxwin.C // // Configure Performer to render in an existing X window. // This example was tested using Performer 2.2 on IRIX 6.3. // // CC -o pfxwin pfxwin.C -lpf_ogl -lpfdu_ogl -lpfutil_ogl -lfpe \ // -lGLw -lGL -lXext -lXm -lXt -lX11 // //-----------------------------------------------------------------------------
#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/prctl.h> #include <Xm/Xm.h> #include <GL/GLwMDrawA.h> #include <Performer/pf/pfChannel.h> #include <Performer/pf/pfDCS.h> #include <Performer/pf/pfLightSource.h> #include <Performer/pf/pfNode.h> #include <Performer/pf/pfPipe.h> #include <Performer/pf/pfPipeWindow.h> #include <Performer/pf/pfScene.h> #include <Performer/pfdu.h>
// We'll be rendering this model. // If it's not on your system, then substitute one that is. #define MODEL_FILE "/usr/share/Performer/data/cow.obj"
// Some options for rendering in another thread include: // (1) sproc and shared address space // (2) pthreads and shared address space // (3) fork/exec and some IPC mechanism (shared memory, sockets, etc) // // We'll use (1), and will therefore make our windowID a global // variable. // Window windowId;
// Entry point for the rendering process. void render( void* );
// The main process sets up the user interface, and then // starts the rendering process. If you want to have both // processes rendering to the drawable, then you'll need some // synchronization mechanism to ensure that both processes // don't try to make current the drawable at the same time. // void main( int argc, char** argv ) { Widget toplevel, glwidget; XtAppContext app; int pid; toplevel = XtVaAppInitialize( &app, "pfwin", NULL, 0, &argc, argv, NULL, XmNwidth, 300, XmNheight, 300, NULL );
// Many GLX applications do their rendering in a GL/Motif // drawing area, so that's what we'll use for the rendering window. glwidget = GLwCreateMDrawingArea( toplevel, "glwidget", NULL, 0 );
// If you forget to manage the drawing area, you won't see // anything rendered. XtManageChild( glwidget );
XtRealizeWidget( toplevel );
// This must be done after the window is realized, or // you won't get a valid window id. windowId = XtWindow( glwidget );
// Start the rendering process. pid = sproc( render, PR_SALL ); assert( pid != -1 );
XtAppMainLoop( app );
} // main( )
// The render process will handle all rendering to the drawable. // In this case, the rendering is done by Performer.
void render( void* ) { Display* display; pfPipe* pipe; pfPipeWindow* pipeWindow; pfChannel* channel; pfScene* scene; pfDCS* dcs; pfNode* node; pfLightSource* light;
// Each process requires its own display connection. display = XOpenDisplay( ":0" ); assert( display );
// Initialize Performer. pfInit( ); pfMultiprocess( PFMP_DEFAULT ); pfConfig( );
// Create the graphics pipeline. See pfPipe(3pf). pipe = pfGetPipe( 0 ); pipeWindow = new pfPipeWindow( pipe ); assert( pipeWindow ); pipeWindow->setWSWindow( display, windowId ); channel = new pfChannel( pipe ); assert( channel );
// Configure the channel, or you won't see anything. pfCoord view; view.hpr.set( 0.0f, -90.0f, 0.0f ); view.xyz.set( 0.0f, 0.0f, 20.0f ); channel->setView(view.xyz, view.hpr);
// Read some geometry from a model file. node = pfdLoadFile( MODEL_FILE ); if ( ! node ) { fprintf( stderr, "Cannot find mode file %s", MODEL_FILE ); exit( 1 ); }
// Attach the geometry to a DCS. dcs = new pfDCS( ); assert( dcs ); dcs->addChild( node );
// Create a light, or you won't see the geometry. light = new pfLightSource( ); assert( light );
// Create the scene graph. scene = new pfScene( ); assert( scene ); scene->addChild( dcs ); scene->addChild( light ); channel->setScene( scene );
// Open the pipewindow. pipeWindow->open();
// Not-so-interesting rendering loop. for ( ;; ) { pfFrame( ); } }
// end of file
This archive was generated by hypermail 2.0b2 on Wed Sep 30 1998 - 08:35:38 PDT