2005-01-24

Preserving stdin when using SDL

SDL has a "feature" where by it redirects stdin/out/err on certain platforms, including OS X. This presented problems since tcprose (an opengl network visualiser) depended on stdin for interprocess communication. After much mucking about, I arrived eventually at a 3 line solution to the problem:

First we duplicate the stdin file descriptor so when SDL calls close() on 0 the stream remains open.
int dup_fd = dup(0);
Then we initalise SDL, and let it redirect stdin as it does.
SDL_Init(SDL_INIT_VIDEO);
Here is where we do our little trick: close 0, then duplicating the original stdin stream back onto 0, so scanf etc will continue to work.
close(0);
dup2(dup_fd,0);
And viola! We have stdin back again, no longer redirected. This solution won't work for window users though. See discussion at gmane.org.
Cheers,
Steve

2005-01-06

FSAA using SDL

Taking a break from working on emmap, I got back into the wonderful of C/OpenGL/SDL programming again.

SDL is a wonderful library that does... well a lot, but in a portable fashion that works on many platforms. One of these include Full Screen Anti Aliasing (FSAA), which makes things Look Good. I won't go into detail on how its done via SDL, there are resources a plenty. What I will impart is however a small piece of knowledge I gained after debugging a visualisation I am writing: FSAA through SDL will only work reliably cross platform only if the screen color depth is 24 or less.

Its a small thing, but it took a while to work out. Hope this helps some one :-)

Cheers,
Steve