Welcome! Log In Create A New Profile

Advanced

SDL - fprintf to console instead of stdout.txt or stderr.txt

Posted by semprance 
SDL - fprintf to console instead of stdout.txt or stderr.txt
February 05, 2010 04:07PM
Hi there,

I'll start by saying that I've really done myself out on this account as I actually solved this problem about a year ago and then lost the #@!%ing source code.... Anyhow, I digress:

How do you make the console appear, and then redirect stdout/stderr to it, when using SDL?

I had it working in a way that you could print text that was visible at the top and bottom of the screen (with the DISPLAY SDL_Surface filling the rest) about a year ago but I have no idea how I did it.

Anyone got any clues? I've looked at dhewgs code but he hasn't gone about it the same way that I did (it's a little over my head to be honest). I just want the console visible behind the SDL 'layer' as such.

Any help / solutions / clues would be appreciated. Thanks all,

semp
Re: SDL - fprintf to console instead of stdout.txt or stderr.txt
February 05, 2010 04:42PM
See the SVN r84 :- [code.google.com]
Re: SDL - fprintf to console instead of stdout.txt or stderr.txt
February 05, 2010 04:49PM
I'm a bit confused, how exactly do I implement this code around the SDL initialisation(s)?

Cheers for the help :-)
Re: SDL - fprintf to console instead of stdout.txt or stderr.txt
February 06, 2010 08:56AM
This line that inits the console (in SDL) is:

CON_Init(xfb[0],20,20,vmode->fbWidth,vmode->xfbHeight,vmode->fbWidth*VI_DISPLAY_PIX_SZ);

I don't believe you have to do anything other than printf your text, maybe there's more but start off trying that.



Edited 2 time(s). Last edit at 02/06/2010 08:57AM by scanff.
Re: SDL - fprintf to console instead of stdout.txt or stderr.txt
February 06, 2010 12:40PM
after you get the console, you can do printf() and not worry about fprintf()
Re: SDL - fprintf to console instead of stdout.txt or stderr.txt
February 06, 2010 01:23PM
Ok, thanks for the help :-) I'll add in the init code tonight and hopefully get it functioning again.

I know I don't need to use fprintf but alot of my code is already setup to print to either stderr or stdout. I assume that once the console is initialised it will all print there anyway.

Cheers again guys,

semp
Re: SDL - fprintf to console instead of stdout.txt or stderr.txt
February 07, 2010 01:30AM
It didn't work :-(

I notice the function described by scanff is almost identical to the one used in the standard wii template (template.c), but presumably the CON_ version is applicable to SDL. My code is setup like this for initialisation:

//---------- INIT SDL LIBRARIES
    if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 )
    {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError() );
		SDL_Delay( 5000 );
        exit(EXIT_FAILURE);
    }
	
	rmode = VIDEO_GetPreferredMode(NULL);
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	CON_Init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
	for(int i = 0; i < 100; i++)
		printf("Hello!\n");
		
	// button initialization
	WPAD_Init();
 
    // make sure SDL cleans up before exit
    atexit(SDL_Quit);
    SDL_ShowCursor(SDL_DISABLE);
 
    //---------- INIT DISPLAY
    screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF);
    if ( !screen )
    {
        fprintf(stderr, "Unable to set video: %s\n", SDL_GetError());
		SDL_Delay( 5000 );
        exit(EXIT_FAILURE);
    }
	
	//---------- INIT AUDIO
	if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 )
	{
		fprintf(stderr, "Unable to start mixer: %s\n", SDL_GetError());
		SDL_Delay( 5000 );
        exit(EXIT_FAILURE);
	}
Re: SDL - fprintf to console instead of stdout.txt or stderr.txt
February 07, 2010 03:45AM
You don't need to call CON_Init as SDL has already done that for you. Did you just try printf? Remember on most TV's the first printf will be above the visible area. try for(int i=0;i<20;i++) printf("line %d\n",i);
Sorry, only registered users may post in this forum.

Click here to login