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 6 of 6

Thread: Problem in displaying text

  1. #1
    Junior Member Regular Contributor
    Join Date
    Aug 2009
    Posts
    111

    Problem in displaying text

    Dear Friends
    I am finding some difficulty in displaying the text in properposition mean at proper coordinate position. I am using bitmap fonts.. Using nehe tutorials I am able to draw a text. but now I want customize the text. Basically I want to display X, Y, Z at x=10, y=10 and z=10 location. I have an axes xyz threee lines I have already drawn.

    For that I am doing like this.

    glRasterPos3f(10.0f, 0.0f, 0.0f);
    glPrint("X");
    glRasterPos3f(0.0f, 10.0f, 0.0f);
    glPrint("Y");
    glRasterPos3f(0.0f, 0.0f, 10.0f);
    glPrint("Z");

    But I can see XYandZ all are coming at (10,0,0) position....Y and Z shoulb be at 0,10,0 and 0,0,10 respectively. Please help me someone whats going wrong in this.

    My glPrint is like this
    ///////////////////////////////////////////////////////////////
    GLvoid CRevolutionProjView::glPrint(const char *fmt, ...) // Custom GL "Print" Routine
    {
    CDC* pDC = GetDC();
    wglMakeCurrent(pDC->m_hDC, m_hrc);
    char text[256]; // Holds Our String
    va_list ap; // Pointer To List Of Arguments

    if (fmt == NULL) // If There's No Text
    return; // Do Nothing

    va_start(ap, fmt); // Parses The String For Variables
    vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
    va_end(ap); // Results Are Stored In Text

    glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
    glListBase(base - 32); // Sets The Base Character to 32
    glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
    glPopAttrib(); // Pops The Display List Bits
    wglMakeCurrent(NULL,NULL);
    }
    //////////////////////////////////////////////////////////////

    and I am creating font like this....
    //////////////////////////////////////////////////////////////
    GLvoid CRevolutionProjView::BuildFont(GLvoid) // Build Our Bitmap Font
    {
    CDC* pDC = GetDC();
    wglMakeCurrent(pDC->m_hDC, m_hrc);

    HFONT font; // Windows Font ID
    HFONT oldfont; // Used For Good House Keeping

    base = glGenLists(96); // Storage For 96 Characters

    font = CreateFont( -24, // Height Of Font
    0, // Width Of Font
    0, // Angle Of Escapement
    0, // Orientation Angle
    FW_BOLD, // Font Weight
    FALSE, // Italic
    FALSE, // Underline
    FALSE, // Strikeout
    ANSI_CHARSET, // Character Set Identifier
    OUT_TT_PRECIS, // Output Precision
    CLIP_DEFAULT_PRECIS, // Clipping Precision
    ANTIALIASED_QUALITY, // Output Quality
    FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
    L"Courier New"); // Font Name

    oldfont = (HFONT)SelectObject(pDC->m_hDC, font); // Selects The Font We Want
    wglUseFontBitmaps(pDC->m_hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32
    SelectObject(pDC->m_hDC, oldfont); // Selects The Font We Want
    DeleteObject(font); // Delete The Font
    wglMakeCurrent(NULL,NULL);
    }
    ////////////////////////////////////////////////////////

    I am calling BuildFont in PrepareScene like this

    ///////////////////////////////////////////////////////////
    void CRevolutionProjView::PrepareScene(CDC *pDC)
    {
    wglMakeCurrent(pDC->m_hDC, m_hrc);
    //---------------------------------
    glClearColor (0.0, 0.0, 0.0, 1.0);
    drawAxes();
    BuildFont();
    wglMakeCurrent(NULL, NULL);
    }
    ///////////////////////////////////////////////////////////

    Please tell me why they'are not coming at their proper positions. How can I achieve this. Thanks a lot in advance for the reply. Thanks Sujan

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Problem in displaying text

    You have missed from your post perhaps the most important thing - the conents of each displaylist.

    Is glRasterPos realy the right command?
    Here's part of the definition of the command:

    OpenGL maintains a 3-D position in window coordinates. This position, called the raster position, is maintained with subpixel accuracy. It is used to position pixel and bitmap write operations. See glBitmap, glDrawPixels, and glCopyPixels.

    So instead try glTranslatef to position your text.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Aug 2009
    Posts
    111

    Re: Problem in displaying text

    glTranslatef is not working either. I have tried glTranslatef nothing happening with that. Please whatelse I can do for this. Thanks Sujan

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Problem in displaying text

    Like I said really. What's in the display list?
    Did you use glVertex2f to draw a quad per text character?
    If so then glTranslatef will work as that's how 99% of gl programs are written.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Aug 2009
    Posts
    111

    Re: Problem in displaying text

    No I am not using glVertex2f

    glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text


    this is how I am displaying the text.
    Thanks for your help. My problem is resolved now. I am calling glRasterPosf() inside glPrint() just before glCallLists(). So now I need to write three separate api glPrintX() with x position, glPrintY() with y position and glPrintZ() with z position. Then I call separately them in the paint() function. Its now displaying 3 legends at their respective positions. Thanks a lot for your help.
    Regards
    Sujan

  6. #6
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Problem in displaying text

    Quote Originally Posted by BionicBytes
    Like I said really. What's in the display list?
    Did you use glVertex2f to draw a quad per text character?
    If so then glTranslatef will work as that's how 99% of gl programs are written.
    wglUseFontBitmaps generates the display lists.
    It probably call glBitmap or glDrawPixels.
    So the function to use is glColor (to setup the color) followed by glRasterPos and then glCallList.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

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