Setting color of overlay text in scene

New Message Reply Date view Thread view Subject view Author view

From: Simon C Mills (simon++at++wgs.estec.esa.nl)
Date: 09/12/2001 09:35:49


Hi all,

I want to place some text label attached to objects in the scene.
However, I'm having trouble setting the color of this text correctly. I
was basing my code in the standard example
/usr/share/Performer/src/pguide/libpf/C/text.c. I attach a modified
version to show the problem - the text in the scene always comes out
white no matter what, and the text over scene drawn after that comes out
blue, not red as I expected from the code. There would seem to be
nothing wrong. Can anyone shed any light on this?

Using Performer 2.2, IRIX 6.5.12m.

Regards, Simon
_______________________________________________________________________

Simon Mills
Modelling & Simulation Section (TOS-EMM) Tel: +31 (0)71 565 3725
European Space Agency (ESA/ESTEC) Fax: +31 (0)71 565 5420
Postbus 299, 2200AG Noordwijk e-mail: Simon.Mills++at++esa.int
The Netherlands http://www.estec.esa.nl/wmwww/EMM
_______________________________________________________________________

/*
 * Copyright 1995, Silicon Graphics, Inc.
 * ALL RIGHTS RESERVED
 *
 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
 * States. Use of a copyright notice is precautionary only and does not
 * imply publication or disclosure.
 *
 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
 * Use, duplication or disclosure by the Government is subject to restrictions
 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without
 * fee, provided that (i) the above copyright notices and this
 * permission notice appear in all copies of the software and related
 * documentation, and (ii) the name of Silicon Graphics may not be
 * used in any advertising or publicity relating to the software
 * without the specific, prior written permission of Silicon Graphics.
 *
 * THE SOFTWARE IS PROVIDED "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 SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL,
 * INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY
 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY
 * THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE
 * OR PERFORMANCE OF THIS SOFTWARE.
 *
 * text.c: simple Performer program to demonstrate using
 * GL text
 *
 * $Revision: 1.25 $
 * $Date: 1995/12/08 23:23:09 $
 *
 */

#include <stdlib.h>
#include <string.h>

#include <Performer/pf.h>
#include <Performer/pfdu.h>

static void DrawChannel(pfChannel *chan, void *data);

static pfMatrix idmat ={{1.0f, 0.0f, 0.0f, 0.0f},
                        {0.0f, 1.0f, 0.0f, 0.0f},
                        {0.0f, 0.0f, 1.0f, 0.0f},
                        {0.0f, 0.0f, 0.0f, 1.0f}};

pfSphere *bsphere;

#ifndef IRISGL /* OPENGL */

/*
 * Would normally use pfuXFont routines, see pfuXFont man page
 */

static char fontName[] ="-*-courier-bold-r-normal--14-*-*-*-m-90-iso8859-1";
static int fontDLHandle;
static XFontStruct *fontInfo;

#define FIRSTGLYPH 32
#define LASTGLYPH 128

void loadXFont(void)
{
    Display *xdisplay;

        /* get font from X Server */
    xdisplay = pfGetCurWSConnection();
    fontInfo = XLoadQueryFont(xdisplay, fontName);
    if(fontInfo == NULL){
        pfNotify(PFNFY_FATAL, PFNFY_USAGE, "loadXFont: Couldn't load X font\n");
        exit(1);
    }

        /* Create GL display lists for font */
    pfNotify(PFNFY_NOTICE, PFNFY_PRINT, "loadXFont: making X font display "
        "lists\n");
    fontDLHandle = glGenLists((GLuint) LASTGLYPH + 1);
    if(fontDLHandle == 0)
    {
        pfNotify(PFNFY_FATAL, PFNFY_USAGE, "loadXFont: Couldn't get %d "
            "display lists\n", LASTGLYPH + 1);
        exit(1);
    }
    glXUseXFont(fontInfo->fid, FIRSTGLYPH, LASTGLYPH - FIRSTGLYPH + 1,
        fontDLHandle + FIRSTGLYPH);
}

void drawXFontString(char *s)
{
    glPushAttrib(GL_LIST_BIT);
    glListBase(fontDLHandle);
    glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *)s);
    glPopAttrib();
}

#endif /* OPENGL */

static void OpenPipeWin(pfPipeWindow *pw)
{
    pfOpenPWin(pw);
#ifndef IRISGL
    loadXFont();
#endif
}

