static void Main(string[] args) { DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(800, 600), 16); if (device == null) { return; } device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.SetWindowResizable(true); device.SetWindowCaption("Irrlicht Engine - Loading..."); VideoDriver driver = device.VideoDriver; GUIEnvironment env = device.GUIEnvironment; SceneManager smgr = device.SceneManager; smgr.Attributes.SetValue(SceneParameters.COLLADA_CreateSceneInstances, true); driver.SetTextureCreationFlag(TextureCreationFlag.Always32Bit, true); smgr.AddLightSceneNode(null, new Vector3Df(200), new Colorf(1.0f, 1.0f, 1.0f), 2000); smgr.AmbientLight = new Colorf(0.3f, 0.3f, 0.3f); // add our media directory as "search path" device.FileSystem.AddFileArchive("../../media/"); // read configuration from xml file // (we use .NET way to do this, since Lime doesn't support native Irrlicht' xml reader) XmlDocument xml = new XmlDocument(); xml.Load("../../media/config.xml"); startUpModelFile = xml.DocumentElement["startUpModel"].Attributes["file"].Value; caption = xml.DocumentElement["messageText"].Attributes["caption"].Value; messageText = xml.DocumentElement["messageText"].InnerText; if (args.Length > 0) { startUpModelFile = args[0]; } // set a nicer font GUIFont font = env.GetFont("fonthaettenschweiler.bmp"); if (font != null) { env.Skin.SetFont(font); } // load the irrlicht engine logo GUIImage img = env.AddImage( driver.GetTexture("irrlichtlogoalpha2.tga"), new Vector2Di(10, driver.ScreenSize.Height - 128)); img.ID = (int)guiID.Logo; // lock the logo's edges to the bottom left corner of the screen img.SetAlignment(GUIAlignment.UpperLeft, GUIAlignment.UpperLeft, GUIAlignment.LowerRight, GUIAlignment.LowerRight); // create menu GUIContextMenu menu = env.AddMenu(); menu.AddItem("File", -1, true, true); menu.AddItem("View", -1, true, true); menu.AddItem("Camera", -1, true, true); menu.AddItem("Help", -1, true, true); GUIContextMenu submenu; submenu = menu.GetSubMenu(0); submenu.AddItem("Open Model File & Texture...", (int)guiID.OpenModel); submenu.AddItem("Set Model Archive...", (int)guiID.SetModelArchive); submenu.AddItem("Load as Octree", (int)guiID.LoadAsOctree); submenu.AddSeparator(); submenu.AddItem("Quit", (int)guiID.Quit); submenu = menu.GetSubMenu(1); submenu.AddItem("sky box visible", (int)guiID.SkyBoxVisible, true, false, true); submenu.AddItem("toggle model debug information", (int)guiID.ToggleDebugInfo, true, true); submenu.AddItem("model material", -1, true, true); submenu = submenu.GetSubMenu(1); submenu.AddItem("Off", (int)guiID.DebugOff); submenu.AddItem("Bounding Box", (int)guiID.DebugBoundingBox); submenu.AddItem("Normals", (int)guiID.DebugNormals); submenu.AddItem("Skeleton", (int)guiID.DebugSkeleton); submenu.AddItem("Wire overlay", (int)guiID.DebugWireOverlay); submenu.AddItem("Half-Transparent", (int)guiID.DebugHalfTransparent); submenu.AddItem("Buffers bounding boxes", (int)guiID.DebugBuffersBoundingBoxes); submenu.AddItem("All", (int)guiID.DebugAll); submenu = menu.GetSubMenu(1).GetSubMenu(2); submenu.AddItem("Solid", (int)guiID.ModelMaterialSolid); submenu.AddItem("Transparent", (int)guiID.ModelMaterialTransparent); submenu.AddItem("Reflection", (int)guiID.ModelMaterialReflection); submenu = menu.GetSubMenu(2); submenu.AddItem("Maya Style", (int)guiID.CameraMaya); submenu.AddItem("First Person", (int)guiID.CameraFirstPerson); submenu = menu.GetSubMenu(3); submenu.AddItem("About", (int)guiID.About); // create toolbar GUIToolBar bar = env.AddToolBar(); Texture image = driver.GetTexture("open.png"); bar.AddButton((int)guiID.ButtonOpenModel, null, "Open a model", image, null, false, true); image = driver.GetTexture("tools.png"); bar.AddButton((int)guiID.ButtonShowToolbox, null, "Open Toolset", image, null, false, true); image = driver.GetTexture("zip.png"); bar.AddButton((int)guiID.ButtonSelectArchive, null, "Set Model Archive", image, null, false, true); image = driver.GetTexture("help.png"); bar.AddButton((int)guiID.ButtonShowAbout, null, "Open Help", image, null, false, true); // create a combobox with some senseless texts GUIComboBox box = env.AddComboBox(new Recti(250, 4, 350, 23), bar, (int)guiID.TextureFilter); box.AddItem("No filtering"); box.AddItem("Bilinear"); box.AddItem("Trilinear"); box.AddItem("Anisotropic"); box.AddItem("Isotropic"); // disable alpha setSkinTransparency(255, env.Skin); // add a tabcontrol createToolBox(); // create fps text GUIStaticText fpstext = env.AddStaticText("", new Recti(400, 4, 570, 23), true, false, bar); GUIStaticText postext = env.AddStaticText("", new Recti(10, 50, 470, 80), false, false, null, (int)guiID.PositionText); postext.Visible = false; // show about message box and load default model if (args.Length == 0) { showAboutText(); } loadModel(startUpModelFile); // add skybox skybox = smgr.AddSkyBoxSceneNode( "irrlicht2_up.jpg", "irrlicht2_dn.jpg", "irrlicht2_lf.jpg", "irrlicht2_rt.jpg", "irrlicht2_ft.jpg", "irrlicht2_bk.jpg"); // add a camera scene node camera[0] = smgr.AddCameraSceneNodeMaya(); camera[0].FarValue = 20000; // Maya cameras reposition themselves relative to their target, // so target the location where the mesh scene node is placed. camera[0].Target = new Vector3Df(0, 30, 0); camera[1] = smgr.AddCameraSceneNodeFPS(); camera[1].FarValue = 20000; camera[1].Position = new Vector3Df(0, 0, -70); camera[1].Target = new Vector3Df(0, 30, 0); setActiveCamera(camera[0]); // set window caption caption = string.Format("{0} - [{1}]", caption, driver.Name); device.SetWindowCaption(caption); // remember state so we notice when the window does lose the focus bool hasFocus = device.WindowFocused; // draw everything while (device.Run() && driver != null) { // Catch focus changes (workaround until Irrlicht has events for this) bool focused = device.WindowFocused; if (hasFocus && !focused) { onKillFocus(); } hasFocus = focused; if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(50, 50, 50)); smgr.DrawAll(); env.DrawAll(); driver.EndScene(); string str = string.Format("FPS: {0} Tris: {1}", driver.FPS, driver.PrimitiveCountDrawn); fpstext.Text = str; CameraSceneNode cam = device.SceneManager.ActiveCamera; str = string.Format("Pos: {0} Tgt: {1}", cam.Position, cam.Target); postext.Text = str; } else { device.Yield(); } } device.Drop(); }