view 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
line wrap: on
line source

/* LICENSE BLOCK
Part of mde: a Modular D game-oriented Engine
Copyright © 2007-2008 Diggory Hardy

This program is free software: you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation, either
version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>. */

/** Some basic OpenGL code.
*
* Everything here is really intended as makeshift code to enable GUI development. */
module mde.gl;

import mde.scheduler.runTime;

import derelict.sdl.sdl;
import derelict.opengl.gl;

static this () {
    Scheduler.perRequest (RF_KEYS.DRAW, &mde.gl.draw);
}

//BEGIN GL & window setup
void glSetup () {
    glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
}

void setProjection (int w, int h) {
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    
    glViewport (0,0,w,h);
    glOrtho (0.0,w, 0.0,h, -1.0, 1.0);
    //glOrtho (0.0,1.0,0.0,1.0,-1.0,1.0);
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
//END GL & window setup

//BEGIN Drawing utils
// Simple drawing commands for use by GUI
// (temporary)
void setColor (float r, float g, float b) {
    glColor3f (r, g, b);
}
void drawBox (int l, int r, int b, int t) {
    glBegin (GL_QUADS);
    {
        glVertex2i (l, b);
        glVertex2i (r, b);
        glVertex2i (r, t);
        glVertex2i (l, t);
    }
    glEnd();
}
//END Drawing utils

//BEGIN Drawing loop
// Temporary draw function
void draw () {
    glClear(GL_COLOR_BUFFER_BIT);
    
    foreach (func; drawCallbacks)
        func();
    
    glFlush();
    SDL_GL_SwapBuffers();
}

alias void delegate() DrawingFunc;
void addDrawCallback (DrawingFunc f) {
    drawCallbacks ~= f;
}
private DrawingFunc[] drawCallbacks;
//END Drawing loop