static void
    DrawChannel (pfChannel *channel, void *data)
{
    static pfMatrix tempmat, tempmat2;
    
    pfClearChan (channel);
    pfDraw();
    
#ifdef IRISGL

    zfunction (ZF_ALWAYS); /* text always drawn */
    zwritemask (0x0);

#else /* OPENGL */

    glDepthFunc(GL_ALWAYS); /* always draw */
    glDepthMask(GL_FALSE);

#endif /* GL type */
    
    /* text moving with the scene */
    pfPushState();
    
    pfBasicState();
    
#ifdef IRISGL

    cmov (0.5f * bsphere->radius, 0.0f, 0.5f * bsphere->radius);
    cpack(0xFFFFFF);
    charstr ("Text-in-Scene");

#else /* OPENGL */

    glRasterPos3f(0.5f * bsphere->radius, 0.0f, 0.5f * bsphere->radius);
    glColor3ub(0, 0, 255);
    drawXFontString("Text-in-Scene (blue)");

    
#endif /* GL type */
    
    pfPopState();
    
    /* text overlaid on top of scene, like a HUD */
    pfPushState();
    pfBasicState();
    
#ifdef IRISGL

    mmode (MPROJECTION);
    getmatrix (tempmat);
    mmode (MVIEWING);
    
    ortho2 (-10.0f, 10.0f, -10.0f, 10.0f);

#else /* OPENGL */

    glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat *)tempmat);

    glMatrixMode(GL_PROJECTION);
    glLoadMatrixf((GLfloat *)idmat);
    glOrtho(-10.0, 10.0, -10.0, 10.0, 1.0, -1.0);

    glMatrixMode(GL_MODELVIEW);

#endif /* GL type */
    
    pfPushMatrix();
    pfLoadMatrix(idmat);

#ifdef IRISGL

    cmov2 (-3.0f, 0.0f);
    charstr ("text over scene");

#else /* OPENGL */

    glRasterPos2f (-3.0f, 0.0f);
    glColor3ub(255, 0, 0);
    drawXFontString("text over scene (red)");

#endif /* GL type */

    pfPopMatrix();
    
#ifdef IRISGL

    mmode (MPROJECTION);
    loadmatrix (tempmat);
    mmode (MVIEWING);
    
#else /* OPENGL */

    glMatrixMode(GL_PROJECTION);
    glLoadMatrixf((GLfloat *)tempmat);
    glMatrixMode(GL_MODELVIEW);

#endif /* GL type */

    pfPopState();
    
#ifdef IRISGL

    zfunction (ZF_LEQUAL); /* the default */
    zwritemask (0xffffffff);

#else /* OPENGL */

    glDepthFunc(GL_LEQUAL);
    glDepthMask(GL_TRUE);

#endif /* GL type */
}

/*
 * Usage() -- print usage advice and exit. This
 * procedure is executed in the application process.
 */
static void
    Usage (void)
{
    pfNotify(PFNFY_FATAL, PFNFY_USAGE, "Usage: text file.ext ...\n");
    exit(1);
}

int
    main (int argc, char *argv[])
{
    float t = 0.0f;
    pfScene *scene;
    pfPipe *p;
    pfPipeWindow *pw;
    pfChannel *chan;
    pfNode *root;
    
    if (argc < 2)
        Usage();
    
    /* Initialize Performer */
    pfInit();
    
    /* Use default multiprocessing mode based on number of
     * processors.
     */
    pfMultiprocess( PFMP_DEFAULT );
    bsphere = (pfSphere*) pfMalloc (sizeof(pfSphere), pfGetSharedArena());
    
    /* Load all loader DSO's before pfConfig() forks */
    pfdInitConverter(argv[1]);

    /* Configure multiprocessing mode and start parallel
     * processes.
     */
    pfConfig();
    
    /* Append to PFPATH additional standard directories where
     * geometry and textures exist
     */
    pfFilePath(".:/usr/share/Performer/data");
    
    /* Read a single file, of any known type. */
    if ((root = pfdLoadFile(argv[1])) == NULL)
    {
        pfExit();
        exit(-1);
    }
    
    /* Attach loaded file to a pfScene. */
    scene = pfNewScene();
    pfAddChild(scene, root);
    
    /* determine extent of scene's geometry */
    pfGetNodeBSphere (scene, bsphere);
    
    /* Create a pfLightSource and attach it to scene. */
    pfAddChild(scene, pfNewLSource());
    
    /* Configure and open GL window */
    p = pfGetPipe(0);
    pw = pfNewPWin(p);
    pfPWinType(pw, PFPWIN_TYPE_X);
    pfPWinName(pw, argv[0]);
    pfPWinOriginSize(pw, 0, 0, 500, 500);
    /* Open and configure the GL window. */
    pfPWinConfigFunc(pw, OpenPipeWin);
    pfConfigPWin(pw);

    
    /* Create and configure a pfChannel. */
    chan = pfNewChan(p);
    pfChanTravFunc(chan, PFTRAV_DRAW, DrawChannel);
    pfChanScene(chan, scene);
    pfChanNearFar(chan, 1.0f, 10.0f * bsphere->radius);
    pfChanFOV(chan, 45.0f, 0.0f);
    
    
    /* Simulate for twenty seconds. */
    while (t < 20.0f)
    {
        float s, c;
        pfCoord view;
        
        /* Go to sleep until next frame time. */
        pfSync();
        
        /* Compute new view position. */
        t = pfGetTime();
        pfSinCos(45.0f*t, &s, &c);
        pfSetVec3(view.hpr, 45.0f*t, -10.0f, 0);
        pfSetVec3(view.xyz, 2.0f * bsphere->radius * s,
                  -2.0f * bsphere->radius *c,
                  0.5f * bsphere->radius);
        pfChanView(chan, view.xyz, view.hpr);
        
        /* Initiate cull/draw for this frame. */
        pfFrame();
    }
    
    /* Terminate parallel processes and exit. */
    pfExit();
    
    return 0;
}


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Sep 12 2001 - 08:32:36 PDT

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