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

Thread: Can you use cout and the iostream header file with OpenGL?

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    Chicago, IL
    Posts
    5

    Can you use cout and the iostream header file with OpenGL?

    I mainly use only C++ keywords when coding with OpenGL because that's what they taught us in college. Anyway, I've noticed that most OpenGL source code has printf to print out program output. I was wondering if I could use cout instead since I am more accustomed to using it? I'm asking this because I don't think I've ever seen it used in OpenGL source code from the web. Does it not work under OpenGL?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    668

    Re: Can you use cout and the iostream header file with OpenGL?

    cout is c++, as you know, so not too sure what you mean when you say 'work under OpenGL'.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    Chicago, IL
    Posts
    5

    Re: Can you use cout and the iostream header file with OpenGL?

    Sorry for being unspecific in my previous question. What I mean is that most people use printf to print out let's say the FPS of an OpenGL program. I tried doing something similar like this with cout in a program but couldn't find the ouput line. So it made me wonder if cout could be used to shouw output since most people use printf and not cout in the OpenGL programs I've seen. Maybe I'll just try it again. But, thanks for the reply.

  4. #4
    Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Princeton, NJ
    Posts
    391

    Re: Can you use cout and the iostream header file with OpenGL?

    Which you use depends on what you mean when you want to display something. To display it in the window through opengl people use some custom defined glPrint(...) routine that has the same syntax as printf, you could wrap it into a cout style stream if you wanted
    if you mean writing to the console you can use either printf or cout, though I find that cout has delayed evaluation, printf actually writes at the time of the function call.
    Thats just my experiance

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: Can you use cout and the iostream header file with OpenGL?

    though I find that cout has delayed evaluation, printf actually writes at the time of the function call
    cout is normally a buffered output, and will flush the buffer on a new line (endl or '\n'), or when you explicitly call the flush metod on the stream. Maybe that's what you experienced.

  6. #6
    Junior Member Regular Contributor
    Join Date
    Nov 2001
    Location
    Malaysia
    Posts
    112

    Re: Can you use cout and the iostream header file with OpenGL?

    Originally posted by vgohan:
    I mainly use only C++ keywords when coding with OpenGL because that's what they taught us in college. Anyway, I've noticed that most OpenGL source code has printf to print out program output. I was wondering if I could use cout instead since I am more accustomed to using it? I'm asking this because I don't think I've ever seen it used in OpenGL source code from the web. Does it not work under OpenGL?
    iostream, stdio.h... have nothing to do with OpenGL. Use it whenever you like, although mixing iostream function and stdio.h is not a very good idea.

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,757

    Re: Can you use cout and the iostream header file with OpenGL?

    If you want cout to write text to the GL viewport, yes, you can easily do that, if you write your own ostream derived class to handle it and redirect cout to use your class. You can do the same with cerr.

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

    Re: Can you use cout and the iostream header file with OpenGL?

    I think the answer to this question is simply, "Yes, you can use cout with opengl." Just compile with a C++ compiler.

    [This message has been edited by nickels (edited 06-18-2002).]

Posting Permissions

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