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

Thread: writing numbers on the screen

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2000
    Location
    gainesville, fla, usa
    Posts
    17

    writing numbers on the screen

    Hi,
    I want to display a set of 3D (float) coordinates on the screen. I know you can use glRasterPos and glutBitmapCharacter to display a character but I am lost on writing float values. Any help is appreciated.

  2. #2
    Member Regular Contributor nickels's Avatar
    Join Date
    Feb 2000
    Location
    Colorado
    Posts
    298

    Re: writing numbers on the screen

    I don't know, but if you can display any character, can you do something like this:

    float x;
    char *ptr;
    char buf[1024];
    x = 3.14 (etc...)
    sprintf(buf, "%f", x);
    for(ptr = &buf[0]; ptr; ptr++)
    {
    display_gl_char(*ptr);
    }

  3. #3
    Intern Contributor
    Join Date
    Feb 2000
    Location
    San Diego Ca, USA
    Posts
    51

    Re: writing numbers on the screen

    use sprintf()
    this is what I got to work...

    char str[] //storage for string

    sprintf(str, "myfloat: %f", outputVar);

    glRasterPos2f(-50, -50);
    len = (int)strlen(str);
    for (i=0; i<len; i++)
    {
    glutBitmapCharacter(hudFont, str[i]);
    }




    [This message has been edited by mike j (edited 02-24-2000).]

  4. #4
    Member Regular Contributor nickels's Avatar
    Join Date
    Feb 2000
    Location
    Colorado
    Posts
    298

    Re: writing numbers on the screen

    Wait a minute. That line has to be:

    for(ptr = &buf[0]; *ptr; ptr++)

    (Test for null at end of string)

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2000
    Location
    gainesville, fla, usa
    Posts
    17

    Re: writing numbers on the screen

    Thanks alot mikej and nickels.


    glguru

Posting Permissions

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