annotate mde/setup/sdl.d @ 63:66d555da083e

Moved many modules/packages to better reflect usage.
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 27 Jun 2008 18:35:33 +0100
parents mde/sdl.d@f3d8c0441408
children cc3763817b8a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /** Just a temporary place to put SDL Init and Video stuff.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 */
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 55
diff changeset
18 module mde.setup.sdl;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 55
diff changeset
20 import mde.setup.initFunctions;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 import mde.input.joystick;
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 55
diff changeset
22 import mde.lookup.Options;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 import mde.gl.basic;
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 33
diff changeset
24 import imde = mde.imde;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26 import tango.util.log.Log : Log, Logger;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27 import tango.stdc.stringz;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29 import derelict.sdl.sdl;
48
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
30 import derelict.opengl.gl; // for loading a later gl version
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
31 import derelict.util.exception;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
33 private Logger logger;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34 static this() {
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 55
diff changeset
35 logger = Log.getLogger ("mde.setup.sdl");
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 init.addFunc (&initSdlAndGl, "initSdlAndGl");
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
39
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
40 private uint flags = 0;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 void initSdlAndGl() { // init func
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43 // Initialise SDL
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_JOYSTICK /+| SDL_INIT_EVENTTHREAD+/)) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45 logger.fatal ("SDL initialisation failed:");
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 char* msg = SDL_GetError ();
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47 logger.fatal (msg ? fromStringz(msg) : "no reason available");
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49 setInitFailure ();
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 return;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
51 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53 debug logger.trace ("SDL initialised");
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
54
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55 // Must be called after SDL has been initialised, so cannot be a separate Init function.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
56 openJoysticks (); // after SDL init
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 cleanup.addFunc (&cleanupSDL, "cleanupSDL");
41
b3a6ca4516b4 The renderer now controls which parts of the window border allow resizing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
58
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 setupWindow();
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
60 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
61
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
62 void setupWindow() { // indirect init func (depends on initSdlAndGl)
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
63 // Window creation flags and size
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64 flags = SDL_OPENGL;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
65 if (vidOpts.hardware) flags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66 else flags |= SDL_SWSURFACE;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 int w, h;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68 if (vidOpts.fullscreen) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
69 flags |= SDL_FULLSCREEN;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
70 w = vidOpts.screenW;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
71 h = vidOpts.screenH;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
72 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
73 else {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
74 if (vidOpts.resizable) flags |= SDL_RESIZABLE;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
75 if (vidOpts.noFrame) flags |= SDL_NOFRAME;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
76 w = vidOpts.windowW;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
77 h = vidOpts.windowH;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
78 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
79
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
80 // OpenGL attributes
48
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
81 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
82 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
83 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
84 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
85 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
86
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
87 // Open a window
41
b3a6ca4516b4 The renderer now controls which parts of the window border allow resizing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
88 debug logger.trace ("Opening a window (this can crash if the libraries are messed up)");
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
89 if (SDL_SetVideoMode (w, h, 32, flags) is null) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
90 logger.fatal ("Unable to set video mode:");
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
91 char* msg = SDL_GetError ();
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
92 logger.fatal (msg ? fromStringz(msg) : "no reason available");
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
93
48
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
94 // Print a load of info:
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
95 logger.info ("Available video modes:");
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
96 char[128] tmp;
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
97 SDL_Rect** modes = SDL_ListModes (null, SDL_FULLSCREEN);
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
98 if (modes is null) logger.info ("None!");
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
99 else if (modes is cast(SDL_Rect**) -1) logger.info ("All modes are available");
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
100 else {
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
101 for (uint i = 0; modes[i] !is null; ++i) {
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
102 logger.info (logger.format (tmp, "\t{}x{}", modes[i].w, modes[i].h));
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
103 }
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
104 }
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
105
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
106 SDL_VideoInfo* vi = SDL_GetVideoInfo ();
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
107 if (vi !is null) {
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
108 logger.info ("Video info:");
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
109 logger.info ("Hardware surface support: "~ (vi.flags & SDL_HWSURFACE ? "yes" : "no"));
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
110 logger.info (logger.format (tmp, "Video memory: {}", vi.video_mem));
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
111
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
112 if (vi.vfmt !is null) {
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
113 logger.info ("Best video mode:");
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
114 logger.info (logger.format (tmp, "Bits per pixel: {}", vi.vfmt.BitsPerPixel));
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
115 }
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
116 }
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
117
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
118 setInitFailure ();
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
119 return;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
120 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
121
48
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
122 /* Now (must be done after GL context is created) we can try to load later version.
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
123 * The initial loading provides opengl 1.1 features.
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
124 *
55
f3d8c0441408 Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 54
diff changeset
125 * 1.4 is now used for glBlendColor (coloured text).
f3d8c0441408 Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 54
diff changeset
126 *
48
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
127 * Currently the latest version used is 1.3; adjust this as necessary. However, before using
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
128 * features from any OpenGL version > 1.1 a check must be made on what was loaded by calling
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
129 * DerelictGL.availableVersion(). Note that availableVersion() could be used instead to load
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
130 * the highest supported version but this way we know what we're getting.
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
131 */
55
f3d8c0441408 Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 54
diff changeset
132 if (DerelictGL.availableVersion < GLVersion.Version13) {
f3d8c0441408 Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 54
diff changeset
133 logger.fatal ("Required at least OpenGL 1.3");
f3d8c0441408 Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 54
diff changeset
134 setInitFailure;
f3d8c0441408 Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 54
diff changeset
135 return;
f3d8c0441408 Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 54
diff changeset
136 }
f3d8c0441408 Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 54
diff changeset
137 /+try {
f3d8c0441408 Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 54
diff changeset
138 DerelictGL.loadVersions(GLVersion.Version14);
48
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
139 } catch (SharedLibProcLoadException e) {
55
f3d8c0441408 Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 54
diff changeset
140 logger.warn ("Loading OpenGL version 1.4 failed:");
48
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
141 logger.warn (e.msg);
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
142
48
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
143 //NOTE: might be worth guaranteeing a minimal version to save later checks?
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
144 /+ Do this if you want the program to abort:
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
145 setInitFailure ();
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
146 return;
48
a98ffb64f066 Implemented font rendering (grayscale only; i.e. non-LCD).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
147 +/
55
f3d8c0441408 Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 54
diff changeset
148 }+/
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
149
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
150 // OpenGL stuff:
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
151 glSetup();
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
152 setProjection (w, h);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
153
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
154 // Window-manager settings
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
155 SDL_WM_SetCaption (toStringz ("mde"), null);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
156 // SDL_WM_GrabInput (use later)
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
157 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
158
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
159 void resizeWindow (int w, int h) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
160 if (vidOpts.fullscreen) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
161 Options.setInt ("video", "screenW", w);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
162 Options.setInt ("video", "screenH", h);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
163 } else {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
164 Options.setInt ("video", "windowW", w);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
165 Options.setInt ("video", "windowH", h);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
166 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
167
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
168 if (SDL_SetVideoMode (w, h, 32, flags) is null) {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
169 logger.fatal ("Unable to reset video mode:");
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
170 char* msg = SDL_GetError ();
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
171 logger.fatal (msg ? fromStringz(msg) : "no reason available");
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
172
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 33
diff changeset
173 imde.run = false;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
174 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
175
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
176 // Reset the projection and viewport
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
177 setProjection (w, h);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
178 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
179
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
180 void cleanupSDL () { // cleanup func
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
181 closeJoysticks();
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
182 SDL_Quit();
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
183 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
184
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
185
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
186 /** All video options. */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
187 OptionsVideo vidOpts;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
188 class OptionsVideo : Options {
50
f68ae1d667f9 Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 48
diff changeset
189 mixin (impl!("bool fullscreen,hardware,resizable,noFrame; int screenW,screenH,windowW,windowH;"));
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
190
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
191 static this() {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
192 vidOpts = new OptionsVideo;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
193 Options.addOptionsClass (vidOpts, "video");
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
194 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
195 }