Exemplo n.º 1
0
        private void initGUI(int size)
        {
            GUIEnvironment gui = device.GUIEnvironment;
            VideoDriver    drv = gui.VideoDriver;

            gui.Clear();

            gui.AddImage(
                drv.GetTexture("../../media/lime_logo_alpha.png"),
                new Vector2Di(30, 0));

            guiWindow = gui.AddWindow(new Recti(20, 120, size + 20 + 20, size + 120 + 20 + 20 + 30), false, "Paint");

            guiSize128 = gui.AddButton(new Recti(10, 30, 40, 30 + 20), guiWindow, -1, "128");
            guiSize256 = gui.AddButton(new Recti(50, 30, 80, 30 + 20), guiWindow, -1, "256");
            guiSize512 = gui.AddButton(new Recti(90, 30, 120, 30 + 20), guiWindow, -1, "512");

            guiImage  = gui.AddImage(new Recti(10, 30 + 30, size + 10 - 1, size + 30 - 1 + 30), true, guiWindow);
            gui.Focus = guiImage;
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        static void Main()
        {
            DriverType?driverType = AskForDriver();

            if (!driverType.HasValue)
            {
                return;
            }

            IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480));

            if (device == null)
            {
                return;
            }

            VideoDriver    driver = device.VideoDriver;
            SceneManager   smgr   = device.SceneManager;
            GUIEnvironment env    = device.GUIEnvironment;

            driver.SetTextureCreationFlag(TextureCreationFlag.Always32Bit, true);

            // add irrlicht logo
            env.AddImage(driver.GetTexture("../../media/irrlichtlogoalpha2.tga"), new Vector2Di(10));

            // add camera
            CameraSceneNode camera = smgr.AddCameraSceneNodeFPS();

            camera.Position = new Vector3Df(-200, 200, -200);

            // disable mouse cursor
            device.CursorControl.Visible = false;

            driver.Fog = new Fog(new Color(138, 125, 81, 0), FogType.Linear, 250, 1000, 0.003f, true, false);

            AnimatedMesh roomMesh = smgr.GetMesh("../../media/room.3ds");
            SceneNode    room     = null;
            SceneNode    earth    = null;

            if (roomMesh != null)
            {
                // the room mesh doesn't have proper texture mapping on the floor,
                // so we can recreate them on runtime
                smgr.MeshManipulator.MakePlanarTextureMapping(roomMesh.GetMesh(0), 0.003f);

                Texture normalMap = driver.GetTexture("../../media/rockwall_height.bmp");
                if (normalMap != null)
                {
                    driver.MakeNormalMapTexture(normalMap, 9.0f);
                }

                Mesh tangentMesh = smgr.MeshManipulator.CreateMeshWithTangents(roomMesh.GetMesh(0));
                room = smgr.AddMeshSceneNode(tangentMesh);
                room.SetMaterialTexture(0, driver.GetTexture("../../media/rockwall.jpg"));
                room.SetMaterialTexture(1, normalMap);
                room.GetMaterial(0).SpecularColor = new Color(0);
                room.GetMaterial(0).Shininess     = 0.0f;
                room.SetMaterialFlag(MaterialFlag.Fog, true);
                room.SetMaterialType(MaterialType.ParallaxMapSolid);
                room.GetMaterial(0).MaterialTypeParam = 1.0f / 64.0f; // adjust height for parallax effect

                tangentMesh.Drop();                                   // drop mesh because we created it with a "create" call
            }

            // add earth sphere
            AnimatedMesh earthMesh = smgr.GetMesh("../../media/earth.x");

            if (earthMesh != null)
            {
                // perform various task with the mesh manipulator
                MeshManipulator manipulator = smgr.MeshManipulator;

                // create mesh copy with tangent informations from original earth.x mesh
                Mesh tangentSphereMesh = manipulator.CreateMeshWithTangents(earthMesh.GetMesh(0));

                // set the alpha value of all vertices to 200
                manipulator.SetVertexColorAlpha(tangentSphereMesh, 200);

                // scale the mesh by factor 50
                Matrix m = new Matrix();
                m.Scale = new Vector3Df(50);
                manipulator.Transform(tangentSphereMesh, m);

                earth          = smgr.AddMeshSceneNode(tangentSphereMesh);
                earth.Position = new Vector3Df(-70, 130, 45);

                // load heightmap, create normal map from it and set it
                Texture earthNormalMap = driver.GetTexture("../../media/earthbump.jpg");
                if (earthNormalMap != null)
                {
                    driver.MakeNormalMapTexture(earthNormalMap, 20);
                    earth.SetMaterialTexture(1, earthNormalMap);
                    earth.SetMaterialType(MaterialType.NormalMapTransparentVertexAlpha);
                }

                // adjust material settings
                earth.SetMaterialFlag(MaterialFlag.Fog, true);

                // add rotation animator
                SceneNodeAnimator anim = smgr.CreateRotationAnimator(new Vector3Df(0, 0.1f, 0));
                earth.AddAnimator(anim);
                anim.Drop();

                // drop mesh because we created it with a "create" call.
                tangentSphereMesh.Drop();
            }

            // add light 1 (more green)
            LightSceneNode light1 = smgr.AddLightSceneNode(null, new Vector3Df(), new Colorf(0.5f, 1.0f, 0.5f, 0.0f), 800);

            if (light1 != null)
            {
                light1.DebugDataVisible = DebugSceneType.BBox;

                // add fly circle animator to light
                SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(50, 300, 0), 190.0f, -0.003f);
                light1.AddAnimator(anim);
                anim.Drop();

                // attach billboard to the light
                BillboardSceneNode bill = smgr.AddBillboardSceneNode(light1, new Dimension2Df(60, 60));
                bill.SetMaterialFlag(MaterialFlag.Lighting, false);
                bill.SetMaterialFlag(MaterialFlag.ZWrite, false);
                bill.SetMaterialType(MaterialType.TransparentAddColor);
                bill.SetMaterialTexture(0, driver.GetTexture("../../media/particlegreen.jpg"));
            }

            // add light 2 (red)
            SceneNode light2 = smgr.AddLightSceneNode(null, new Vector3Df(), new Colorf(1.0f, 0.2f, 0.2f, 0.0f), 800.0f);

            if (light2 != null)
            {
                // add fly circle animator to light
                SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 150, 0), 200.0f, 0.001f, new Vector3Df(0.2f, 0.9f, 0.0f));
                light2.AddAnimator(anim);
                anim.Drop();

                // attach billboard to light
                SceneNode bill = smgr.AddBillboardSceneNode(light2, new Dimension2Df(120, 120));
                bill.SetMaterialFlag(MaterialFlag.Lighting, false);
                bill.SetMaterialFlag(MaterialFlag.ZWrite, false);
                bill.SetMaterialType(MaterialType.TransparentAddColor);
                bill.SetMaterialTexture(0, driver.GetTexture("../../media/particlered.bmp"));

                // add particle system
                ParticleSystemSceneNode ps = smgr.AddParticleSystemSceneNode(false, light2);

                // create and set emitter
                ParticleEmitter em = ps.CreateBoxEmitter(
                    new AABBox(-3, 0, -3, 3, 1, 3),
                    new Vector3Df(0.0f, 0.03f, 0.0f),
                    80, 100,
                    new Color(255, 255, 255, 10), new Color(255, 255, 255, 10),
                    400, 1100);

                em.MinStartSize = new Dimension2Df(30.0f, 40.0f);
                em.MaxStartSize = new Dimension2Df(30.0f, 40.0f);

                ps.Emitter = em;
                em.Drop();

                // create and set affector
                ParticleAffector paf = ps.CreateFadeOutParticleAffector();
                ps.AddAffector(paf);
                paf.Drop();

                // adjust some material settings
                ps.SetMaterialFlag(MaterialFlag.Lighting, false);
                ps.SetMaterialFlag(MaterialFlag.ZWrite, false);
                ps.SetMaterialTexture(0, driver.GetTexture("../../media/fireball.bmp"));
                ps.SetMaterialType(MaterialType.TransparentAddColor);
            }

            MyEventReceiver receiver = new MyEventReceiver(device, room, earth);

            int lastFPS = -1;

            while (device.Run())
            {
                if (device.WindowActive)
                {
                    driver.BeginScene(ClearBufferFlag.All, new Color(0));

                    smgr.DrawAll();
                    env.DrawAll();

                    driver.EndScene();

                    int fps = driver.FPS;
                    if (lastFPS != fps)
                    {
                        device.SetWindowCaption(String.Format(
                                                    "Per pixel lighting example - Irrlicht Engine [{0}] fps: {1}",
                                                    driver.Name, fps));

                        lastFPS = fps;
                    }
                }
            }

            device.Drop();
        }
