RE: [info-performer] Overlay for HUD

Date view Thread view Subject view Author view

From: Michael Petrou (Michael.Petrou++at++sydac.com.au)
Date: 02/12/2004 14:49:31


This might be of help:

m_pos is a pfVec3 using the first two elements specifying the position 0 ->
1, which is left -> right, bottom -> top
m_size is a pfVec3 using the first two elements specifying the size of the
overlay, where 1, 1 is fullscreen (ala the ortho setup).

dont bother asking why this code is using pfVec3's for these...

void Overlay::Render()
{
    // Make sure performer is happy
    pfPushState();
    pfBasicState();

    // Setup the open gl state
    glPushAttrib(GL_ALL_ATTRIB_BITS);
    glPushMatrix();

    int zbuff = glIsEnabled(GL_DEPTH_TEST);
    if (zbuff)
        glDisable(GL_DEPTH_TEST);

    // Make the viewport a standard 1 x 1 for easy use
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // Iterate through all overlays and render each one
    if (m_enabled)
    {
        if (m_ptexture)
        {
            glEnable(GL_TEXTURE_2D);
            glEnable(GL_ALPHA_TEST);
            glEnable(GL_BLEND);
            glDisable(GL_LIGHTING);
            glDisable(GL_LIGHTING_BIT);

            int handle = m_ptexture->getGLHandle();
            glBindTexture(GL_TEXTURE_2D, handle);

            // Set the vertex color
            glColor4f(m_clear_color[0], m_clear_color[1], m_clear_color[2],
m_clear_alpha);

            // Draw the quad
            glBegin(GL_QUADS);
                glTexCoord2f(0.0f, 0.0f);
                glVertex3f(m_pos[0], m_pos[1], 0.0f);
                glTexCoord2f(1.0f, 0.0f);
                glVertex3f(m_pos[0] + m_size[0], m_pos[1], 0.0f);
                glTexCoord2f(1.0f, 1.0f);
                glVertex3f(m_pos[0] + m_size[0], m_pos[1] + m_size[1],
0.0f);
                glTexCoord2f(0.0f, 1.0f);
                glVertex3f(m_pos[0], m_pos[1] + m_size[1], 0.0f);
            glEnd();
        } // if
        else
        {
            // Set the vertex color
            glColor4f(m_clear_color[0], m_clear_color[1], m_clear_color[2],
m_clear_alpha);
            glDisable(GL_LIGHTING);
            glDisable(GL_LIGHTING_BIT);

            // Draw the quad
            glBegin(GL_QUADS);
                glVertex3f(m_pos[0], m_pos[1], 0.0f);
                glVertex3f(m_pos[0] + m_size[0], m_pos[1], 0.0f);
                glVertex3f(m_pos[0] + m_size[0], m_pos[1] + m_size[1],
0.0f);
                glVertex3f(m_pos[0], m_pos[1] + m_size[1], 0.0f);
            glEnd();
        } // else
    } // if

    if (zbuff)
        glEnable(GL_DEPTH_TEST);

    // Wait until gl is done!
    glFinish();

    // Reset the open gl state
    glPopMatrix();
    glPopAttrib();
    pfPopState();
} // Render

bool Overlay::BuildOverlay(std::string filename)
{
    if (m_ptexture)
        return false;

    if (filename.empty())
        return true;

    m_ptexture = new pfTexture();
    if (!m_ptexture->loadFile(filename.c_str()))
    {
        pfDelete(m_ptexture);
        m_ptexture = 0;
        return false;
    } // if

    m_ptexture->apply();
    return true;
}

-----Original Message-----
From: jcasilla [mailto:jcasilla++at++isoco.com]
Sent: Tuesday, 10 February 2004 6:22 PM
To: 'info-performer++at++sgi.com'
Cc: Simon.Mills++at++esa.int
Subject: Re: [info-performer] Overlay for HUD

Simon.Mills++at++esa.int wrote:
> It only makes sense to use the overlay planes if the HUD is static and
will
> not change frame to frame. Changing to and from overlay planes usually
incurs
> some overhead. For your application it looks like it will be best to use
post
> draw callbacks.
>
> Regards, Simon
> _______________________________________________________________________

Hi,

Yes, the HUD has dynamic elements so I'm using postdraw callbacks. I
want to base the code in the Velab hud classes and Aqua demo, that is,
inheriting a class from pfChannel to get the hud in a separate channel.

Although drawing text is working well, when I try to draw some lines
with opengl calls in the draw method nothing seems to be drawn. ¿Do I
have to set up a special channel configuration for this?

Basically, the calls in the draw method are as follow:

        pfPushState();
        pfBasicState();
        glDrawBuffer(GL_BACK);

        // 2D OpenGL calls

        pfPopState();

This works well when drawing text, but not with geometry. The channel
set up is as follow:

        chan->makeOrtho(0.0, 1.0, 0.0, 1.0);
        chan->setNearFar(0.5, 2.0);
        xyz.set(0, -1.0, 0);
        hpr.set(0, 0, 0);
        chan->setView(xyz, hpr);
        chan->setTravFunc(PFTRAV_CULL, (pfChanFuncType)MyCull);
        chan->setTravFunc(PFTRAV_DRAW, (pfChanFuncType)MyDraw);

Perhaps I'm missing some openGL set up staff like in text.C demo, but
having a look at velab hud code it seems that no special openGL set up
is needed.

Any help with this will be greatly appreciated.

Regards,

-- 
-------------------------------------------------------------------------
Joaquín Casillas Meléndez, R+D Engineer at iSOCO
Intelligent Software Components, S.A. http://www.isoco.com
Addr: Profesor Beltrán Báguena, 4, oficina 107, 46009 Valencia
Voice: +34 96 346 71 43 Fax: +34 96 346 71 42

----------------------------------------------------------------------- List Archives, Info, FAQ: http://www.sgi.com/software/performer/ Open Development Project: http://oss.sgi.com/projects/performer/ Submissions: info-performer++at++sgi.com Admin. requests: info-performer-request++at++sgi.com -----------------------------------------------------------------------


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Thu Feb 12 2004 - 14:52:35 PST