diff mde/SDL.d @ 21:a60cbb7359dd

Window settings now come from options, and may use OpenGL (enabled/disabled at compile time). committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 24 Mar 2008 17:53:28 +0000
parents 838577503598
children 249eb6620685
line wrap: on
line diff
--- a/mde/SDL.d	Sat Mar 22 16:22:59 2008 +0000
+++ b/mde/SDL.d	Mon Mar 24 17:53:28 2008 +0000
@@ -19,6 +19,7 @@
 
 import mde.scheduler.InitStage;
 import mde.input.joystick;
+import mde.options;
 
 import tango.util.log.Log : Log, Logger;
 import tango.stdc.stringz;
@@ -36,6 +37,8 @@
 }
 
 void initSdlAndGl() {   // init2 func
+    logger.trace ("init2: initSdlAndGl() started");
+    
     // Load SDL and GL dynamic libs
     try {
         DerelictSDL.load();
@@ -44,7 +47,7 @@
         logger.fatal ("Loading dynamic library failed:");
         logger.fatal (de.msg);
         
-        init2.setFailure ();
+        setInitFailure ();
         return;
     }
     logger.trace ("Derelict: loaded SDL and OpenGL");
@@ -55,7 +58,7 @@
         char* msg = SDL_GetError ();
         logger.fatal (msg ? fromStringz(msg) : "no reason available");
         
-        init2.setFailure ();
+        setInitFailure ();
         return;
     }
     
@@ -65,23 +68,56 @@
     // Must be called after SDL has been initialised, so cannot be a separate Init function.
     openJoysticks ();                   // after SDL init
     cleanup2.addFunc (&closeJoysticks);
+
+    logger.trace ("init2: initSdlAndGl() finished");
 }
 
 void setupWindow() {    // init4 func
+    logger.trace ("init4: setupWindow() started");
+    
+    // Window creation flags
+    /* NOTE: I'm getting an API mismatch error from the nvidia driver when using OpenGL,
+    * thus I've temporarily disabled it. */
+    version (MDE_OPENGL) uint flags = SDL_OPENGL;
+    else uint flags = 0;
+    if (Options.video.fullscreen) flags |= SDL_FULLSCREEN;
+    else {
+        if (Options.video.resizable) flags |= SDL_RESIZABLE;
+        if (Options.video.noFrame) flags |= SDL_NOFRAME;
+    }
+    if (Options.video.hardware) flags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
+    else flags |= SDL_SWSURFACE;
+    
+    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,  16);
+    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
+    }
+    
     // Open a window
-    // FIXME: provide a way to re-set video mode and change settings
-    if (SDL_SetVideoMode (800, 600, 0, 0) is null) {   // Can't open in windows!!
+    if (SDL_SetVideoMode (Options.video.width, Options.video.height, 32, flags) is null) {
         logger.fatal ("Unable to set video mode:");
         char* msg = SDL_GetError ();
         logger.fatal (msg ? fromStringz(msg) : "no reason available");
         
-        init4.setFailure ();
+        setInitFailure ();
         return;
     }
+    
+    // Window-manager settings
+    SDL_WM_SetCaption (toStringz ("mde"), null);
+    // SDL_WM_GrabInput (use later)
+    
+    logger.trace ("init4: setupWindow() finished");
 }
 
-void cleanupSDL () {
+void cleanupSDL () {    // cleanup2 func
+    logger.trace ("cleanup2: cleanupSDL() started");
     SDL_Quit();
+    logger.trace ("cleanup2: cleanupSDL() finished");
 }
 
     /+ Load of info-printing stuff (currently doesn't have a use)