2licht

C Eample Code

This is basically a ported version of the first Irrlicht Engine example code.

#include <2licht/2licht.h>


int main(void)
{
    L2CreationParameters params;
    L2CreationParametersSetDefaults(&params);
    params.DriverType = L2_DRIVER_TYPE_SOFTWARE;
    L2SizeSet(&params.WindowSize, 640, 480);
    params.BitsPerPixel = 16;
    
    L2Device *device = L2CreateDevice(&params, NULL);
    if (!device) return 1;
    
    L2DeviceSetWindowCaption(device, "Hello World! - Irrlicht Engine Demo");
    
    L2VideoDriver *driver = L2DeviceGetVideoDriver(device);  
    L2SceneManager *smgr  = L2DeviceGetSceneManager(device);
    L2GUIEnvironment * guienv = L2DeviceGetGUIEnvironment(device);
    
    L2Rectangle textPos = { 10, 10, 260, 22 };
    L2GUIEnvironmentAddStaticText(guienv," Hello World! This is the Irrlicht Software renderer!",
        &textPos, true, false, NULL, -1, true);
    
    L2AnimatedMesh *mesh = L2SceneManagerGetMesh(smgr, "../../../media/sydney.md2");
    if (!mesh)
    {
        L2DestroyDevice(device);
        return 1;
    }
    
    L2Vector3D nullVec = { 0, 0, 0 }, oneVec = { 1, 1, 1 };
    L2AnimatedMeshSceneNode *node = L2SceneManagerAddAnimatedMeshSceneNode(
        smgr, mesh, NULL, -1, &nullVec, &nullVec, &oneVec, false);
    
    if (node)
    {
        L2SceneNodeSetMaterialFlag((L2SceneNode*) node, L2_MATERIAL_FLAG_LIGHTING, false);
        L2AnimatedMeshSceneNodeSetMD2Animation(node, L2_MD2_ANIMATION_STAND);
        L2SceneNodeSetMaterialTexture((L2SceneNode*) node, 0, 
                                 L2VideoDriverGetTexture(driver, "../../../media/sydney.bmp"));
    }
    
    L2Vector3D cameraVec = { 0, 30, -40 }, cameraTargetVec = { 0, 5, 0 };
    L2SceneManagerAddCameraSceneNode(smgr, NULL, &cameraVec, &cameraTargetVec, -1, true);
    
    while (L2DeviceRun(device))
        if (L2DeviceIsWindowActive(device))
        {
            L2VideoDriverBeginScene(driver, true, true, 0xff646594, NULL, NULL);
            L2SceneManagerDrawAll(smgr);
            L2GUIEnvironmentDrawAll(guienv);
            L2VideoDriverEndScene(driver);
        }
    
    L2DestroyDevice(device);
    return 0;
}

Thanks to Oleg Parashchenko for his Syntax Highlighter.