Page 1 of 1

Irrlicht with haxe

Posted: Wed Aug 19, 2015 1:56 pm
by djoker
i folks,
with the new haxe its now possible to code c++ in to haxe .
so i try to bind irrlicht directly and this is the result.

https://github.com/akadjoker/hxIrr

Image

Code: Select all

 
import irr.Driver;
import irr.Device;
import irr.SceneManager;
 
 
 
class Test {
    static function main() {
        trace("INIT");
        try {
            start();
        } catch( e : Dynamic ) {
        }
        trace("DONE");
    }
 
    static function start() 
    {
    
var device:Device = new Device(800, 600);
var driver:Driver = device.getVideoDriver();
var smgr:SceneManager = device.getSceneManager();
 
var cube = smgr.addCubeSceneNode();
cube.setPosition(0, 0, 2);
 
cube.setMaterialTexture(0,driver.getTexture("hxlogo.png"));
 
//var camera = smgr.addCameraSceneNodeFPS();
var camera = smgr.addCameraSceneNode();
 
    device.setWindowCaption("Irrlicht with HAXE");
    
 
        
        while (device.run())
        {
            driver.beginScene(0x0000ffff);
            smgr.drawAll();
            driver.endScene();
            device.setWindowCaption("Irrlicht with HAXE - FPS["+ driver.getFps()+"]");
        }
        
            
            
            
    }
 
}
 

Code: Select all

 
package irr;
import cpp.ConstCharStar;
import haxe.NativeWrapper;
 
/**
 * ...
 * @author Luis Santos AKA DJOKER
 */
class Driver  implements NativeWrapper 
{
 
    @cpp var driver : PTR<IVideoDriver>;
    
    public function new( )  
    {
     untyped __cpp__('driver = 0;');
    }
    
    public function getTexture(filename:String):Texture
    {
        var t = new Texture();
        
        var fnm:ConstCharStar = ConstCharStar.fromString(filename);
        
        
         untyped __cpp__('
         
         t->ptr = driver->getTexture(fnm);
         
         ');
         return t;
    }
    
    
    public function beginScene(color:Int, backBuffer:Bool = true, zBuffer:Bool = true):Bool
    {
         untyped __cpp__('
         
         driver->beginScene(backBuffer, zBuffer, SColor(color));
         
         ');
         return true;
    }
    
    public function endScene():Bool
    {
         untyped __cpp__('
         
         driver->endScene();
         
         
         ');
         return true;
    }
    
    public function getFps():Int
    {
        var fps:Int = 0;
         untyped __cpp__('
         
         fps=driver->getFPS();
         
         
         ');
         return fps;
    }
}