PDA

View Full Version : Debugging output



franz1999
04-18-2003, 01:03 PM
Let me start saying that I am totally new in Windows programming and C++. I have been programming in Java mostly and C++ (but just console applications).
I found very useful to use some debugging output on the console cout to get some quick information about the behavior of the program. I like using the debugger and I know how to do it, but sometimes would be much faster to have some output printed by the program in real time.
I hope I was able to explaine what I mean.
Is there any way to have such output while programming for Windows (same structure of those tutorials in gametutorials.com)?
Is the debugger my only way to go?
I am using VC++ 6

Thanks in advance for any input!

F.

shinpaughp
04-18-2003, 01:24 PM
If it is a console app, you can print to the console window using printf and cout would probably work too. For Win32/MFC, I don't know, you could probably create a console window (I think you do it with AllocConsole - not sure) and have std output go to that window. Look up "AllocConsole" or "console creation" on http://msdn.microsoft.com .

franz1999
04-18-2003, 10:06 PM
Originally posted by shinpaughp:
If it is a console app, you can print to the console window using printf and cout would probably work too. For Win32/MFC, I don't know, you could probably create a console window (I think you do it with AllocConsole - not sure) and have std output go to that window. Look up "AllocConsole" or "console creation" on http://msdn.microsoft.com .


I am gonna take a look at this AllocConsole, but since my knowledge of both C++ and MFC are very limited I am not sure I'll be able to manage it.
I wonder... no one ever made a NON console application and found himself in the necessity of print some data contained in some data structure? I neeeeed "printf" http://www.opengl.org/discussion_boards/ubb/frown.gif

shinpaughp
04-18-2003, 11:53 PM
Sorry, I thought it'd be easier than that. You might be able to find some code of how to set up the console on msdn.microsoft.com (http://msdn.microsoft.com) .

You could easily print strings in OpenGL context window. But, you have to call wglUseFontBitmaps or wglUseFontOutlines. Then you need to make a little function to print the characters, and you need to provide the position using glRasterPos which will only display it if the position you provide is within the screen.

Good place to start is http://nehe.gamedev.net/lesson.asp?index=03 or http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg4.htm

[This message has been edited by shinpaughp (edited 04-19-2003).]

franz1999
04-19-2003, 02:21 PM
Originally posted by shinpaughp:
For Win32/MFC, I don't know, you could probably create a console window (I think you do it with AllocConsole - not sure)

You were absolutely right... I found out the correct syntax. I am posting it here for future reference. Just put this code somewhere in an initialization method:

#ifdef _DEBUG
AllocConsole();
freopen("conin$", "r", stdin);
freopen("conout$", "w", stdout);
freopen("conout$", "w", stderr);
#endif

and then use printf(...) in the same way you would do with the usual console.
Thanks for your help!

Francesco