static void drawTextureManagerActivity() { if (selectedNode != null) { return; } if (tasksAddedToTextureManager == 0) { return; } int l = textureManager.GetCommandQueueLength(); if (l == 0) { tasksAddedToTextureManager = 0; return; } VideoDriver v = irr.Driver; float p = (tasksAddedToTextureManager - l) / (float)tasksAddedToTextureManager; if (p > 1) { p = 1; } Recti r = new Recti(v.ScreenSize.Width - 140, 20, v.ScreenSize.Width - 24, 30); v.Draw2DRectangleOutline(r, new Color(0x88446699)); r.LowerRightCorner = new Vector2Di(r.UpperLeftCorner.X + (int)(r.Width * p), r.LowerRightCorner.Y); v.Draw2DRectangle(r, new Color(0x88446699)); }
static void drawScrollPosition() { if (selectedNode != null) { return; } if (maxScrollPosition < 1) { return; } VideoDriver v = irr.Driver; if (v.ScreenSize.Height < 200) { return; } float p = irr.Scene.ActiveCamera.Position.Z / maxScrollPosition; v.Draw2DLine(v.ScreenSize.Width - 26, 80, v.ScreenSize.Width - 26, v.ScreenSize.Height - 80, new Color(0x88446699)); float y = (v.ScreenSize.Height - 80 - 80 - 40) * (1.0f - p); Recti r = new Recti(v.ScreenSize.Width - 29, (int)y + 80, v.ScreenSize.Width - 22, (int)y + 80 + 40); v.Draw2DRectangle(r, new Color(0x88446699)); }
static void drawPreviewPlateTooltip() { if (hoveredNode == null || !hoveredNode.Visible) { return; } int k = hoveredNode.ID; Texture t = hoveredNode.GetMaterial(0).GetTexture(0); if (t != null && t.Name.Path != "NoPreviewTexture") { k = hoveredNode.ID & (0xFFFFFFF ^ SelectableNodeIdFlag); } string s = previewPlateInfo.ContainsKey(k) ? previewPlateInfo[k] : "???"; if (s != null) { Vector2Di p = irr.Device.CursorControl.Position + new Vector2Di(16); GUIFont f = irr.GUI.Skin.GetFont(GUIDefaultFont.Default); Dimension2Di d = f.GetDimension(s); d.Inflate(16, 12); Recti r = new Recti(p, d); VideoDriver v = irr.Driver; int ax = r.LowerRightCorner.X - v.ScreenSize.Width; int ay = r.LowerRightCorner.Y - v.ScreenSize.Height; if (ax > 0 || ay > 0) { if (ax < 0) { ax = 0; } if (ay < 0) { ay = 0; } r.Offset(-ax, -ay); } v.Draw2DRectangle(r, new Color(0xbb223355)); v.Draw2DRectangleOutline(r, new Color(0xbb445577)); f.Draw(s, r.UpperLeftCorner + new Vector2Di(8, 6), Color.SolidYellow); } }
static void Main(string[] args) { device = IrrlichtDevice.CreateDevice(DriverType.Direct3D8, new Dimension2Di(1024, 768)); if (device == null) { return; } device.SetWindowCaption("Fractal Generator - Irrlicht Engine"); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; GUIFont font = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); Color fontBackgroundColor = new Color(0x7f000000); Color fontNormalColor = Color.OpaqueWhite; Color fontActionColor = Color.OpaqueYellow; fGen = new FractalGenerator(device); fGen.Generate(new Rectd( -driver.ScreenSize.Width / 250.0, -driver.ScreenSize.Height / 250.0, driver.ScreenSize.Width / 250.0, driver.ScreenSize.Height / 250.0)); while (device.Run()) { driver.BeginScene(false); Vector2Di o = null; if (mouseMoveStart != null) { o = device.CursorControl.Position - mouseMoveStart; } float w = fGen.DrawAll(o); // draw stats driver.Draw2DRectangle(new Recti(10, 10, 160, 56 + (w < 1 ? 16 : 0)), fontBackgroundColor); Vector2Di v = new Vector2Di(20, 16); font.Draw("Max iterations: " + fGen.GetMaxIterations(), v, fontNormalColor); v.Y += 16; font.Draw("Zoom: " + (long)fGen.GetZoomFactor().X + "x", v, fontNormalColor); if (w < 1) { v.Y += 16; font.Draw("Computing: " + (int)(w * 100) + "%...", v, fontActionColor); } // draw help int h = driver.ScreenSize.Height; driver.Draw2DRectangle(new Recti(10, showHelp ? h - 130 : h - 40, showHelp ? 220 : 160, h - 10), fontBackgroundColor); v.Y = h - 34; font.Draw("[F1] " + (showHelp ? "Hide" : "Show") + " help", v, fontNormalColor); if (showHelp) { v.Y = h - 124; font.Draw("[Mouse Left Button] Navigate", v, fontNormalColor); v.Y += 16; font.Draw("[Mouse Wheel] Zoom in/out", v, fontNormalColor); v.Y += 16; font.Draw("[+][-][*][/] Max iterations", v, fontNormalColor); v.Y += 16; font.Draw("[PrintScreen] Save screenshot", v, fontNormalColor); v.Y += 16; font.Draw("[Esc] Exit application", v, fontNormalColor); } driver.EndScene(); device.Yield(); } fGen.Drop(); device.Drop(); }
static void Main(string[] args) { DriverType driverType; if (!AskUserForDriver(out driverType)) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(512, 384)); if (device == null) { return; } device.SetWindowCaption("Irrlicht Engine - 2D Graphics Demo"); VideoDriver driver = device.VideoDriver; Texture images = driver.GetTexture("../../media/2ddemo.png"); driver.MakeColorKeyTexture(images, new Vector2Di(0, 0)); GUIFont font = device.GUIEnvironment.BuiltInFont; GUIFont font2 = device.GUIEnvironment.GetFont("../../media/fonthaettenschweiler.bmp"); Recti imp1 = new Recti(349, 15, 385, 78); Recti imp2 = new Recti(387, 15, 423, 78); driver.Material2D.Layer[0].BilinearFilter = true; driver.Material2D.AntiAliasing = AntiAliasingMode.FullBasic; while (device.Run()) { if (device.WindowActive) { int time = (int)device.Timer.Time; driver.BeginScene(true, true, new Color(120, 102, 136)); // draw fire & dragons background world driver.Draw2DImage(images, new Vector2Di(50, 50), new Recti(0, 0, 342, 224), null, new Color(255, 255, 255), true); // draw flying imp driver.Draw2DImage(images, new Vector2Di(164, 125), (time / 500 % 2) == 1 ? imp1 : imp2, null, new Color(255, 255, 255), true); // draw second flying imp with colorcylce driver.Draw2DImage(images, new Vector2Di(270, 105), (time / 500 % 2) == 1 ? imp1 : imp2, null, new Color(time % 255, 255, 255), true); // draw some text if (font != null) { font.Draw("This demo shows that Irrlicht is also capable of drawing 2D graphics.", 130, 10, new Color(255, 255, 255)); } // draw some other text if (font2 != null) { font2.Draw("Also mixing with 3d graphics is possible.", 130, 20, new Color(time % 255, time % 255, 255)); } driver.EnableMaterial2D(); driver.Draw2DImage(images, new Recti(10, 10, 108, 48), new Recti(354, 87, 442, 118)); driver.EnableMaterial2D(false); Vector2Di m = device.CursorControl.Position; driver.Draw2DRectangle(new Recti(m.X - 20, m.Y - 20, m.X + 20, m.Y + 20), new Color(255, 255, 255, 100)); driver.EndScene(); } } device.Drop(); }
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; IrrlichtCreationParameters p = new IrrlichtCreationParameters(); p.DriverType = DriverType.Direct3D9; p.WindowID = (IntPtr)e.Argument; IrrlichtDevice device = IrrlichtDevice.CreateDevice(p); if (device == null) { // if device cannot be created by any reason - we just leave this thread, // after all IsRedering will report false, so it is all OK. return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; // setup a simple 3d scene CameraSceneNode cam = smgr.AddCameraSceneNode(); cam.Target = new Vector3Df(0); SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 15, 0), 30.0f); cam.AddAnimator(anim); anim.Drop(); SceneNode cube = smgr.AddCubeSceneNode(20); cube.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp")); cube.SetMaterialTexture(1, driver.GetTexture("../../media/water.jpg")); cube.SetMaterialFlag(MaterialFlag.Lighting, false); cube.SetMaterialType(MaterialType.Reflection2Layer); smgr.AddSkyBoxSceneNode( "../../media/irrlicht2_up.jpg", "../../media/irrlicht2_dn.jpg", "../../media/irrlicht2_lf.jpg", "../../media/irrlicht2_rt.jpg", "../../media/irrlicht2_ft.jpg", "../../media/irrlicht2_bk.jpg"); gui.AddImage( driver.GetTexture("../../media/lime_logo_alpha.png"), new Vector2Di(30, 0)); // draw all while (device.Run()) { driver.BeginScene(false); smgr.DrawAll(); gui.DrawAll(); // draw stats int x = 20; int y = driver.ScreenSize.Height - 50; driver.Draw2DRectangle( new Recti(x, y, x + driver.ScreenSize.Width - 2 * x, y + 30), new IrrlichtLime.Video.Color(0, 0, 0, 128)); device.GUIEnvironment.BuiltInFont.Draw( "Driver: " + driver.Name, new Vector2Di(x + 5, y + 5), new IrrlichtLime.Video.Color(255, 255, 255)); device.GUIEnvironment.BuiltInFont.Draw( "FPS: " + driver.FPS.ToString(), new Vector2Di(x + 5, y + 15), new IrrlichtLime.Video.Color(255, 255, 255)); driver.EndScene(); // check for cancellation if (worker.CancellationPending) { device.Close(); } // check for new command lock (backgroundCommand) { switch (backgroundCommand.Type) { case Command.Kind.Resized: driver.ResizeNotify(backgroundCommand.Value as Dimension2Di); backgroundCommand.Clear(); break; } } } // drop the device device.Drop(); }
static void Main(string[] args) { checkBulletSharpDllPresence(); // setup Irrlicht device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1024, 768)); if (device == null) { return; } 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(true, true, 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.OpaqueYellow); v.Y += 16; font.Draw(scene.Attributes.GetValue("calls") + " nodes", v, Color.OpaqueWhite); v.Y += 16; font.Draw(driver.FPS + " fps", v, Color.OpaqueWhite); v.Y += 16; font.Draw("[T]rails " + (useTrails ? "ON" : "OFF"), v, Color.OpaqueGreen); v.Y += 32; font.Draw("Physics" + (simPaused ? " (paused)" : ""), v, Color.OpaqueYellow); v.Y += 16; font.Draw(physics.NumCollisionObjects + " shapes", v, Color.OpaqueWhite); v.Y += 16; font.Draw(simFps + " fps", v, Color.OpaqueWhite); v.Y += 16; font.Draw("[Space] to pause", v, Color.OpaqueGreen); driver.EndScene(); } device.Yield(); } // drop physics.Drop(); device.Drop(); }
static void Main() { // setup Irrlicht device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(1024, 768), 32, false, true); if (device == null) { return; } device.SetWindowCaption("Stencil Shadows - Irrlicht Engine"); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; GUIFont statsFont = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); cameraNode = scene.AddCameraSceneNodeFPS(); cameraNode.FarValue = 20000; device.CursorControl.Visible = false; // setup shadows shadows = new Shadows(new Color(0xa0000000), 4000); // load quake level device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); Mesh m = scene.GetMesh("20kdm2.bsp").GetMesh(0); MeshSceneNode n = scene.AddOctreeSceneNode(m, null, -1, 1024); n.Position = new Vector3Df(-1300, -144, -1249); quakeLevelNode = n; // add faerie faerieNode = scene.AddAnimatedMeshSceneNode( scene.GetMesh("../../media/faerie.md2"), null, -1, new Vector3Df(100, -40, 80), new Vector3Df(0, 30, 0), new Vector3Df(1.6f)); faerieNode.SetMD2Animation(AnimationTypeMD2.Wave); faerieNode.AnimationSpeed = 20; faerieNode.GetMaterial(0).SetTexture(0, driver.GetTexture("../../media/faerie2.bmp")); faerieNode.GetMaterial(0).Lighting = false; faerieNode.GetMaterial(0).NormalizeNormals = true; shadows.AddObject(faerieNode); // add light lightMovementHelperNode = scene.AddEmptySceneNode(); n = scene.AddSphereSceneNode(2, 6, lightMovementHelperNode, -1, new Vector3Df(15, -10, 15)); n.SetMaterialFlag(MaterialFlag.Lighting, false); lightNode = n; shadows.AddLight(lightNode); // add flashlight m = scene.GetMesh("../../media/flashlight.obj"); n = scene.AddMeshSceneNode(m, lightNode, -1, new Vector3Df(0), new Vector3Df(0), new Vector3Df(5)); n.SetMaterialFlag(MaterialFlag.Lighting, false); flashlightNode = n; flashlightNode.Visible = false; // render uint shdFrameTime = 0; uint shdFrames = 0; uint shdFps = 0; while (device.Run()) { if (useShadowsRebuilding && shadows.BuildShadowVolume()) { shdFrames++; } uint t = device.Timer.Time; if (t - shdFrameTime > 1000) { shdFrameTime = t; shdFps = shdFrames; shdFrames = 0; } if (useLightBinding) { lightMovementHelperNode.Position = cameraNode.AbsolutePosition.GetInterpolated(lightMovementHelperNode.Position, 0.1); lightMovementHelperNode.Rotation = cameraNode.AbsoluteTransformation.Rotation; } driver.BeginScene(ClearBufferFlag.All, new Color(0xff112244)); scene.DrawAll(); if (useShadowsRendering) { shadows.DrawShadowVolume(driver); } // display stats driver.Draw2DRectangle(new Recti(10, 10, 150, 220), new Color(0x7f000000)); Vector2Di v = new Vector2Di(20, 20); statsFont.Draw("Rendering", v, Color.SolidYellow); v.Y += 16; statsFont.Draw(driver.FPS + " fps", v, Color.SolidWhite); v.Y += 16; statsFont.Draw("[S]hadows " + (useShadowsRendering ? "ON" : "OFF"), v, Color.SolidGreen); v.Y += 16; statsFont.Draw("[L]ight binding " + (useLightBinding ? "ON" : "OFF"), v, Color.SolidGreen); v.Y += 16; statsFont.Draw("[F]lashlight " + (useFlashlight ? "ON" : "OFF"), v, Color.SolidGreen); v.Y += 32; statsFont.Draw("Shadows", v, Color.SolidYellow); v.Y += 16; statsFont.Draw(shdFps + " fps", v, Color.SolidWhite); v.Y += 16; statsFont.Draw(shadows.VerticesBuilt + " vertices", v, Color.SolidWhite); v.Y += 16; statsFont.Draw("[R]ebuilding " + (useShadowsRebuilding ? "ON" : "OFF"), v, Color.SolidGreen); v.Y += 16; statsFont.Draw("[Q]uake level " + (useShadowsQuakeLevel ? "ON" : "OFF"), v, Color.SolidGreen); driver.EndScene(); } shadows.Drop(); device.Drop(); }