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
    Senior Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    356
    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! ~ ~

Similar Threads

  1. Draw GUI and text
    By Mattous in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-14-2017, 12:06 AM
  2. Text rendering class does not draw text
    By th0masr0ss in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-23-2015, 09:10 PM
  3. Draw Text
    By Rong Yao in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-02-2007, 12:03 PM
  4. Draw axes in with Text
    By fcoutel in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-12-2002, 07:51 AM
  5. Draw a text in a window
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-26-2002, 06:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean