Scott McMillan (scott++at++ht.com)
Mon, 19 Aug 1996 11:00:12 -0400 (EDT)
This seems like overkill to me. We just draw text and graphics to the
framebuffer/window of the main channel in a post-pfDraw function. It works
for us in OpenGL. This has come up a number of times, so I have included
code that also loads in fonts too.
Here's the second half of the draw function:
// ========= DRAW =========
// invoke Performer draw-processing for this frame
pfDraw();
// ======= POST DRAW ======
// set up ortho viewing
glDepthFunc(GL_ALWAYS);
glDepthMask(GL_FALSE);
pfPushState();
pfBasicState();
static pfMatrix tempmat;
glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat *)tempmat.mat);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf((GLfloat *)pfIdentMat.mat);
glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
pfPushIdentMatrix();
// ALL ORTHO2 DRAW ROUTINES GO HERE
// output heads-up display information
if (G_shared->HUD_flag)
{
displayHUD();
}
// RESTORE GRAPHICS STATE
pfPopMatrix();
glMatrixMode(GL_PROJECTION);
glLoadMatrixf((GLfloat *)tempmat.mat);
glMatrixMode(GL_MODELVIEW);
pfPopState();
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
Here's what the displayHUD() function looks like:
//----------------------------------------------------------------------
// Function: displayHUD
// Summary: output the heads-up (overlay) display to GUI
// Parameters: none
// Returns: none
//----------------------------------------------------------------------
void displayHUD()
{
// DRAW THE CROSSHAIRS
float linelen = .05f;
float linesep = 0.01;
glColor3ub(55,168,255);
glBegin(GL_LINES);
// the cross hairs
glVertex2f(0.5-linelen-linesep, 0.5);
glVertex2f(0.5-linesep, 0.5);
glVertex2f(0.5+linelen+linesep, 0.5);
glVertex2f(0.5+linesep, 0.5);
glVertex2f(0.5, 0.5-linelen-linesep);
glVertex2f(0.5, 0.5-linesep);
glVertex2f(0.5, 0.5+linelen+linesep);
glVertex2f(0.5, 0.5+linesep);
glEnd();
// Print text (graphically) to screen
glColor3ub(44, 106, 249);
// current time
char text[100];
sprintf(text, "Time: %5.2f sec.", G_shared->time);
glRasterPos2f(0.02, 0.02);
drawXFontString(fontDLHandleS, text);
}
Doing fonts was not exactly straight forward (credit goes to Paul Sherman for
working this stuff out). Here are some of the things that need to be added:
Variables:
static char fontNameS[] = "-*-courier-medium-r-*-*-13-*-*-*-*-*-iso8859-*";
static XFontStruct *fontInfoS;
int fontDLHandleS;
#define FIRSTGLYPH 32
#define LASTGLYPH 128
Loading fonts during initialization I was told that this should be executed the
first time through the draw process, however I have had success in calling it
after the pw->open() (pfPipeWindow) function in the function
(openPipeWindow for example) specified by
pw->setConfigFunc(openPipeWindow);
that is called when pw->config() is executed:
fontInfoS = XLoadQueryFont(xdisplay, fontNameS);
if(fontInfoS == NULL){
pfNotify(PFNFY_FATAL,PFNFY_USAGE,
"loadXFont: Couldn't load Small X font\n");
exit(1);
}
// Create GL display lists for fonts
fontDLHandleS = glGenLists((GLuint) LASTGLYPH + 1);
if(fontDLHandleS == 0)
{
pfNotify(PFNFY_FATAL, PFNFY_USAGE, "loadXFont: Couldn't get %d "
"display lists for Small Font\n", LASTGLYPH + 1);
exit(1);
}
glXUseXFont(fontInfoS->fid, FIRSTGLYPH, LASTGLYPH - FIRSTGLYPH + 1,
fontDLHandleS + FIRSTGLYPH);
Drawing fonts on screen
//----------------------------------------------------------------------------
// Function:
// Summary:
// Parameters:
// Returns:
//----------------------------------------------------------------------------
void drawXFontString(int fontDLHandle, char *s)
{
glPushAttrib(GL_LIST_BIT);
glListBase(fontDLHandle);
glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *)s);
glPopAttrib();
}
Hope this helps,
scott
-- Scott McMillan | HT Medical, Inc. | Developing virtual environ- scott++at++ht.com | http://www.ht.com | ment medical and surgical Ph: 301-984-3706 | 6001 Montrose Rd., St. 902 | simulations and surgery Fax: 301-984-2104 | Rockville, MD 20852 | simulation creation tools.======================================================================= List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/ Submissions: info-performer++at++sgi.com Admin. requests: info-performer-request++at++sgi.com
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:53:23 PDT