dirk/C++/pf/pfHello


Ravensburg, 10-02-28

pfHello – Hello OpenGL Performer

Source Code

Text File pfHello.cc:
/** @file simple OpenGL Performer sample
 * (to check proper compile/link/execute)
 *
 * Last CVS checkin:
 * $Date: $
 * $Author: scheff $
 */

/**************************************************************************/

// OpenGL Performer header:
#include <Performer/pr/pfGeoState.h>
#include <Performer/pr/pfGeoSet.h>
#include <Performer/pf/pfGeode.h>
#include <Performer/pf/pfDCS.h>
#include <Performer/pf/pfLightSource.h>
#include <Performer/pf/pfScene.h>
#include <Performer/pf/pfPipeWindow.h>
#include <Performer/pf/pfChannel.h>

/**************************************************************************/

/// coordinates for the cube
static float coords[][3] = {
  { -0.5f, +0.5f, +0.5f },
  { -0.5f, -0.5f, -0.5f },
  { -0.5f, -0.5f, +0.5f },
  { +0.5f, -0.5f, +0.5f },
  { -0.5f, +0.5f, +0.5f },
  { +0.5f, +0.5f, +0.5f },
  { +0.5f, +0.5f, -0.5f },
  { +0.5f, -0.5f, +0.5f },
  { +0.5f, -0.5f, -0.5f },
  { -0.5f, -0.5f, -0.5f },
  { +0.5f, +0.5f, -0.5f },
  { -0.5f, +0.5f, -0.5f },
  { -0.5f, +0.5f, +0.5f },
  { -0.5f, -0.5f, -0.5f }
};

/// normals for the cube
static float normals[][3] = {
  { -1.0f, 0.0f, 0.0f }, 
  { 0.0f, -1.0f, 0.0f },
  { 0.0f, 0.0f, 1.0f },
  { 0.0f, 0.0f, 1.0f },
  { 0.0f, 1.0f, 0.0f }, 
  { 1.0f, 0.0f, 0.0f }, 
  { 1.0f, 0.0f, 0.0f }, 
  { 0.0f, -1.0f, 0.0f },
  { 0.0f, 0.0f, -1.0f }, 
  { 0.0f, 0.0f, -1.0f }, 
  { 0.0f, 1.0f, 0.0f }, 
  { -1.0f, 0.0f, 0.0f }  
}; 

/// primitive lengths
int primLens[] = { 14 };

/// per-vertex colors
static float colors[][4] = {
  { 1.000f, 0.000f, 0.000f, 1.0f }, 
  { 1.000f, 0.367f, 0.000f, 1.0f }, 
  { 1.000f, 0.727f, 0.000f, 1.0f }, 
  { 0.909f, 1.000f, 0.000f, 1.0f }, 
  { 0.545f, 1.000f, 0.000f, 1.0f }, 
  { 0.182f, 1.000f, 0.000f, 1.0f }, 
  { 0.000f, 1.000f, 0.182f, 1.0f }, 
  { 0.000f, 1.000f, 0.545f, 1.0f }, 
  { 0.000f, 1.000f, 0.909f, 1.0f }, 
  { 0.000f, 0.727f, 1.000f, 1.0f }, 
  { 0.000f, 0.367f, 1.000f, 1.0f }, 
  { 0.000f, 0.000f, 1.000f, 1.0f }   
};

/**************************************************************************/

/** provides the main function of application.
 *
 * @param argc number of command line arguments
 * @param argv pointer to array of pointers to strings with command line
 *        arguments
 * @return 0 ... application exited regularly\n
 *         else ... execution of application aborted
 */
int main(int argc, char *argv[], char *env[])
{
  // setup Performer
  pfInit();
  pfMultiprocess(PFMP_DEFAULT);
  pfConfig();
  // setup scene
  pfGeoState *pPfGState = new pfGeoState;
  pPfGState->setMode(PFSTATE_ENLIGHTING, PF_ON);
  pfGeoSet *pPfGSet = new pfGeoSet;
  pPfGSet->setPrimType(PFGS_FLAT_TRISTRIPS);
  pPfGSet->setNumPrims(1);
  pPfGSet->setPrimLengths(primLens);
  pPfGSet->setAttr(PFGS_COORD3, PFGS_PER_VERTEX, coords, 0);
  pPfGSet->setAttr(PFGS_NORMAL3, PFGS_PER_VERTEX, normals, 0);
  pPfGSet->setAttr(PFGS_COLOR4, PFGS_PER_VERTEX, colors, 0);
  pPfGSet->setGState(pPfGState);
  pfGeode *pPfGeode = new pfGeode;
  pPfGeode->addGSet(pPfGSet);
  pfDCS *pPfDCS = new pfDCS;
  pPfDCS->addChild(pPfGeode);
  pfLightSource *pPfLSource = new pfLightSource;
  pPfLSource->setPos(-0.3f, -0.6f, 1.0f, 0.0f);
  pfScene *pPfScene = new pfScene;
  pPfScene->addChild(pPfDCS);
  pPfScene->addChild(pPfLSource);
  // set up pipe window
  pfPipe *pPfPipe = pfGetPipe(0);
  pfPipeWindow *pPfPipeWin = new pfPipeWindow(pPfPipe);
  pPfPipeWin->setWinType(PFPWIN_TYPE_X);
  pPfPipeWin->setName("OpenGL Performer - A Cube made from one TriStrip");
  pPfPipeWin->setOriginSize(0, 0, 500, 500);
  pPfPipeWin->open();
  // create channel
  pfChannel *pPfChan = new pfChannel(pPfPipe);
  pPfChan->setScene(pPfScene);
  pPfChan->setFOV(45.0f, 0.0f);
  // determine extent of scene's geometry
  pfSphere bSphere;
  pPfScene->getBound(&bSphere);
  pPfChan->setNearFar(0.1f, 50.0f * bSphere.radius);
  pfVec3 pos(0.0f, -5.0f, 0.5f), dir(0.0f, -10.0f, 0.0f);
  pPfChan->setView(pos, dir);
  // simulate for sixty seconds.
  for (double t = 0.0; t < 60.0f; t = pfGetTime()) {
    pfSync();               
    pfFrame();
    // turn dcs with cube
    pPfDCS->setRot(45.0f * t, -20.0f * t + 10.f, 0.0f);
  }
  // Terminate parallel processes and exit
  pfExit();
  // done
  return 0;
}

Output

This was a test run on MS Windows XP:

Console:
                                                                                
PF                             ================================================
PF                             =            OpenGL Performer 3.2.2            =
PF                             =                 DEMO EDITION                 =
PF                             ================================================
PF                             =   For information about purchasing the full  =
PF                             =        OpenGL Performer product, visit       =
PF                             =     http://www.sgi.com/software/performer/   =
PF                             ================================================
Snapshot:
Snapshot

Conclusion

I didn't expect to get it compiled, linked, and running with MS Visual C++ 2008. Thus, I'm glad it does.

Did you notice that the whole cube is enveloped in one triangle strip?

The unrolled cube
The unrolled cube

Files

Text File pfHello.cc...C++ source code
MS Visual C++ 2008 Project File pfHello.vcproj...MS Visual C++ 2008 project file

dirk/C++/pf/pfHello


Last modified: Sun Feb 28 18:30:06 2010