Mercurial > projects > mde
comparison mde/SDL.d @ 22:249eb6620685
Changes to Options, particularly regarding window sizes.
Window sizes for fullscreen and windowed modes are now independant.
Window resizes by the WM are now persistant.
Options class contents are now generated by templates.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 25 Mar 2008 12:24:04 +0000 |
parents | a60cbb7359dd |
children | 47478557428d |
comparison
equal
deleted
inserted
replaced
21:a60cbb7359dd | 22:249eb6620685 |
---|---|
33 logger = Log.getLogger ("mde.SDL"); | 33 logger = Log.getLogger ("mde.SDL"); |
34 | 34 |
35 init2.addFunc (&initSdlAndGl); | 35 init2.addFunc (&initSdlAndGl); |
36 init4.addFunc (&setupWindow); | 36 init4.addFunc (&setupWindow); |
37 } | 37 } |
38 | |
39 private uint flags = 0; | |
38 | 40 |
39 void initSdlAndGl() { // init2 func | 41 void initSdlAndGl() { // init2 func |
40 logger.trace ("init2: initSdlAndGl() started"); | 42 logger.trace ("init2: initSdlAndGl() started"); |
41 | 43 |
42 // Load SDL and GL dynamic libs | 44 // Load SDL and GL dynamic libs |
76 logger.trace ("init4: setupWindow() started"); | 78 logger.trace ("init4: setupWindow() started"); |
77 | 79 |
78 // Window creation flags | 80 // Window creation flags |
79 /* NOTE: I'm getting an API mismatch error from the nvidia driver when using OpenGL, | 81 /* NOTE: I'm getting an API mismatch error from the nvidia driver when using OpenGL, |
80 * thus I've temporarily disabled it. */ | 82 * thus I've temporarily disabled it. */ |
81 version (MDE_OPENGL) uint flags = SDL_OPENGL; | 83 version (MDE_OPENGL) flags = SDL_OPENGL; |
82 else uint flags = 0; | |
83 if (Options.video.fullscreen) flags |= SDL_FULLSCREEN; | 84 if (Options.video.fullscreen) flags |= SDL_FULLSCREEN; |
84 else { | 85 else { |
85 if (Options.video.resizable) flags |= SDL_RESIZABLE; | 86 if (Options.video.resizable) flags |= SDL_RESIZABLE; |
86 if (Options.video.noFrame) flags |= SDL_NOFRAME; | 87 if (Options.video.noFrame) flags |= SDL_NOFRAME; |
87 } | 88 } |
96 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); | 97 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); |
97 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); | 98 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); |
98 } | 99 } |
99 | 100 |
100 // Open a window | 101 // Open a window |
101 if (SDL_SetVideoMode (Options.video.width, Options.video.height, 32, flags) is null) { | 102 SDL_Surface* surface; |
103 if (Options.video.fullscreen) { | |
104 surface = SDL_SetVideoMode (Options.video.screenW, Options.video.screenH, 32, flags); | |
105 } else { | |
106 surface = SDL_SetVideoMode (Options.video.windowW, Options.video.windowH, 32, flags); | |
107 } | |
108 if (surface is null) { | |
102 logger.fatal ("Unable to set video mode:"); | 109 logger.fatal ("Unable to set video mode:"); |
103 char* msg = SDL_GetError (); | 110 char* msg = SDL_GetError (); |
104 logger.fatal (msg ? fromStringz(msg) : "no reason available"); | 111 logger.fatal (msg ? fromStringz(msg) : "no reason available"); |
105 | 112 |
106 setInitFailure (); | 113 setInitFailure (); |
110 // Window-manager settings | 117 // Window-manager settings |
111 SDL_WM_SetCaption (toStringz ("mde"), null); | 118 SDL_WM_SetCaption (toStringz ("mde"), null); |
112 // SDL_WM_GrabInput (use later) | 119 // SDL_WM_GrabInput (use later) |
113 | 120 |
114 logger.trace ("init4: setupWindow() finished"); | 121 logger.trace ("init4: setupWindow() finished"); |
122 } | |
123 | |
124 void resizeWindow (int w, int h) { | |
125 if (Options.video.fullscreen) { | |
126 Options.video.screenW = w; | |
127 Options.video.screenH = h; | |
128 } else { | |
129 Options.video.windowW = w; | |
130 Options.video.windowH = h; | |
131 } | |
132 | |
133 /+ Does SDL_SetVideoMode need to be called? | |
134 setupWindow (); | |
135 +/ | |
115 } | 136 } |
116 | 137 |
117 void cleanupSDL () { // cleanup2 func | 138 void cleanupSDL () { // cleanup2 func |
118 logger.trace ("cleanup2: cleanupSDL() started"); | 139 logger.trace ("cleanup2: cleanupSDL() started"); |
119 SDL_Quit(); | 140 SDL_Quit(); |