Mercurial > projects > mde
annotate mde/gl.d @ 30:467c74d4804d
Major changes to the scheduler, previously only used by the main loop.
Revamped Scheduler. Functions can be removed, have multiple schedules, have their scheduling changed, etc.
Scheduler has a unittest. Checked all pass.
Main loop scheduler moved to mde. Draw-on-demand currently disabled, simplifying this.
Made mtunitest.d remove the temporary file it uses afterwards.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Mon, 28 Apr 2008 10:59:47 +0100 |
parents | 0aa621b3e070 |
children |
rev | line source |
---|---|
20 | 1 /* LICENSE BLOCK |
2 Part of mde: a Modular D game-oriented Engine | |
3 Copyright © 2007-2008 Diggory Hardy | |
4 | |
26
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
25
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
25
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
25
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
20 | 8 |
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | |
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
11 See the GNU General Public License for more details. | |
12 | |
26
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
25
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
25
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
20 | 15 |
27
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
16 /** Some basic OpenGL code. |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
17 * |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
18 * Everything here is really intended as makeshift code to enable GUI development. */ |
20 | 19 module mde.gl; |
20 | |
30
467c74d4804d
Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
21 import global = mde.global; |
467c74d4804d
Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
22 import mde.gui.gui; |
23
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
23 |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
24 import derelict.sdl.sdl; |
20 | 25 import derelict.opengl.gl; |
26 | |
30
467c74d4804d
Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
27 import tango.time.Time; // TimeSpan (type only; unused) |
23
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
28 |
27
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
29 //BEGIN GL & window setup |
23
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
30 void glSetup () { |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
31 glClearColor (0.0f, 0.0f, 0.0f, 0.0f); |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
32 } |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
33 |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
34 void setProjection (int w, int h) { |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
35 glMatrixMode (GL_PROJECTION); |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
36 glLoadIdentity (); |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
37 |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
38 glViewport (0,0,w,h); |
27
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
39 glOrtho (0.0,w, 0.0,h, -1.0, 1.0); |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
40 //glOrtho (0.0,1.0,0.0,1.0,-1.0,1.0); |
23
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
41 |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
42 glMatrixMode(GL_MODELVIEW); |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
43 glLoadIdentity(); |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
44 } |
27
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
45 //END GL & window setup |
23
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
46 |
27
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
47 //BEGIN Drawing utils |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
48 // Simple drawing commands for use by GUI |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
49 // (temporary) |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
50 void setColor (float r, float g, float b) { |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
51 glColor3f (r, g, b); |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
52 } |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
53 void drawBox (int l, int r, int b, int t) { |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
54 glBegin (GL_QUADS); |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
55 { |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
56 glVertex2i (l, b); |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
57 glVertex2i (r, b); |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
58 glVertex2i (r, t); |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
59 glVertex2i (l, t); |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
60 } |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
61 glEnd(); |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
62 } |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
63 //END Drawing utils |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
64 |
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
65 //BEGIN Drawing loop |
23
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
66 // Temporary draw function |
30
467c74d4804d
Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
67 void draw (TimeSpan) { |
23
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
68 glClear(GL_COLOR_BUFFER_BIT); |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
69 |
30
467c74d4804d
Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
70 gui.draw (); |
23
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
71 |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
72 glFlush(); |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
73 SDL_GL_SwapBuffers(); |
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
74 } |
27
0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
26
diff
changeset
|
75 //END Drawing loop |