ex1: A simple declaration and initialization of 3 channels.
void
InitChannel(void)
{
/* The channels are often declared globally */
pfChannel *chan, *chan2, *chan3;
/* Initialize and attach the channels */
chan = new pfChannel(pfGetPipe(0));
chan2 = new pfChannel(pfGetPipe(0));
chan3 = new pfChannel(pfGetPipe(0));
/* Form a channel group with 'chan' as the master */
chan->attach(chan2);
chan->attach(chan3);
/* Initialize all attributes shared between channels */
/* Set the callback routines for the pfChannel */
chan->setTravFunc(PFTRAV_APP, AppFunc);
chan->setTravFunc(PFTRAV_CULL, CullFunc);
chan->setTravFunc(PFTRAV_DRAW, DrawFunc);
/* Attach the visual database to the channels */
chan->setScene(scene);
/* Attach the EarthSky model to the channels */
chan->setESky(eSky);
/* Initialize the near and far clipping planes */
chan->setNearFar(near, far);
/* Initialize the viewing position and direction */
chan->setView(initView->xyz, initView->hpr);
/* Set channel frustums */
chan->setAutoAspect(PFFRUST_CALC_VERT);
chan->makeSimple(fov);
.....
}
ex2: Setting Viewports and ViewOffsets of 2 channels to create a stereo
image.
void
InitChannel(void)
{
float paralax = 0.5f /* Convergence */
float ioc = 0.02f /* Intraocular distance */
int share; /* Share mask */
pfVec3 xyz, hpr;
.....
chan->attach(chan2);
.....
/* channels need to share a viewport ---> Viewports should be shared
automatically. This should be unnecessary unless multiple
pipes are used.*/
/* Get the default */
share = chan->getShare();
/* Add in the viewport share bit */
share |= PFCHAN_VIEWPORT;
share &= ~PFCHAN_FOV;
chan->setShare(share);
/* Set the Viewport and ViewOffsets for both channels */
chan->setViewport(0.0f, 1.0f, 0.0f, 1.0f);
/* Set left channel offsets */
hpr.set(paralax, 0.0f, 0.0f);
xyz.set(-ioc, 0.0f, 0.0f);
chan->setViewOffsets(xyz, hpr);
/* Set right channel offsets */
hpr.set(-paralax, 0.0f, 0.0f);
xyz.set(ioc, 0.0f, 0.0f);
chan2->setViewOffsets(xyz, hpr);
.....
}
ex3: Setting the Viewports and Offsets of 2 channels with each view in a
different direction. Click here for a
picture of front and 45 degrees left views as seen from a car in
Hank. (Click here for the same picture
with a gap between the channels).
void
InitChannel(void)
{
pfVec3 xyz, hpr;
float fov = 45.0;
.....
/* Set front channel offsets */
chan->setViewport(1.0f/2.0f, 1.0f, 0.0f, 1.0f);
hpr.set(0.0f, 0.0f, 0.0f);
xyz.set(0.0f, 0.0f, 0.0f);
chan->setViewOffsets(xyz, hpr);
/* Set left channel offsets */
chan2->setViewport(0.0f, 1.0f/2.0f, 0.0f, 1.0f);
hpr.set(45.0f, 0.0f, 0.0f);
xyz.set(0.0f, 0.0f, 0.0f);
chan2->setViewOffsets(xyz, hpr);
.....
{
Return to the top.
ex4: Choosing a buffer by alternating with each call to the draw
callback.
void
PreDraw(pfChannel *chan, void *data)
{
static long stereoFlag = 0 ;
if (stereoFlag)
glDrawBuffer(GL_BACK_RIGHT);
else
glDrawBuffer(GL_BACK_LEFT);
stereoFlag = !stereoFlag;
.....
}
Return to the top.
ex5: Clearing and drawing two partially overlapping channels.
void
PreDraw(void)
{
.....
/* Clear the frame buffer of the background channel */
chan->clear();
/* Draw the background channel */
pfDraw();
/* Clear the frame buffer of the foreground channel */
chan2->clear();
/* Draw the foreground channel */
pfDraw();
}
Return to the top.
ex6: A buffer swapping function.
void OpenWin(pfPipeWindow *pw)
{
.....
pfGetPipe(0)->setSwapFunc(StereoSwap(pw));
.....
}
pfPipeSwapFuncType StereoSwap(pfPipeWindow *pw)
{
pw->swapBuffers();
return 0; /* prevents warnings in compilation */
}
Return to the top.
ex7: One way to discover stereo capability (Note: this particular method
occasionally reports a falsely positive response)
void OpenWin(pfPipeWindow *pw)
{
int Stereo = 1; /* Stereo-Mode, default is on */
int stereo_flag = 0;
.....
pw->query(PFQWIN_STEREO,&stereo_flag);
if(stereo_flag==PFQFTR_FALSE)
{
cout << "Mono-Mode" << endl;
// here might be a good place to reset the channel
// viewing offsets since stereo isn't possible.
{
pfVec3 xyz, hpr;
xyz.set(0.0f, 0.0f, 0.0f);
hpr.set(0.0f, 0.0f, 0.0f);
chan->setViewOffsets(xyz,hpr);
chan2->setViewOffsets(xyz,hpr);
}
Stereo=0;
}
else
cout << "Stereo-Mode" << endl;
.....
}
Return to the top.
ex8: Setting the window attributes to allow for stereo.
static int FBAttrs[]={PFFB_DOUBLEBUFFER,
PFFB_STEREO,
None};
void
InitPipe(void)
{
pfPipeWindow *pw;
.....
pw->setFBConfigAttrs(FBAttrs); /* set window attributes */
pw->setConfigFunc(OpenWin); /* configuration function */
pw->config(); /* call to configure */
.....
}
Return to the top.
Return to the main page.