Archived

This topic is now archived and is closed to further replies.

radjan_spirit

console output prob / debugging poll !

Recommended Posts

making a game (not in glut) and i want a console window that I can easily print information to help me debug as I go. I''ve gotten an extra window (of the regular old dos-like variety) to pop up but I cannot for the life of me find a way to print to it. I''m using: WINBASEAPI BOOL WINAPI AllocConsole(); from wincon.h to create the console, but cout and printf don''t work. It compiles but nothing is output. cprintf (as suggested by someone earlier) seems only to exist on macintosh''s (i''m windows, please correct me if i''m wrong though). I''ve also thought that maybe I had to set this new window as default before printf''ing and played around with combinations of functions I thought might work from wincon.h like: SetConsoleCP(GetConsoleCP()); and SetConsoleOutputCP(GetConsoleCP()); but these don''t work either (and i really don''t know what they do) -any advice, asides from using glut? ------------------------------------------- POLL: WHAT''S YOUR TECHNIQUE TO DEBUGGING YOUR PROGRAM AS YOU CODE? (obviously, i''m used to spitting out lots and lots of print statements concerning variable states and specific occurances) ------------------------------------------- (quick apology: i asked about consoles a few days ago but thought problems were solved when i just got the console to appear, oyve)

Share this post


Link to post
Share on other sites
Get the demogl v1.3 sourcecode from http://www.demogl.com. In that sourcecode you''ll find the console class I wrote for DemoGL. The sourcecode also contains a lowlevel debugger you can easily add to your code and then you just have to call simple functions to log messages, return/enter statements etc in a file, including call tree.

--

Get productive, Get DemoGL: http://www.demogl.com

Share this post


Link to post
Share on other sites
Hi,

Using AllocConsole, you need to use _cprintf(), note the underscore in front.

Here's my logging macros -


#ifndef _CONSOLELOG_H_
#define _CONSOLELOG_H_

#include

#ifdef _DEBUG
#define LogString(P_message) {_cprintf("%s", P_message);}
#define LogInt(P_message) {_cprintf("%i", P_message);}
#define LogFloat(P_message) {_cprintf("%f", P_message);}
#define LogName(P_message) {_cprintf("[%-20s] - ", P_message);}
#define StartConsole() {AllocConsole(); LogString("Starting log\n");}
#else
#define LogString(P_message) {}
#define LogInt(P_message) {}
#define LogFloat(P_message) {}
#define LogName(P_message) {}
#define StartConsole() {}
#endif

#endif


It's nice and small (I didn't bother with a StopConsole() macro) and works fine for me. A possible upgrade would be to not only _cprintf() to the the console, but write it to a log file as well.

The source function here in the forum didn't work for this code, it was all stretched out. The #include should be conio.h

Dan

Edited by - danbrown on February 2, 2001 2:01:01 PM

Share this post


Link to post
Share on other sites