SDL: printf/cout ?
I just started playing with SDL, as I think GLUT is quite limiting.
I however did like the console window that GLUT spawned, where I could print out debugging information.
I'm perfecetly capable of placing breakpoints and such, but sometimes printing out to a console is a better and faster way.
Is it possible to spawn such a window in SDL? Where do printf() lines go anyway? /dev/null? :o
Ps.. I know that singleton file logging is pretty effective for debugging.. But I prefer console method for quick and dirty debugging... I use file logging as well for the more obvious stuff and error handling.
How SDL handles stdout and stderr depends on the platform. For example, on Windows, if the application is compiled for the Windows subsystem, SDL redirects stdout and stderr to text files.
Don't use a singleton log file.
This code works for me:
However, this way you lose logging to files, which is handy. If you are feeling adventurous, you can write a custom std::streambuf that redirects printing to std::cout (or any stream) to an arbitrary location. With a bit of work, you can write a streambuf that writes to a console and to a file. However, you would have to switch from printf to C++ streams. Which is probably a good idea.
This code works for me:
#ifdef _WIN32 const char * confile = "CONOUT$"; FreeConsole(); if( !AllocConsole() ) { // handle error } freopen(confile, "w", stdout); freopen(confile, "w", stderr);#endif
However, this way you lose logging to files, which is handy. If you are feeling adventurous, you can write a custom std::streambuf that redirects printing to std::cout (or any stream) to an arbitrary location. With a bit of work, you can write a streambuf that writes to a console and to a file. However, you would have to switch from printf to C++ streams. Which is probably a good idea.
Ok.. In that case, I'll probably just log everything then..
However.. does anyone know of a good lightweight "log watching" program? that would function similarly to a console window.. I could just let it sit on my other monitor and instantly print out to a window anything that was written to the log?
EDIT:
The code above worked. Thanks a ton, that's awesome!
However.. Still, if anyone does happen to know of a log watching program that I described above, feel free to post :)
However.. does anyone know of a good lightweight "log watching" program? that would function similarly to a console window.. I could just let it sit on my other monitor and instantly print out to a window anything that was written to the log?
EDIT:
The code above worked. Thanks a ton, that's awesome!
However.. Still, if anyone does happen to know of a log watching program that I described above, feel free to post :)
How about this?
http://tailforwin32.sourceforge.net/
EDIT: Or just "tail -f". I assumed you were on Windows for some reason :)
http://tailforwin32.sourceforge.net/
EDIT: Or just "tail -f". I assumed you were on Windows for some reason :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement