public void run() { // ask user for driver DriverType driverType; // Ask user to select driver: StringBuilder sb = new StringBuilder(); sb.Append("Please select the driver you want for this example:\n"); sb.Append("\n(a) Direct3D 9.0c\n(b) Direct3D 8.1\n(c) OpenGL 1.5"); sb.Append("\n(d) Software Renderer\n(e) Apfelbaum Software Renderer"); sb.Append("\n(f) Null Device\n(otherKey) exit\n\n"); // Get the user's input: TextReader tIn = Console.In; TextWriter tOut = Console.Out; tOut.Write(sb.ToString()); string input = tIn.ReadLine(); // Select device based on user's input: switch (input) { case "a": driverType = DriverType.DIRECT3D9; break; case "b": driverType = DriverType.DIRECT3D8; break; case "c": driverType = DriverType.OPENGL; break; case "d": driverType = DriverType.SOFTWARE; break; case "e": driverType = DriverType.SOFTWARE2; break; case "f": driverType = DriverType.NULL_DRIVER; break; default: return; } // Create device and exit if creation fails: device = new IrrlichtDevice(driverType, new Dimension2D(1024, 768), 32, false, true, true); if (device == null) { tOut.Write("Device creation failed."); return; } /* set this as event receiver*/ device.EventReceiver = this; /* Get a pointer to the video driver and the SceneManager so that we do not always have to write device.VideoDriver and device.SceneManager and device.GUIEnvironment. */ ISceneManager smgr = device.SceneManager; IVideoDriver driver = device.VideoDriver; IGUIEnvironment env = device.GUIEnvironment; /*We add three buttons. The first one closes the engine. The second creates a window and the third opens a file open dialog. The third parameter is the id of the button, with which we can easily identify the button in the event receiver.*/ env.AddButton(new Rect(10, 210, 100, 240), null, 101, "Quit"); env.AddButton(new Rect(10, 250, 100, 290), null, 102, "New Window"); env.AddButton(new Rect(10, 300, 100, 340), null, 103, "File Open"); /*Now, we add a static text and a scrollbar, which modifies the transparency of all gui elements. We set the maximum value of the scrollbar to 255, because that's the maximal value for a color value. Then we create an other static text and a list box.*/ env.AddStaticText("Transparent Control:", new Rect(150, 20, 350, 40), true, false, null, 0); IGUIElement scrollbar = env.AddScrollBar(true, new Rect(150, 45, 350, 60), null, 104); //nopt implemented yet //scrollbar.Max=255; env.AddStaticText("Logging Listbox:", new Rect(50, 80, 250, 100), true, false, null, 0); listbox = env.AddListBox(new Rect(50, 110, 250, 180), null, 0, true); /*To make the font a little bit nicer, we load an external font and set it as new font in the skin. An at last, we create a nice Irrlicht Engine logo in the top left corner. */ IGUISkin skin = env.Skin; IGUIFont font = env.GetFont(path + "fonthaettenschweiler.bmp"); if (font != null) { skin.Font = font; } IGUIElement img = env.AddImage(driver.GetTexture(path + "irrlichtlogoalpha.tga"), new Position2D(10, 10), false, //UseAlphaChannel null, //Parent 0, //ID ""); //Text /* We have done everything, so lets draw it. */ while (device.Run()) { if (device.WindowActive) { device.VideoDriver.BeginScene(true, true, new Color(0, 122, 65, 171)); device.SceneManager.DrawAll(); device.GUIEnvironment.DrawAll(); device.VideoDriver.EndScene(); } } /* In the end, delete the Irrlicht device. */ // Instead of device->drop, we'll use: GC.Collect(); }
public void displayMainMenu() { device = new IrrlichtDevice(DriverType.SOFTWARE, new Dimension2D(512, 384), 16, false, false, false); // set event receiver device.EventReceiver = this; // set text device.WindowCaption = "Irrlicht .NET test demos - main menu"; // load font IGUIFont font = device.GUIEnvironment.GetFont("../../media/fonthaettenschweiler.bmp"); if (font != null) { device.GUIEnvironment.Skin.Font = font; } // add images device.GUIEnvironment.AddImage(device.VideoDriver.GetTexture("../../media/dotnetback.jpg"), new Position2D(0, 0), false, null, -1, ""); // add list box Rect pos = new Rect(150, 60, 350, 135); IGUIListBox box = device.GUIEnvironment.AddListBox(pos, null, -1, true); box.AddItem("Irrlicht Software Renderer 1.0"); box.AddItem("Apfelbaum Software Renderer 1.0"); box.AddItem("Direct3D 8.1"); box.AddItem("Direct3D 9.0c"); box.AddItem("OpenGL 1.5"); box.Selected = ((int)SelectedDriverType) - 1; // add terrain button pos.LowerRightCorner.Y += 50; pos.UpperLeftCorner.Y += 100; device.GUIEnvironment.AddButton(pos, null, (int)TestScenarios.TERRAIN_TEST, "Start Terrain Test"); // add indoor button pos.LowerRightCorner.Y += 30; pos.UpperLeftCorner.Y += 30; device.GUIEnvironment.AddButton(pos, null, (int)TestScenarios.INDOOR_TEST, "Start Indoor Test"); // add windows forms button pos.LowerRightCorner.Y += 30; pos.UpperLeftCorner.Y += 30; device.GUIEnvironment.AddButton(pos, null, (int)TestScenarios.WINDOWS_FORMS_TEST, "Start Windows.Forms Test"); // add shader test button pos.LowerRightCorner.Y += 30; pos.UpperLeftCorner.Y += 30; device.GUIEnvironment.AddButton(pos, null, (int)TestScenarios.SHADER_TEST, "Start Shader Test"); // add copyright stuff IGUIStaticText text = device.GUIEnvironment.AddStaticText( "Background 3D scene created by Alvaro F. Celis, rendered using Irrlicht", new Rect(2, 368, 500, 384), false, false, null, -1); text.OverrideColor = new Color(100, 150, 150, 150); // draw everything while (device.Run() && ClickedButton == TestScenarios.NONE) { if (device.WindowActive) { device.VideoDriver.BeginScene(true, true, new Color(255, 0, 0, 50)); device.SceneManager.DrawAll(); device.GUIEnvironment.DrawAll(); device.VideoDriver.EndScene(); } } device.CloseDevice(); return; }
public void run() { // ask user for driver DriverType driverType; // Ask user to select driver: StringBuilder sb = new StringBuilder(); sb.Append("Please select the driver you want for this example:\n"); sb.Append("\n(a) Direct3D 9.0c\n(b) Direct3D 8.1\n(c) OpenGL 1.5"); sb.Append("\n(d) Software Renderer\n(e) Apfelbaum Software Renderer"); sb.Append("\n(f) Null Device\n(otherKey) exit\n\n"); // Get the user's input: TextReader tIn = Console.In; TextWriter tOut = Console.Out; tOut.Write(sb.ToString()); string input = tIn.ReadLine(); // Select device based on user's input: switch (input) { case "a": driverType = DriverType.DIRECT3D9; break; case "b": driverType = DriverType.DIRECT3D8; break; case "c": driverType = DriverType.OPENGL; break; case "d": driverType = DriverType.SOFTWARE; break; case "e": driverType = DriverType.SOFTWARE2; break; case "f": driverType = DriverType.NULL_DRIVER; break; default: return; } // Create device and exit if creation fails: device = new IrrlichtDevice(driverType, new Dimension2D(1024, 768), 32, false, true, true); if (device == null) { tOut.Write("Device creation failed."); return; } /* set this as event receiver*/ device.EventReceiver = this; /* * Get a pointer to the video driver and the SceneManager so that * we do not always have to write device.VideoDriver and * device.SceneManager and device.GUIEnvironment. */ ISceneManager smgr = device.SceneManager; IVideoDriver driver = device.VideoDriver; IGUIEnvironment env = device.GUIEnvironment; /*We add three buttons. The first one closes the engine. The second creates * a window and the third opens a file open dialog. The third parameter is * the id of the button, with which we can easily identify the button in the * event receiver.*/ env.AddButton(new Rect(10, 210, 100, 240), null, 101, "Quit"); env.AddButton(new Rect(10, 250, 100, 290), null, 102, "New Window"); env.AddButton(new Rect(10, 300, 100, 340), null, 103, "File Open"); /*Now, we add a static text and a scrollbar, which modifies the transparency * of all gui elements. We set the maximum value of the scrollbar to 255, * because that's the maximal value for a color value. Then we create an other * static text and a list box.*/ env.AddStaticText("Transparent Control:", new Rect(150, 20, 350, 40), true, false, null, 0); IGUIElement scrollbar = env.AddScrollBar(true, new Rect(150, 45, 350, 60), null, 104); //nopt implemented yet //scrollbar.Max=255; env.AddStaticText("Logging Listbox:", new Rect(50, 80, 250, 100), true, false, null, 0); listbox = env.AddListBox(new Rect(50, 110, 250, 180), null, 0, true); /*To make the font a little bit nicer, we load an external font and set it as * new font in the skin. An at last, we create a nice Irrlicht Engine logo in the * top left corner. */ IGUISkin skin = env.Skin; IGUIFont font = env.GetFont(path + "fonthaettenschweiler.bmp"); if (font != null) { skin.Font = font; } IGUIElement img = env.AddImage(driver.GetTexture(path + "irrlichtlogoalpha.tga"), new Position2D(10, 10), false, //UseAlphaChannel null, //Parent 0, //ID ""); //Text /* * We have done everything, so lets draw it. */ while (device.Run()) { if (device.WindowActive) { device.VideoDriver.BeginScene(true, true, new Color(0, 122, 65, 171)); device.SceneManager.DrawAll(); device.GUIEnvironment.DrawAll(); device.VideoDriver.EndScene(); } } /* * In the end, delete the Irrlicht device. */ // Instead of device->drop, we'll use: GC.Collect(); }