static void Main(string[] args) { DriverType driverType; if (!AskUserForDriver(out driverType)) return; device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(640, 480)); if (device == null) return; device.SetWindowCaption("Irrlicht Engine - User Interface Demo"); device.SetWindowResizable(true); VideoDriver driver = device.VideoDriver; GUIEnvironment env = device.GUIEnvironment; GUISkin skin = env.Skin; GUIFont font = env.GetFont("../../media/fonthaettenschweiler.bmp"); if (font != null) skin.SetFont(font); skin.SetFont(env.BuiltInFont, GUIDefaultFont.Tooltip); env.AddButton(new Recti(10, 240, 110, 240 + 32), null, GUI_ID_ButtonQuit, "Quit", "Exits Program"); env.AddButton(new Recti(10, 280, 110, 280 + 32), null, GUI_ID_ButtonWindowNew, "New Window", "Launches a new Window"); env.AddButton(new Recti(10, 320, 110, 320 + 32), null, GUI_ID_ButtonFileOpen, "File Open", "Opens a file"); env.AddStaticText("Transparent Control:", new Recti(150, 20, 350, 40), true); GUIScrollBar scrollbar = env.AddScrollBar(true, new Recti(150, 45, 350, 60), null, GUI_ID_ScrollbarTransparency); scrollbar.MaxValue = 255; scrollbar.Position = (int)env.Skin.GetColor(GUIDefaultColor.WindowBackground).Alpha; GUIStaticText trq = env.AddStaticText("Logging ListBox:", new Recti(50,110,250,130), true); listbox = env.AddListBox(new Recti(50, 140, 250, 210)); env.AddEditBox("Editable Text", new Recti(350, 80, 550, 100)); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); env.AddImage(driver.GetTexture("../../media/irrlichtlogoalpha2.tga"), new Vector2Di(10, 10)); while (device.Run()) if (device.WindowActive) { driver.BeginScene(true, true, new Color(200, 200, 200)); env.DrawAll(); driver.EndScene(); } device.Drop(); }
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(); }
static void Main(string[] args) { DriverType driverType; if (!AskUserForDriver(out driverType)) return; device = IrrlichtDevice.CreateDevice(driverType, 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, (int)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(true, true, 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(); }
static void Main() { // setup Irrlicht device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1024, 768)); if (device == null) { return; } device.SetWindowResizable(true); device.SetWindowCaption("BulletSharp Test - Irrlicht Engine"); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; GUIFont font = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); CameraSceneNode camera = scene.AddCameraSceneNodeFPS(); camera.Position = new Vector3Df(100, 800, -1000); camera.Target = new Vector3Df(0, 100, 0); camera.FarValue = 30000; camera.AutomaticCulling = CullingType.FrustumBox; device.CursorControl.Visible = false; // setup physics physics = new Physics(); physics.Setup(new Vector3Df(0, -worldGravity, 0)); // setup particles particles = new Particles(device); // load quake level device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); Mesh mesh = scene.GetMesh("20kdm2.bsp").GetMesh(0); SceneNode quakeLevel = scene.AddOctreeSceneNode(mesh, null, -1, 1024); quakeLevel.Position = new Vector3Df(-1300, -144, -1249); physics.AddShape(Physics.Shape.Mesh, quakeLevel); // generate dynamic objects for (int i = 0; i < 3; i++) { for (int j = 0; j < 30; j++) { for (int k = 0; k < 3; k++) { MeshSceneNode n = scene.AddCubeSceneNode(cubeSize); n.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp")); n.SetMaterialFlag(MaterialFlag.Lighting, false); n.Position = new Vector3Df(70 + i * cubeSize, 520 + j * cubeSize, -650 + k * cubeSize); physics.AddShape(Physics.Shape.Box, n, cubeMass); } } } // main loop uint curTime = 0; uint lastTime = 0; int simFps = 0; int simFrames = 0; uint simFramesTime = 0; while (device.Run()) { if (device.WindowActive) { // simulate physics lastTime = curTime; curTime = device.Timer.Time; if (!simPaused) { float deltaTime = (curTime - lastTime) / 1000.0f; bool b = physics.StepSimulation(deltaTime); if (b) { simFrames++; } } if (curTime - simFramesTime > 1000) { simFramesTime = curTime; simFps = simFrames; simFrames = 0; } // winnow particles particles.Winnow(curTime, simPaused); // render scene driver.BeginScene(ClearBufferFlag.All, new Color(40, 80, 160)); scene.DrawAll(); Material material = new Material(); material.Lighting = false; device.VideoDriver.SetMaterial(material); // display stats driver.Draw2DRectangle(new Recti(10, 10, 140, 180), new Color(0x7f000000)); Vector2Di v = new Vector2Di(20, 20); font.Draw("Rendering", v, Color.SolidYellow); v.Y += 16; font.Draw(scene.Attributes.GetValue("calls") + " nodes", v, Color.SolidWhite); v.Y += 16; font.Draw(driver.FPS + " fps", v, Color.SolidWhite); v.Y += 16; font.Draw("[T]rails " + (useTrails ? "ON" : "OFF"), v, Color.SolidGreen); v.Y += 32; font.Draw("Physics" + (simPaused ? " (paused)" : ""), v, Color.SolidYellow); v.Y += 16; font.Draw(physics.NumCollisionObjects + " shapes", v, Color.SolidWhite); v.Y += 16; font.Draw(simFps + " fps", v, Color.SolidWhite); v.Y += 16; font.Draw("[Space] to pause", v, Color.SolidGreen); driver.EndScene(); } device.Yield(); } // drop physics.Drop(); device.Drop(); }
static void Main(string[] args) { DriverType driverType; if (!AskUserForDriver(out driverType)) { return; } device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(640, 480)); if (device == null) { return; } device.SetWindowCaption("Irrlicht Engine - User Interface Demo"); device.SetWindowResizable(true); VideoDriver driver = device.VideoDriver; GUIEnvironment env = device.GUIEnvironment; GUISkin skin = env.Skin; GUIFont font = env.GetFont("../../media/fonthaettenschweiler.bmp"); if (font != null) { skin.SetFont(font); } skin.SetFont(env.BuiltInFont, GUIDefaultFont.Tooltip); env.AddButton(new Recti(10, 240, 110, 240 + 32), null, GUI_ID_ButtonQuit, "Quit", "Exits Program"); env.AddButton(new Recti(10, 280, 110, 280 + 32), null, GUI_ID_ButtonWindowNew, "New Window", "Launches a new Window"); env.AddButton(new Recti(10, 320, 110, 320 + 32), null, GUI_ID_ButtonFileOpen, "File Open", "Opens a file"); env.AddStaticText("Transparent Control:", new Recti(150, 20, 350, 40), true); GUIScrollBar scrollbar = env.AddScrollBar(true, new Recti(150, 45, 350, 60), null, GUI_ID_ScrollbarTransparency); scrollbar.MaxValue = 255; scrollbar.Position = (int)env.Skin.GetColor(GUIDefaultColor.WindowBackground).Alpha; GUIStaticText trq = env.AddStaticText("Logging ListBox:", new Recti(50, 110, 250, 130), true); listbox = env.AddListBox(new Recti(50, 140, 250, 210)); env.AddEditBox("Editable Text", new Recti(350, 80, 550, 100)); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); env.AddImage(driver.GetTexture("../../media/irrlichtlogoalpha2.tga"), new Vector2Di(10, 10)); while (device.Run()) { if (device.WindowActive) { driver.BeginScene(true, true, new Color(200, 200, 200)); env.DrawAll(); driver.EndScene(); } } device.Drop(); }