import dogre.all; import std.stdio; import ogrebites.sdkcameraman; pragma(lib, "dogre.lib"); class Tutorial2Stuff { Root root; ConfigFile cf; SceneManager sm; RenderWindow win; Camera cam; Viewport vp; this() { root = new Root(); if(!(root.restoreConfig || root.showConfigDialog)) throw new Exception("Unable to configure."); root.saveConfig(); initResources(); initScene(); if(go) render(); } void initResources() { cf = new ConfigFile(); cf.load("resources_d.cfg"); ConfigFile.SectionIterator seci = cf.getSectionIterator(); string secname; while(seci.hasMoreElements) { secname = seci.peekNextKey(); //get [General] auto settings = seci.getNext(); foreach(string typename, string archname; settings) ResourceGroupManager.getSingleton().addResourceLocation(archname, typename, secname); } } void initScene() { sm = root.createSceneManager(ST_GENERIC); win = root.initialise(true, "Tutorial #2"); ResourceGroupManager.getSingleton().initialiseAllResourceGroups(); //ALWAYS //call that AFTER... not before initialising the window. cam = sm.createCamera("PlayerCam"); cam.setPosition(new Vector3(300,600,190)); cam.lookAt(new Vector3(0,0,0)); cam.setNearClipDistance(5); vp = win.addViewport(cam); vp.setBackgroundColour(new ColourValue(0,0,0)); cam.setAspectRatio(cast(float)vp.getActualWidth()/cast(float)vp.getActualHeight()); auto man = new SdkCameraMan(cam); } bool go() { sm.setAmbientLight(new ColourValue(0, 0, 0)); sm.setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); Entity entNinja = sm.createEntity("Ninja", "ninja.mesh"); entNinja.setCastShadows(true); sm.getRootSceneNode().createChildSceneNode().attachObject(entNinja); MeshManager mm = MeshManager.getSingleton(); Plane plane = new Plane(Vector3.UNIT_Y, 0); mm.createPlane("ground", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 20, 20, true, 1, 5, 5, Vector3.UNIT_Z); Entity entGround = sm.createEntity("GroundEntity", "ground"); sm.getRootSceneNode().createChildSceneNode().attachObject(entGround); entGround.setMaterialName("Examples/Rockwall"); entGround.setCastShadows(false); Light pointLight = sm.createLight("pointLight"); pointLight.setType(Light.LT_POINT); pointLight.setPosition(new Vector3(0, 600, 250)); pointLight.setDiffuseColour(1, 0, 0); pointLight.setSpecularColour(new ColourValue(1, 0, 0)); Light dirLight = sm.createLight("dirLight"); dirLight.setType(Light.LT_DIRECTIONAL); dirLight.setDiffuseColour(.25, .25, 0); dirLight.setSpecularColour(new ColourValue(.25, .25, 0)); dirLight.setDirection(new Vector3(0, -1, 1)); auto spotLight = sm.createLight("spotLight"); spotLight.setType(Light.LT_SPOTLIGHT); spotLight.setDiffuseColour(0, 0, .6); spotLight.setSpecularColour(0, 0, .9); spotLight.setDirection(30, -300, -100); spotLight.setPosition(new Vector3(100, 500, 100)); spotLight.setSpotlightRange(new Radian(.5), new Radian(.9)); return true; //OK to render. } void render() { while(true) { WindowEventUtilities.messagePump(); if(win.isClosed() || !root.renderOneFrame()) break; } } } void main() { auto stuff = new Tutorial2Stuff(); }