Mercurial > projects > mde
comparison mde/gl.d @ 27:0aa621b3e070
Some GUI work, plus a small fix in the paths module.
Implemented GUI code to load windows from file with a basic widget and draw.
Fixed a bug in mde.resource.paths.mdeDirectory.makeMTReader when called with readOrder == PRIORITY.HIGH_ONLY.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Fri, 04 Apr 2008 17:07:38 +0100 |
parents | 611f7b9063c6 |
children | 467c74d4804d |
comparison
equal
deleted
inserted
replaced
26:611f7b9063c6 | 27:0aa621b3e070 |
---|---|
11 See the GNU General Public License for more details. | 11 See the GNU General Public License for more details. |
12 | 12 |
13 You should have received a copy of the GNU General Public License | 13 You should have received a copy of the GNU General Public License |
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | 14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
15 | 15 |
16 /** Simple OpenGL functions. */ | 16 /** Some basic OpenGL code. |
17 * | |
18 * Everything here is really intended as makeshift code to enable GUI development. */ | |
17 module mde.gl; | 19 module mde.gl; |
18 | 20 |
19 import mde.scheduler.runTime; | 21 import mde.scheduler.runTime; |
20 | 22 |
21 import derelict.sdl.sdl; | 23 import derelict.sdl.sdl; |
23 | 25 |
24 static this () { | 26 static this () { |
25 Scheduler.perRequest (RF_KEYS.DRAW, &mde.gl.draw); | 27 Scheduler.perRequest (RF_KEYS.DRAW, &mde.gl.draw); |
26 } | 28 } |
27 | 29 |
30 //BEGIN GL & window setup | |
28 void glSetup () { | 31 void glSetup () { |
29 glClearColor (0.0f, 0.0f, 0.0f, 0.0f); | 32 glClearColor (0.0f, 0.0f, 0.0f, 0.0f); |
30 } | 33 } |
31 | 34 |
32 void setProjection (int w, int h) { | 35 void setProjection (int w, int h) { |
33 glMatrixMode (GL_PROJECTION); | 36 glMatrixMode (GL_PROJECTION); |
34 glLoadIdentity (); | 37 glLoadIdentity (); |
35 | 38 |
36 glViewport (0,0,w,h); | 39 glViewport (0,0,w,h); |
37 //glOrtho (0.0,w, 0.0,h, -1.0, 1.0); | 40 glOrtho (0.0,w, 0.0,h, -1.0, 1.0); |
38 glOrtho (0.0,1.0,0.0,1.0,-1.0,1.0); | 41 //glOrtho (0.0,1.0,0.0,1.0,-1.0,1.0); |
39 | 42 |
40 glMatrixMode(GL_MODELVIEW); | 43 glMatrixMode(GL_MODELVIEW); |
41 glLoadIdentity(); | 44 glLoadIdentity(); |
42 } | 45 } |
46 //END GL & window setup | |
43 | 47 |
48 //BEGIN Drawing utils | |
49 // Simple drawing commands for use by GUI | |
50 // (temporary) | |
51 void setColor (float r, float g, float b) { | |
52 glColor3f (r, g, b); | |
53 } | |
54 void drawBox (int l, int r, int b, int t) { | |
55 glBegin (GL_QUADS); | |
56 { | |
57 glVertex2i (l, b); | |
58 glVertex2i (r, b); | |
59 glVertex2i (r, t); | |
60 glVertex2i (l, t); | |
61 } | |
62 glEnd(); | |
63 } | |
64 //END Drawing utils | |
65 | |
66 //BEGIN Drawing loop | |
44 // Temporary draw function | 67 // Temporary draw function |
45 void draw () { | 68 void draw () { |
46 glClear(GL_COLOR_BUFFER_BIT); | 69 glClear(GL_COLOR_BUFFER_BIT); |
47 | 70 |
48 glBegin (GL_QUADS); | 71 foreach (func; drawCallbacks) |
49 { | 72 func(); |
50 glColor3f (0.2f, 0.6f, 0.8f); | |
51 /+glVertex2i (40, 40); | |
52 glVertex2i (200, 40); | |
53 glVertex2i (200, 200); | |
54 glVertex2i (40, 200);+/ | |
55 glVertex2f (0.1f, 0.1f); | |
56 glVertex2f (0.9f, 0.1f); | |
57 glVertex2f (0.9f, 0.9f); | |
58 glVertex2f (0.1f, 0.9f); | |
59 } | |
60 glEnd(); | |
61 | 73 |
62 glFlush(); | 74 glFlush(); |
63 SDL_GL_SwapBuffers(); | 75 SDL_GL_SwapBuffers(); |
64 } | 76 } |
77 | |
78 alias void delegate() DrawingFunc; | |
79 void addDrawCallback (DrawingFunc f) { | |
80 drawCallbacks ~= f; | |
81 } | |
82 private DrawingFunc[] drawCallbacks; | |
83 //END Drawing loop |