Exemplo n.º 5
0
        static void Main()
        {
            DriverType?driverType = AskForDriver();

            if (!driverType.HasValue)
            {
                return;
            }

            IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480));

            if (device == null)
            {
                return;
            }

            VideoDriver    driver = device.VideoDriver;
            SceneManager   smgr   = device.SceneManager;
            GUIEnvironment env    = device.GUIEnvironment;

            driver.SetTextureCreationFlag(TextureCreationFlag.Always32Bit, true);

            // add irrlicht logo
            env.AddImage(driver.GetTexture("../../media/irrlichtlogoalpha2.tga"), new Vector2Di(10));

            // set gui font
            env.Skin.SetFont(env.GetFont("../../media/fontlucida.png"));

            // add some help text
            env.AddStaticText(
                "Press 'W' to change wireframe mode\nPress 'D' to toggle detail map\nPress 'S' to toggle skybox/skydome",
                new Recti(10, 421, 250, 475), true, true, null, -1, true);

            // add camera
            CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(null, 100.0f, 1.2f);

            camera.Position = new Vector3Df(2700 * 2, 255 * 2, 2600 * 2);
            camera.Target   = new Vector3Df(2397 * 2, 343 * 2, 2700 * 2);
            camera.FarValue = 42000.0f;

            // disable mouse cursor
            device.CursorControl.Visible = false;

            // add terrain scene node
            TerrainSceneNode terrain = smgr.AddTerrainSceneNode(
                "../../media/terrain-heightmap.bmp",                    // heightmap
                null,                                                   // parent node
                -1,                                                     // node id
                new Vector3Df(),                                        // position
                new Vector3Df(),                                        // rotation
                new Vector3Df(40, 4.4f, 40),                            // scale
                new Color(255, 255, 255),                               // vertex color
                5,                                                      // max LOD
                TerrainPatchSize._17,                                   // patch size
                4);                                                     // smooth factor

            terrain.SetMaterialFlag(MaterialFlag.Lighting, false);
            terrain.SetMaterialTexture(0, driver.GetTexture("../../media/terrain-texture.jpg"));
            terrain.SetMaterialTexture(1, driver.GetTexture("../../media/detailmap3.jpg"));
            terrain.SetMaterialType(MaterialType.DetailMap);

            terrain.ScaleTexture(1, 20);

            // create triangle selector for the terrain
            TriangleSelector selector = smgr.CreateTerrainTriangleSelector(terrain, 0);

            terrain.TriangleSelector = selector;

            // create collision response animator and attach it to the camera
            SceneNodeAnimator anim = smgr.CreateCollisionResponseAnimator(
                selector, camera,
                new Vector3Df(60, 100, 60),
                new Vector3Df(0, 0, 0),
                new Vector3Df(0, 50, 0));

            selector.Drop();
            camera.AddAnimator(anim);
            anim.Drop();

            // create skybox and skydome
            driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, false);

            SceneNode skybox = 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");

            SceneNode skydome = smgr.AddSkyDomeSceneNode(driver.GetTexture("../../media/skydome.jpg"), 16, 8, 0.95f, 2);

            driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, true);

            // create event receiver
            new MyEventReceiver(device, terrain, skybox, skydome);

            int lastFPS = -1;

            while (device.Run())
            {
                if (device.WindowActive)
                {
                    driver.BeginScene(ClearBufferFlag.All, new Color(0));

                    smgr.DrawAll();
                    env.DrawAll();

                    driver.EndScene();

                    // display frames per second in window title
                    int fps = driver.FPS;
                    if (lastFPS != fps)
                    {
                        // also print terrain height of current camera position
                        // we can use camera position because terrain is located at coordinate origin

                        device.SetWindowCaption(String.Format(
                                                    "Terrain rendering example - Irrlicht Engine [{0}] fps: {1} Height: {2}",
                                                    driver.Name, fps, terrain.GetHeight(camera.AbsolutePosition.X, camera.AbsolutePosition.Z)));

                        lastFPS = fps;
                    }
                }
            }

            device.Drop();
        }
Exemplo n.º 6
0
        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();
        }