OT: Started a blog about D, OpenGL and SDL

Anders F Björklund afb at algonet.se
Fri Jan 26 11:58:47 PST 2007


Mike Parker wrote:

>> For Win32 you can fake this SDL_main by reproducing it in D, but
>> for the regular MacOS driver it is written in Objective-C (not C)...
> 
> For Win32, you can just skip it completely. I have a C framework I put 
> together that uses SDL and doesn't even link in SDL_main. That's why 
> DerelictSDL has no issues on Windows. All SDL_main does there is 
> redirect stdout & stderr, call SDL_Init with the NO_PARACHUTE flag, and 
> call ddhelp.exe for some reason, all of which can be done without.

I think it also accepts some parameters to change depth/driver/etc ?
Just figured if I'm doing a special main anyway, might use theirs...

> I looked over the Mac version of SDL_main a while ago, but I didn't 
> really grok it. What exactly does it do that is required to run an SDL 
> app? Why can we not do without it on Mac? That's what I'm curious about.

Well, on Mac OS X there are two major frameworks: Carbon and Cocoa.
(where Carbon is the old MacOS API, and Cocoa is the old NeXT API)

If you use Cocoa (which is SDL default), you need to initialize the
Objective-C runtime which is what SDLmain.m does. For Carbon I don't
think it does any special init you can't live without, similar to
the Win32 version of SDLmain... But there is a SDLmain there too.
(and if you use the X11 version of SDL it doesn't need any special
setup, similar to how it works on Linux. But that's not too common)

And while you could write a special D main replacement, to initialize
both Phobos/GC and Objective-C in the right order, I think that's
trickier than just calling the SDLmain after initializing D ? With
the added bonus of the stdout/stderr redirection and params, etc...
But the major reason why you can't live without SDLmain on Mac OS X
is that Obj-C/Cocoa runtime initialization done in the SDLmain.m.

Beyond setting up the runtime, it also loads and sets the menubar
from a NIB file. I think there's an alternate fancier SDLMain too.
You also need to link with /usr/lib/libobjc.dylib (or Cocoa.framework),
all this is normally done by using `sdl-config --libs` in the Makefile.

--anders



More information about the Digitalmars-d-announce mailing list