PDA

View Full Version : Can you use cout and the iostream header file with OpenGL?



vgohan
06-16-2002, 10:11 AM
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?

Gavin
06-16-2002, 11:19 AM
cout is c++, as you know, so not too sure what you mean when you say 'work under OpenGL'.

vgohan
06-16-2002, 11:46 AM
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.

chowe6685
06-16-2002, 04:06 PM
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

Bob
06-17-2002, 12:38 AM
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.

Questions Burner
06-18-2002, 01:21 AM
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.

DFrey
06-18-2002, 04:34 AM
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.

nickels
06-18-2002, 10:59 AM
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).]