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: Draw 2D text

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2011
    Posts
    5

    Draw 2D text

    Hi,


    I'm trying to paint some 2D label text in OpenGL.
    I've already achieved it, but I'm having problems because I don't want the text to be always visible, I mean I would like that the DEPTH_TEST would be applied to the text rendered, but I've been unable to accomplish it.
    I'm using glCallLists in order to render the text, here is a sample of more or less what I'm doing:


    <CODE>

    SelectObject(hDCForm, font);
    wglUseFontBitmaps(hDCForm, 0, 255, IDBASELISTAFUENTETEXTO);


    GLdouble modelView[16], projection[16];
    GLint viewport[4];
    glGetDoublev(GL_MODELVIEW_MATRIX, modelView);
    glGetDoublev(GL_PROJECTION_MATRIX, projection);
    glGetIntegerv(GL_VIEWPORT, viewport);


    //2D mode
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0.0, (GLfloat)(viewport[2] - viewport[0]), 0.0, (GLfloat)(viewport[3] - viewport[1]), -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    glDisable(GL_DEPTH_TEST);

    //project
    double tx, ty, tz;
    gluProject(position.x, position.y, position.z, modelView, projection, viewport, &tx, &ty, &tz);

    //draw text
    glRasterPos3d(tx, ty, tz);
    glPushAttrib(GL_LIST_BIT);
    glListBase(IDBASELISTAFUENTETEXTO);
    glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);
    glPopAttrib();

    //restore 3D
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glEnable(GL_DEPTH_TEST);


    </CODE>


    Thanks in advance

  2. #2
    Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    355
    if you want the GL_DEPTH_TEST to be enabled during the text rendering why you disable it?
    Witch part of the scene should occlude your text?
    From the code you posted the text is rendered with an ortho projection, usually 3d scene are rendered with perspective, how can you compare the depth of two different projections?
    Can you post a picture of what you want?
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

Posting Permissions

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