4

I'm using the SDL library in my project and I'm working on a Windows platform.

When I'd decided to move my project to SDL 2, I encountered a problem:

There was an option in SDL 1.2 to print output from stdout/stderr into the console window, rather than to files by defining a NO_STDIO_REDIRECT macro. However, I haven't found that macro in SDL 2.

Is there a way to print SDL 2 output to the console instead of the standard files?

JNYRanger
  • 6,829
  • 12
  • 53
  • 81
cybermind
  • 73
  • 1
  • 5
  • Could you add some code examples, what you've tried, what you want should happen. – Johanna Larsson Nov 19 '13 at 15:21
  • Though there is an answer to my question here http://wiki.libsdl.org/FAQWindows (last question), it refers to an old SDL 1.2 version, while i'm trying to use new SDL 2, and that approach described in FAQ couldn't be used. – cybermind Nov 19 '13 at 15:54
  • Did you build SDLmain.lib yourself or are you using a prebuilt one? With MinGW with prebuilt ones it doesn't create stdout and stderr in my test program. – Xonar Nov 19 '13 at 16:56

1 Answers1

8

I suspect that NO_STDIO_REDIRECT is no longer part of SDL2.

You should use instead SDL_Log and all the other related functions to log messages from within your application.
Then you can use SDL_LogSetOutputFunction to:

replace the default log output function with one of your own

Note that you can gracefully handle any given category or priority, being the prototype of the handler the one below:

void SDL_LogOutputFunction(void*           userdata,
                           int             category,
                           SDL_LogPriority priority,
                           const char*     message)

Please, refer to the linked documentation for further details.

skypjack
  • 49,335
  • 19
  • 95
  • 187
  • Wow, you are really late with answer, but thanks anyway – cybermind Jul 01 '16 at 13:07
  • 6
    @cybermind You are right, sometimes I try to answer old unanswered questions. Even if it's a bit too late for you, newcomers will benefit from these answers. ;-) – skypjack Jul 01 '16 at 13:10