Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: drawing 2d overlays and HUD's

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2001
    Posts
    7

    drawing 2d overlays and HUD's

    I am having some trouble drawing a 2d overlay. I am currently trying to draw a quad that is 200x200 pixels in screen coordinates. If you could point out what is wrong in the following code or show your own I would highly appreciate it:

    bool CFrame: raw()
    {
    if (use_alpha)
    {
    glEnable(GL_BLEND); // Enable Blending
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Select The Type Of Blending
    }

    glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    glPushMatrix(); // Store The Projection Matrix
    glLoadIdentity(); // Reset The Projection Matrix
    gluOrtho2D(0,800,0,600); // Set Up An Ortho Screen
    glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
    glPushMatrix(); // Store The Modelview Matrix
    glLoadIdentity(); // Reset The Modelview Matrix
    glTranslated(0,0,0); // draw some stuff (blended, textured, alpha tested quad etc.)


    if(use_tex)
    {
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, tex.tex);
    glTexCoord2f(0.0f, 0.0f); glVertex2d( lBC.x, lBC.y); // Bottom Left Of The Texture and Quad
    glTexCoord2f(1.0f, 0.0f); glVertex2d( rBC.x, rBC.y); // Bottom Right Of The Texture and Quad
    glTexCoord2f(1.0f, 1.0f); glVertex2d( rTC.x, rTC.y); // Top Right Of The Texture and Quad
    glTexCoord2f(0.0f, 1.0f); glVertex2d( lTC.x, lTC.y); // Top Left Of The Texture and Quad
    glDisable(GL_TEXTURE_2D);
    }
    else
    {
    glColor4ub(col.r, col.g, col.b, col.a); // Color our quad
    glVertex2d( lBC.x, lBC.y); // Bottom Left Of The Texture and Quad
    glVertex2d( rBC.x, rBC.y); // Bottom Right Of The Texture and Quad
    glVertex2d( rTC.x, rTC.y); // Top Right Of The Texture and Quad
    glVertex2d( lTC.x, lTC.y); // Top Left Of The Texture and Quad
    }

    glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    glPopMatrix(); // Restore The Old Projection Matrix
    glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
    glPopMatrix();

    if (use_alpha)
    {
    glDisable(GL_BLEND);
    }
    return true;
    }

  2. #2

    Re: drawing 2d overlays and HUD's

    Easy: You are forgetting to bracket glVertex calls with glBegin(...) and glEnd().

    I.E.

    glBegin(GL_QUADS);
    glVertex**(...);
    glVertex**(...);
    // more vertices...
    glEnd();

    [This message has been edited by Nocturnal (edited 03-14-2001).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •