CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    164

    Smile 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
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Problem in displaying text

    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #3
    Join Date
    Jul 2005
    Location
    Louisville, KY
    Posts
    201

    Resolved Re: Problem in displaying text

    Quote Originally Posted by S_M_A View Post
    I've mentioned it in another post to him, please use the [ code ] tags, as it makes your code and posts easier to read.

  4. #4
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    164

    Re: Problem in displaying text

    how to use tags...pls tell me

  5. #5
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Problem in displaying text

    That what's described in the link I gave...

    The code tags only version of the description is: [code] Place your properly indented code here [/code]
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured