Mercurial > projects > mde
diff mde/SDL.d @ 25:2c28ee04a4ed
Some minor and some futile efforts.
Played around with init functions, had problems, gave up and put them back.
Removed idea for multiple init stages; it's not good for performance or simplicity.
Adjusted exception messages.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 03 Apr 2008 17:26:52 +0100 |
parents | 32eff0e01c05 |
children | 611f7b9063c6 |
line wrap: on
line diff
--- a/mde/SDL.d Thu Mar 27 16:15:21 2008 +0000 +++ b/mde/SDL.d Thu Apr 03 17:26:52 2008 +0100 @@ -17,7 +17,7 @@ */ module mde.SDL; -import mde.scheduler.InitStage; +import mde.scheduler.InitFunctions; import mde.input.joystick; import mde.options; import mde.gl; @@ -34,15 +34,12 @@ static this() { logger = Log.getLogger ("mde.SDL"); - init2.addFunc (&initSdlAndGl); - init4.addFunc (&setupWindow); + init.addFunc (&initSdlAndGl); } private uint flags = 0; -void initSdlAndGl() { // init2 func - debug logger.trace ("init2: initSdlAndGl() started"); - +void initSdlAndGl() { // init func // Load SDL and GL dynamic libs try { DerelictSDL.load(); @@ -66,25 +63,18 @@ return; } - cleanup2.addFunc (&cleanupSDL); debug logger.trace ("SDL initialised"); // Must be called after SDL has been initialised, so cannot be a separate Init function. openJoysticks (); // after SDL init - cleanup2.addFunc (&closeJoysticks); + cleanup.addFunc (&cleanupSDL); - debug logger.trace ("init2: initSdlAndGl() finished"); + setupWindow(); } -version = MDE_OPENGL; - -void setupWindow() { // init4 func - debug logger.trace ("init4: setupWindow() started"); - +void setupWindow() { // indirect init func (depends on initSdlAndGl) // Window creation flags and size - /* NOTE: I'm getting an API mismatch error from the nvidia driver when using OpenGL, - * thus I've temporarily disabled it. */ - version (MDE_OPENGL) flags = SDL_OPENGL; + flags = SDL_OPENGL; if (vidOpts.hardware) flags |= SDL_HWSURFACE | SDL_DOUBLEBUF; else flags |= SDL_SWSURFACE; int w, h; @@ -100,14 +90,12 @@ h = vidOpts.windowH; } - version (MDE_OPENGL) { // OpenGL attributes SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); - } // Open a window if (SDL_SetVideoMode (w, h, 32, flags) is null) { @@ -119,6 +107,19 @@ return; } + // Now (must be done after GL context is created) try to load later version: + /+ No later GL features are currently used. + try { + DerelictGL.loadVersions(GLVersion.Version21); + } catch (DerelictException de) { + logger.fatal ("Loading OpenGL version > 1.1 failed:"); + logger.fatal (de.msg); + + setInitFailure (); + return; + } + +/ + // OpenGL stuff: glSetup(); @@ -128,8 +129,6 @@ // Window-manager settings SDL_WM_SetCaption (toStringz ("mde"), null); // SDL_WM_GrabInput (use later) - - debug logger.trace ("init4: setupWindow() finished"); } void resizeWindow (int w, int h) { @@ -153,10 +152,9 @@ setProjection (w, h); } -void cleanupSDL () { // cleanup2 func - debug logger.trace ("cleanup2: cleanupSDL() started"); +void cleanupSDL () { // cleanup func + closeJoysticks(); SDL_Quit(); - debug logger.trace ("cleanup2: cleanupSDL() finished"); } /+ Load of info-printing stuff (currently doesn't have a use)