Jump to content
  • Advertisement
Sign in to follow this  
bjarnia

SDL: printf/cout ?

This topic is 3919 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Don't use a singleton log file.

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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
How about this?

http://tailforwin32.sourceforge.net/

EDIT: Or just "tail -f". I assumed you were on Windows for some reason :)

Share this post


Link to post
Share on other sites
Thanks. That was exactly what I was looking for.

Ps yes I am on windows... I've used tail before on linux but it didn't ring a bell this time, or else it would've been easier to google :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!