Project Description
Dogre is a wrapper for the Ogre3D library in D. It is developed in both C++ and D.
Still a work in progress, do not use yet.

import dogre.all;
import std.stdio;

pragma(lib, "Dogre.lib");

class MyListener : LogListener
{
    this()
    {
        //Event.messageLogged ~= &messageLogged
        //Also possible (handy because multiple inheritance is not allowed in D)
    }
    override void messageLogged(string message, LogMessageLevel lml, bool maskDebug, string logName)
    {
        //writeln("Listened to: ",message);
    }
}

class MyFrameListener : FrameListener
{
    private float timeElapsed;
    
    this(){timeElapsed = 0.0f;}
    
    bool frameStarted(ref const(FrameEvent) evt)
    {
        timeElapsed += evt.timeSinceLastFrame;
        if(timeElapsed > 5)
            return false;
        return true;
    }
}

void main()
{
    LogManager logMan = new LogManager();
    logMan = LogManager.getSingleton();  //essentially does nothing...
    
    logMan.setLogDetail(LL_BOREME);
    Log log = logMan.createLog("mylog.log", true, true, false);  //Creates a log
    
    auto ln = new MyListener();  //Listener to the log
    
    log.addListener(ln); //adds that listener to the default log
    
    Root r = new Root("", "ogre_settings.cfg");  //3rd argument not used because
    //the singleton log is already created.

    if(!r.restoreConfig())  //if ogre_settings.cfg not there
        if(!r.showConfigDialog())
            return;

    Log l = new Log("Hi.txt");  //You can also create a log like this.
    
    //demonstrating that the destructor also works.

    r.saveConfig();
    
    SceneManager sm = r.createSceneManager(ST_GENERIC);

    RenderWindow win = r.initialise(true, "My Window");

    Camera mycam = sm.createCamera("MyCamera");
    
    auto vp = win.addViewport(mycam);
    
    mycam.setAspectRatio(cast(float)vp.getActualWidth() / cast(float)vp.getActualHeight());
    
    mycam.setFarClipDistance(1000.0f);
	mycam.setNearClipDistance(5.0f);
    
    r.addFrameListener(new MyFrameListener());
    r.startRendering();
    
    //delete r;  Well, this keyword is deprecated now.
}

More: Code examples!

Screenshot

ogrehead_works.png

Moved from http://code.google.com/p/dogre/.

Last edited Nov 15, 2010 at 12:26 AM by jcao219, version 12