Re: HUD problems; how to use OpenGL?

New Message Reply Date view Thread view Subject view Author view

Fred Clyne (fred++at++octave.cambridge.com)
Sat, 3 Aug 1996 18:47:31 -0400


On Aug 3, 3:28pm, Sandeep S. Mulgund wrote:
> Subject: HUD problems; how to use OpenGL?
> I'm trying to use the example from the Performer FAQ to construct a HUD in a
> C++ Performer application (based on libpf and OpenGL). I've pasted in the
> relevant item from the FAQ below. However, the following commands are
> getting me into trouble:
>
> zfunction
> zwritemask
> ortho2
>
....
>
> Thanks,
>
> Sandeep Mulgund

Funny you should ask, I just did this today.
I am working in C but you should be able to translate. Also, this works
for both IrisGL and OpenGL. In the draw callback, after you render the
scene, add your call to the HUD function:

void MyDraw(pfChannel *chan, void *data)
{
pfClearChan(chan);
pfDraw();
DrawHUD();
}

The HUD drawing routine needs to set its perspective matrix with an
ortho command and the viewing matrix with some matrix commands. I
had trouble with the different coordinate systems being used, so be
careful. The scene is in Performer coordinates (z-up, y-away, x-right).
So I created my HUD with z and x coords to be "consistent".
I put my data in gsets and created an ortho frustum that I remember in
the shared data structure along with DCS nodes to move things around on
the HUD. I also didn't wory about saving the perspective matrix since
the HUD is drawn last and the matrix will be set again by the channel.

at init time:
frust = pfNewFrust(arena);
pfFrustNearFar(frust,-1.0f,1.0f);
pfMakeOrthoFrust(frust,left,right,bottom,top);
sharedData->frust = frust;
..
sharedData->numGsets = nn;
sharedData->gsetList[0] = ...
sharedData->dcsList[0] = ...

APP updates the DCS nodes each frame:
pfDCSRot(sharedData->dcsList[0],...

void DrawHUD(void)
{
pfMatrix mat;
int ii;

/* work in my own graphics state */
pfPushState();
pfBasicState();

/* turn of the zbuffer so this always shows on top */
#ifdef IRISGL
zbuffer(FALSE);
#else
#ifdef OPENGL
glDisable(GL_DEPTH_TEST);
#else
...Please Define IRISGL/OPENGL...
#endif
#endif

/* create the ortho projection */
pfApplyFrust(sharedData->frust);

/* set the view matrix - push a GL ident matrix on stack */
pfPushIdentMatrix();
/* rotate back to Perf coords */
pfRotate(PF_X,-90.f);

/* draw the HUD */
for (ii=0; ii<sharedData->numGsets; ++ii)
        {
        pfPushMatrix();
        pfGetDCSMat(sharedData->dcsList[ii],mat)
        pfMultMatrix(mat);
        pfDrawGSet(sharedData->gsetList[ii]);
        pfPopMatrix();
        }

/* restore the view matrix */
pfPopMatrix();

/* restore zbuffer testing */
#ifdef IRISGL
zbuffer(TRUE);
#else
#ifdef OPENGL
glEnable(GL_DEPTH_TEST);
#else
...Please Define IRISGL/OPENGL...
#endif
#endif

/* restore the graphics state */
pfPopState();

}

Hope this helps.

-- 

Fred Clyne

Cambridge Research Associates office: 703-790-0505 x 7211 1430 Spring Hill Road, Suite 200 fax: 703-790-0370 McLean, VA 22102 email: fred++at++cambridge.com

======================================================================= List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/ Submissions: info-performer++at++sgi.com Admin. requests: info-performer-request++at++sgi.com


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:53:18 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.