Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 27

Thread: How to show float numbers?

  1. #11
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    San Diego, CA, USA
    Posts
    769

    Re: How to show float numbers?

    You mean a type-safe stream is a step backwards from a variable argument, buffer overflowing, type-ignorant, mark-up language?

    -- Zeno

    [This message has been edited by Zeno (edited 05-03-2002).]

  2. #12
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: How to show float numbers?

    no he means that with all those new features added, simple formating of the output got lost (it _IS_ still possible, but not at all that nice as before..)

    that is true..
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

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

    Re: How to show float numbers?

    Exactly. printf and sprintf are so immensly easy and efficient to use.
    I tried to learn how to use the C++ formatters once and just laughed. It would take 1000 characters of code to do what takes 20 with sprintf.
    I had a job where they tried to make me use that style of output and I quit, got a new job (not just because of that, but because of general C++ overzealous religousness).

  4. #14
    Junior Member Regular Contributor
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    200

    Re: How to show float numbers?

    JESUS!!!!

    Sorry guys but you are really stressing a trivial issue.

    Yes using streams is SAFE but you are buying it with a lot of overhead.

    If you are doing a %1.5f sprintf on a char[256] buffer there is NO way you will EVER over run the buffer and its fast and easy too....

    BTW: Knackered is right the width.precision only specifies the MININUM length of the result.

    Regards,

    LG

    EDIT: Fixed some typo's

    [This message has been edited by lgrosshennig (edited 05-03-2002).]

  5. #15
    Junior Member Newbie
    Join Date
    Feb 2002
    Posts
    18

    Re: How to show float numbers?

    my teachers,

    Sorry!

    I want to draw some objects with float numbers at (x,y,z). If using glListBase(1000); glRasterPos3f(x,y,z);glCallLists(Twidth,GL_UNSIGNE D_BYTE,Text);,I have to use own code to convert it to a string with finding a decimal position (_fcvt(...)).If using sprintf/printf(), I can't see the float numbers near objects drawed, namely I can't show the float numbers at given (x,y,z).

    How to directly show float numbers at (x,y,z) in OpenGL with drawing objects?

    thanks

  6. #16
    Junior Member Newbie
    Join Date
    Dec 2000
    Location
    Seoul, Korea
    Posts
    8

    Re: How to show float numbers?

    You're misuberstanding the advice, ding

    Used sprintf to format the output string (not printf!), then draw the formatted string using your existing calls.

    Example:

    char buffer[512];
    sprintf (buffer, "%3.5f", output_string);

    YourNormalDrawTextFunction(buffer);

    You don't need to do anything special with OpenGL to draw floats. It's all about formatting the output.

  7. #17
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Hannover, Germany
    Posts
    1,258

    Re: How to show float numbers?

    If you're totally into safety then you might wanna use _ecvt or however it is called, it returns a pointer to a static char array filled with the floating point number.
    - Michael Steinberg

  8. #18
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: How to show float numbers?

    >>(By the way, printf and sprintf are so incredible to use compared to C++ formatting statements. You want to talk about one major step backwards in the name of progress, this is it)<<

    yeah i remember from when i started c++ in about 1996 (c in 1986/7) what struck me with c++.
    the c++ way with formatting strings,
    i thought it was a joke?
    no i mean seriously!
    i still think it nowadays, its a joke right?

    btw i love c++

  9. #19
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Posts
    662

    Re: How to show float numbers?

    I am not sure that :

    ostringstream os;
    float t;

    os << fixed() << setw(3) << setPrecision(2) << t;

    is weirder or uglier than

    char buffer[256];
    sprintf( buffer, "%3.2f", &t );

    I will admit it is longer to type though.



    [This message has been edited by Gorg (edited 05-05-2002).]

  10. #20
    Junior Member Regular Contributor
    Join Date
    Jul 2001
    Location
    Sherbrooke
    Posts
    146

    Re: How to show float numbers?

    humm....I have something to say to this non-opengl debate hehehe

    When I started learning c++ and used nothing of the printf family i thought that it was great.

    But when I discovered that I could use sprintf and printf and all that stuff, I said to myself "f*ck the c++ text formatting method it's ugly" ! hahaha

    maybe(probably) it's more safe though....
    well...I love risks...

    -------------------------------------------
    Evil-Dog
    *Let's have a funny day*
    Let's have a funny day

Posting Permissions

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