SetActive() public method

Activate of deactivate the window as the current target for rendering
public SetActive ( bool active ) : bool
active bool True to activate, false to deactivate (true by default)
return bool
Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            var contextSettings = new ContextSettings {
                DepthBits = 32
            };
            var window = new RenderWindow(new VideoMode(640, 480), "JukeSaver spike: SFML Basic", Styles.Default, contextSettings);
            window.SetActive();

            window.Closed += OnClosed;
            window.KeyPressed += OnKeyPressed;

            int r = 0, g = 0, b = 0;
            var shape = new CircleShape() {
                Position = new Vector2f(320, 240),
            };

            while (window.IsOpen()) {
                window.DispatchEvents();
                window.Clear(new Color((byte)r, (byte)g, (byte)b));

                shape.Radius = (float)(80.0 + GetPulse() * 40.0);
                shape.Origin = new Vector2f(shape.Radius * 0.5f, shape.Radius * 0.5f);
                shape.Position = new Vector2f(320 - shape.Radius * 0.5f, 240 - shape.Radius * 0.5f);

                shape.FillColor = new Color(50, (byte)(160 + 80 * GetPulse()), (byte)(40 - (40 * GetPulse())));

                window.Draw(shape);
                window.Display();
            }
        }
Ejemplo n.º 2
0
        private static void InitializeWindow()
        {
            Window = new RenderWindow(new VideoMode(1600, 900, 32), "Planet Simulation", Styles.Default);
            //window.SetVerticalSyncEnabled(true);
            Window.SetActive(false);
            Window.SetVisible(true);

            Window.Closed += WindowClosedEvent;
        }
Ejemplo n.º 3
0
        public static void InitializeGameLoop(/*Insert arguments here*/)
        {
            //Insert initialization here:
            window = new RenderWindow(new VideoMode(800, 600), "test");
            window.SetActive();
            SpriteManager.Initialize();
            SpriteManager.CreateCircle();

            MainLoop();
        }
Ejemplo n.º 4
0
        public WindowManager()
        {
            //Init main window shit
            window = new RenderWindow(new VideoMode(640, 480), "Super cool window title!");
            window.SetVerticalSyncEnabled(true);
            window.SetActive(true);
            window.Closed += window_Closed;

            // Open gl
            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glLoadIdentity();
            Gl.glOrtho(0, 640, 480, 0, 0, 1);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);

            Gl.glDisable(Gl.GL_DEPTH_TEST);

            Gl.glLoadIdentity();
            Gl.glTranslatef(0.375f, 0.375f, 0);

            particles = new CircleShape[pcount];
            for (int i = 0; i < pcount; i++)
            {
                particles[i] = new CircleShape(4f);
                particles[i].FillColor = Color.White;
                particles[i].Position = new Vector2f(0, 0);
                particles[i].Radius = 4;
            }

            circletest = new CircleShape();
            circletest.Position = new Vector2f(100, 100);
            circletest.OutlineColor = Color.Red;
            circletest.OutlineThickness = 1;
            circletest.FillColor = Color.Black;
            circletest.Radius = 100;

            circletest2 = new CircleShape();
            circletest2.Position = new Vector2f(200, 300);
            circletest2.OutlineColor = Color.Red;
            circletest2.OutlineThickness = 1;
            circletest2.FillColor = Color.Black;
            circletest2.Radius = 100;

            mytext = new Text("test", new Font("arial.ttf"), 16);
            mytext.Position = new Vector2f(4, 4);
            mytext.Color = Color.White;
            mytext.Style = Text.Styles.Bold;

            mytextShadow = new Text("test", new Font("arial.ttf"), 16);
            mytextShadow.Position = new Vector2f(6, 6);
            mytextShadow.Color = Color.Black;

            sim = new Simulation();
            sim.InitSimulation(pcount);
        }
Ejemplo n.º 5
0
        public static void Main()
        {
            #region Initialize Variables
            window = new RenderWindow(new VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Reflexes For Friends", Styles.Default, new ContextSettings(32, 0));
            timer = new Stopwatch();
            world = new GameWorld(new Texture("resources/background-grass.png"));
            player = new Player(new Texture("resources/player.png"));
            friend = new Friend(new Texture("resources/friend.png"));
            enemies = new List<Enemy>();
            gameOver = false;
            #endregion

            #region Register Event Handlers
            window.Closed += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.KeyReleased += new EventHandler<KeyEventArgs>(OnKeyReleased);
            #endregion

            #region Setup Modules
            keyboardModule = new KeyboardModule();
            #endregion

            RegisterKeyBindings();
            GenerateEnemies();

            timer.Start();
            long timeSinceLastUpdate = 0;

            window.SetVerticalSyncEnabled(true);
            window.SetActive();
            while (window.IsOpen())
            {
                window.DispatchEvents();

                if (!gameOver)
                {
                    timeSinceLastUpdate += timer.ElapsedMilliseconds;
                    timer.Restart();
                    if (timeSinceLastUpdate >= UPDATE_FREQUENCY_IN_MS)
                    {
                        UpdateGame(UPDATE_FREQUENCY_IN_MS);

                        timeSinceLastUpdate -= UPDATE_FREQUENCY_IN_MS;
                    }
                }

                DrawGame();
                window.Display();
            }
            timer.Stop();
        }
Ejemplo n.º 6
0
 public static void Start()
 {
     pixels = new List<Pixel>();
     window = new RenderWindow(new VideoMode((uint)Width,(uint)Height), "I Am Goc");
     window.SetFramerateLimit(120);
     Load();
     window.MouseMoved += setMousePos;
     while (window.IsOpen()){
         window.SetActive();
         window.DispatchEvents();
         Update();
         window.Display();
         Count++;
     }
 }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            var videoMode = new VideoMode(1000, 700);
            var contextSettings = new ContextSettings(0, 0, 4);
            RenderWindow window = new RenderWindow(videoMode, "Luda Diaria", Styles.Default, contextSettings);
            window.SetActive(true);
            window.Closed += (sender, e) => window.Close();
            Global.Window = window;

            Randomizer.Generator = new Random(42);

            var input = InputManager.Instance;
            input.Init();

            StateManager.Instance.CurrentState = new LoadingState();

            var lastTick = DateTime.Now;
            const float maxTimeStep = 0.5f;

            while (window.IsOpen())
            {
                float dt = (float)((DateTime.Now - lastTick).TotalSeconds);
                lastTick = DateTime.Now;

                window.DispatchEvents();
                window.Clear(Color.Black);

                if (input.IsKeyPressed(Keyboard.Key.Escape))
                {
                    window.Close();
                }

                while (dt > 0)
                {
                    //---UPDATE
                    var deltatTime = dt < maxTimeStep ? dt : maxTimeStep;
                    StateManager.Instance.CurrentState.Update(deltatTime);
                    dt -= maxTimeStep;
                }
                //---DRAW

                StateManager.Instance.CurrentState.Draw(window, RenderStates.Default);
                window.Display();
            }
        }
Ejemplo n.º 8
0
        private static void Main(string[] args)
        {
            var contextSettings = new ContextSettings { DepthBits = 32 };
            var window = new RenderWindow(new VideoMode(640, 480), "SFML.Net starter kit", Styles.Default, contextSettings);
            window.SetActive();

            window.Closed += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);

            int r=0,g=0,b=0;
            
            while (window.IsOpen())
            {
                window.DispatchEvents();                
                window.Clear(new Color((byte)r, (byte)g, (byte)b));
                window.Display();
            }
        }
        public FboTest()
        {
            Text = new Text("", new Font("lekton.ttf"), 20)
            {
                Color=Color.White,
                Position = new Vector2f(10,10),
            };

            textureOne = new SFML.Graphics.RenderTexture(32,32);
            textureTwo = new SFML.Graphics.RenderTexture(640,480);
            textureThree = new SFML.Graphics.RenderTexture(640,480);

            shapeTwo = new RectangleShape(new Vector2f(20,20)){ FillColor = Color.Red, };
            shapeThree = new RectangleShape(new Vector2f(40,40)){ FillColor = new Color(0,0,0,30), Origin = new Vector2f(20,20) };

            window = new RenderWindow(new VideoMode(640, 480), "SFML.Net RenderTexture FBO bug spike", Styles.Default, new ContextSettings { DepthBits = 32 });
            window.SetActive();
            window.Closed += OnClosed;
            window.KeyPressed += OnKeyPressed;
        }
Ejemplo n.º 10
0
        public static void Main()
        {
            var resolution = new VideoMode(WIDTH, HEIGHT, 32);
            var windowSettings = new ContextSettings(32, 0, 4);
            var window = new RenderWindow(resolution, "Lockheed the Game", Styles.Close, windowSettings);

            window.Closed += Events.OnClose;
            window.KeyPressed += Events.OnKeyPressed;
            window.KeyReleased += Events.OnKeyReleased;
            window.MouseButtonPressed += Events.OnMouseButtonPressed;
            window.SetActive();

            Level.Level newLevel = Level.Level.GenerateSingleLevel();
            Character.Character glava = new Rogue("glava");

            glava.CurrentSkill = new ProjectileSkill(
                "fireball", 10, 10, 10, Tier.Beginner, 5, "weapons/projectiles/fireBall.png", 5);

            EntityManager.CurrentLevel = newLevel;
            EntityManager.Character = glava;

            DateTime lastTick = DateTime.Now;
            while (window.IsOpen())
            {
                float dt = (float)(DateTime.Now - lastTick).TotalMilliseconds;
                lastTick = DateTime.Now;
                window.DispatchEvents();

                while (dt > 0)
                {
                    EntityManager.Update();
                    dt -= MAX_TIMESTEP;
                }

                window.Clear(Color.Black);
                EntityManager.Draw(window);
                window.Display();
            }
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            Log.GlobalLevel = Log.Level.Debug;

            RenderWindow app = new RenderWindow(new VideoMode(800, 600), "HP!",
                Styles.Default, new ContextSettings(0, 0, 4));
            app.SetFramerateLimit(60);
            app.Closed += delegate { app.Close(); };
            app.SetVisible(true);
            app.SetActive(true);

            L.I("Assuming assets in \"assets\"");
            Assets assets = new Assets("assets");
            LoadAnimations(assets);

            Level level1 = assets.Level("level1.json");
            Game game = new Game(assets, level1);
            var view = new View();

            int lastFrameTime = Environment.TickCount;
            while (app.IsOpen) {
                app.DispatchEvents();

                float aspect = (float)app.Size.X / app.Size.Y;
                float targetWidth = 20, targetHeight = targetWidth / aspect;
                view.Reset(new FloatRect(0, 0, targetWidth, targetHeight));
                app.SetView(view);

                int ticks = Environment.TickCount;
                float delta = (ticks - lastFrameTime) / 1000F;
                lastFrameTime = ticks;

                game.Update(delta);
                game.Render(app);

                app.Display();
            }
        }
Ejemplo n.º 12
0
        static void Main()
        {
            //try
            {
                const int width = 1024;
                const int height = 768;

                // Create main window
                m_Window = new RenderWindow(new VideoMode(width, height), "GWEN.Net SFML test", Styles.Titlebar|Styles.Close|Styles.Resize, new ContextSettings(32, 0));

                // Setup event handlers
                m_Window.Closed += OnClosed;
                m_Window.KeyPressed += OnKeyPressed;
                m_Window.Resized += OnResized;
                m_Window.KeyReleased += window_KeyReleased;
                m_Window.MouseButtonPressed += window_MouseButtonPressed;
                m_Window.MouseButtonReleased += window_MouseButtonReleased;
                m_Window.MouseWheelMoved += window_MouseWheelMoved;
                m_Window.MouseMoved += window_MouseMoved;
                m_Window.TextEntered += window_TextEntered;

                //m_Window.SetFramerateLimit(60);

                const int fps_frames = 50;
                List<long> ftime = new List<long>(fps_frames);
                long lastTime = 0;

                // create GWEN renderer
                Renderer.SFML gwenRenderer = new Renderer.SFML(m_Window);

                // Create GWEN skin
                //Skin.Simple skin = new Skin.Simple(GwenRenderer);
                Skin.TexturedBase skin = new Skin.TexturedBase(gwenRenderer, "DefaultSkin.png");

                // set default font
                Font defaultFont = new Font(gwenRenderer) {Size = 10, FaceName = "Arial Unicode MS"};
                
                // try to load, fallback if failed
                if (gwenRenderer.LoadFont(defaultFont))
                {
                    gwenRenderer.FreeFont(defaultFont);
                }
                else // try another
                {
                    defaultFont.FaceName = "Arial";
                    if (gwenRenderer.LoadFont(defaultFont))
                    {
                        gwenRenderer.FreeFont(defaultFont);
                    }
                    else // try default
                    {
                        defaultFont.FaceName = "OpenSans.ttf";
                    }
                }

                skin.SetDefaultFont(defaultFont.FaceName);
                defaultFont.Dispose(); // skin has its own

                // Create a Canvas (it's root, on which all other GWEN controls are created)
                m_Canvas = new Canvas(skin);
                m_Canvas.SetSize(width, height);
                m_Canvas.ShouldDrawBackground = true;
                m_Canvas.BackgroundColor = System.Drawing.Color.FromArgb(255, 150, 170, 170);
                m_Canvas.KeyboardInputEnabled = true;

                // create the unit test control
                m_UnitTest = new UnitTest.UnitTest(m_Canvas);

                // Create GWEN input processor
                m_Input = new Input.SFML();
                m_Input.Initialize(m_Canvas, m_Window);

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                while (m_Window.IsOpen())
                {
                    m_Window.SetActive();
                    m_Window.DispatchEvents();
                    m_Window.Clear();

                    // Clear depth buffer
                    Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT | Gl.GL_COLOR_BUFFER_BIT);

                    if (ftime.Count == fps_frames)
                        ftime.RemoveAt(0);

                    ftime.Add(stopwatch.ElapsedMilliseconds - lastTime);
                    lastTime = stopwatch.ElapsedMilliseconds;

                    if (stopwatch.ElapsedMilliseconds > 1000)
                    {
                        m_UnitTest.Fps = 1000f * ftime.Count / ftime.Sum();
                        stopwatch.Restart();
                    }

                    // render GWEN canvas
                    m_Canvas.RenderCanvas();

                    m_Window.Display();
                }

                // we only need to dispose the canvas, it will take care of disposing all its children
                m_Canvas.Dispose();
                
                // also dispose of these
                skin.Dispose();
                gwenRenderer.Dispose();
            }
            //catch (Exception e)
            //{
                //String msg = String.Format("Exception: {0}\n{1}", e.Message, e.StackTrace);
                //MessageBox.Show(msg);
            //}

            m_Window.Dispose();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Request a 32-bits depth buffer when creating the window
            ContextSettings contextSettings = new ContextSettings();
            contextSettings.DepthBits = 32;

            // Create the main window
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML graphics with OpenGL", Styles.Default, contextSettings);
            window.SetVerticalSyncEnabled(true);

            // Make it the active window for OpenGL calls
            window.SetActive();

            // Setup event handlers
            window.Closed     += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.Resized    += new EventHandler<SizeEventArgs>(OnResized);

            // Create a sprite for the background
            Sprite background = new Sprite(new Texture("resources/background.jpg"));

            // Create a text to display on top of the OpenGL object
            Text text = new Text("SFML / OpenGL demo", new Font("resources/sansation.ttf"));
            text.Position = new Vector2f(250, 450);
            text.Color = new Color(255, 255, 255, 170);

            // Load an OpenGL texture.
            // We could directly use a SFML.Graphics.Texture as an OpenGL texture (with its Bind() member function),
            // but here we want more control on it (generate mipmaps, ...) so we create a new one
            int texture = 0;
            using (Image image = new Image("resources/texture.jpg"))
            {
                Gl.glGenTextures(1, out texture);
                Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture);
                Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGBA, (int)image.Size.X, (int)image.Size.Y, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, image.Pixels);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_LINEAR);
            }

            // Enable Z-buffer read and write
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthMask(Gl.GL_TRUE);
            Gl.glClearDepth(1);

            // Disable lighting
            Gl.glDisable(Gl.GL_LIGHTING);

            // Configure the viewport (the same size as the window)
            Gl.glViewport(0, 0, (int)window.Size.X, (int)window.Size.Y);

            // Setup a perspective projection
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            float ratio = (float)(window.Size.X) / window.Size.Y;
            Gl.glFrustum(-ratio, ratio, -1, 1, 1, 500);

            // Bind the texture
            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture);

            // Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
            float[] cube = new float[]
            {
                // positions    // texture coordinates
                -20, -20, -20,  0, 0,
                -20,  20, -20,  1, 0,
                -20, -20,  20,  0, 1,
                -20, -20,  20,  0, 1,
                -20,  20, -20,  1, 0,
                -20,  20,  20,  1, 1,

                 20, -20, -20,  0, 0,
                 20,  20, -20,  1, 0,
                 20, -20,  20,  0, 1,
                 20, -20,  20,  0, 1,
                 20,  20, -20,  1, 0,
                 20,  20,  20,  1, 1,

                -20, -20, -20,  0, 0,
                 20, -20, -20,  1, 0,
                -20, -20,  20,  0, 1,
                -20, -20,  20,  0, 1,
                 20, -20, -20,  1, 0,
                 20, -20,  20,  1, 1,

                -20,  20, -20,  0, 0,
                 20,  20, -20,  1, 0,
                -20,  20,  20,  0, 1,
                -20,  20,  20,  0, 1,
                 20,  20, -20,  1, 0,
                 20,  20,  20,  1, 1,

                -20, -20, -20,  0, 0,
                 20, -20, -20,  1, 0,
                -20,  20, -20,  0, 1,
                -20,  20, -20,  0, 1,
                 20, -20, -20,  1, 0,
                 20,  20, -20,  1, 1,

                -20, -20,  20,  0, 0,
                 20, -20,  20,  1, 0,
                -20,  20,  20,  0, 1,
                -20,  20,  20,  0, 1,
                 20, -20,  20,  1, 0,
                 20,  20,  20,  1, 1
            };

            // Enable position and texture coordinates vertex components
            Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
            Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
            Gl.glVertexPointer(3, Gl.GL_FLOAT, 5 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 0));
            Gl.glTexCoordPointer(2, Gl.GL_FLOAT, 5 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 3));

            // Disable normal and color vertex components
            Gl.glDisableClientState(Gl.GL_NORMAL_ARRAY);
            Gl.glDisableClientState(Gl.GL_COLOR_ARRAY);

            int startTime = Environment.TickCount;

            // Start game loop
            while (window.IsOpen())
            {
                // Process events
                window.DispatchEvents();

                // Clear the window
                window.Clear();

                // Draw background
                window.PushGLStates();
                window.Draw(background);
                window.PopGLStates();

                // Clear the depth buffer
                Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT);

                // We get the position of the mouse cursor, so that we can move the box accordingly
                float x =  Mouse.GetPosition(window).X * 200.0F / window.Size.X - 100.0F;
                float y = -Mouse.GetPosition(window).Y * 200.0F / window.Size.Y + 100.0F;

                // Apply some transformations
                float time = (Environment.TickCount - startTime) / 1000.0F;
                Gl.glMatrixMode(Gl.GL_MODELVIEW);
                Gl.glLoadIdentity();
                Gl.glTranslatef(x, y, -100.0F);
                Gl.glRotatef(time * 50, 1.0F, 0.0F, 0.0F);
                Gl.glRotatef(time * 30, 0.0F, 1.0F, 0.0F);
                Gl.glRotatef(time * 90, 0.0F, 0.0F, 1.0F);

                // Draw the cube
                Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 36);

                // Draw some text on top of our OpenGL object
                window.PushGLStates();
                window.Draw(text);
                window.PopGLStates();

                // Finally, display the rendered frame on screen
                window.Display();
            }

            // Don't forget to destroy our texture
            Gl.glDeleteTextures(1, ref texture);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Handles the <see cref="IGameContainer.RenderWindowChanged"/> event.
        /// </summary>
        /// <param name="oldValue">The old value.</param>
        /// <param name="newValue">The new value.</param>
        protected virtual void OnRenderWindowChanged(RenderWindow oldValue, RenderWindow newValue)
        {
            if (newValue == null)
                return;

            newValue.SetMouseCursorVisible(ShowMouseCursor);
            newValue.SetVerticalSyncEnabled(UseVerticalSync);
            newValue.SetActive();
            newValue.SetVisible(true);
        }
Ejemplo n.º 15
0
        public ImageViewer(string file)
        {
            IL.Initialize();

            // Extension supported?
            if (!ImageViewerUtils.IsValidExtension(file, EXTENSIONS))
                return;

            // Save Mouse Position -> will open image at this position
            Vector2i mousePos = Mouse.GetPosition();

            // Get Image
            LoadImage(file);

            if (Image == null)
                return;

            // Load Config File
            Config = new Config();
            Config.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.txt"));

            if (Config.Setting_ListenForConfigChanges)
            {
                ConfigFileWatcher = new FileSystemWatcher(AppDomain.CurrentDomain.BaseDirectory, "config.txt");
                ConfigFileWatcher.NotifyFilter = NotifyFilters.LastWrite;
                ConfigFileWatcher.Changed += new FileSystemEventHandler(OnConfigChanged);
                ConfigFileWatcher.EnableRaisingEvents = true;
            }

            // Get/Set Folder Sorting
            SortImagesBy = Config.Setting_DefaultSortBy;
            SortImagesByDir = Config.Setting_DefaultSortDir;

            if (SortImagesBy == SortBy.FolderDefault || SortImagesByDir == SortDirection.FolderDefault)
            {
                // Get parent folder name
                string parentFolder = file.Substring(0, file.LastIndexOf('\\'));
                parentFolder = parentFolder.Substring(parentFolder.LastIndexOf('\\') + 1, parentFolder.Length - parentFolder.LastIndexOf('\\') - 1);

                // Get sort column info from window with corresponding name
                SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
                foreach (SHDocVw.ShellBrowserWindow shellWindow in shellWindows)
                {
                    if (shellWindow.LocationName != parentFolder)
                        continue;

                    Shell32.ShellFolderView view = (Shell32.ShellFolderView)shellWindow.Document;

                    string sort = view.SortColumns;
                    sort = sort.Substring(5, sort.Length - 5);

                    // Direction
                    if (sort[0] == '-')
                    {
                        sort = sort.Substring(1, sort.Length - 1);

                        if (SortImagesByDir == SortDirection.FolderDefault)
                            SortImagesByDir = SortDirection.Descending;
                    }
                    else if (SortImagesByDir == SortDirection.FolderDefault)
                        SortImagesByDir = SortDirection.Ascending;

                    // By
                    if (SortImagesBy == SortBy.FolderDefault)
                    {
                        switch (sort)
                        {
                            case "System.ItemDate;": SortImagesBy = SortBy.Date; break;
                            case "System.DateModified;": SortImagesBy = SortBy.DateModified; break;
                            case "System.DateCreated;": SortImagesBy = SortBy.DateCreated; break;
                            case "System.Size;": SortImagesBy = SortBy.Size; break;
                            default: SortImagesBy = SortBy.Name; break;
                        }
                    }
                }
            }
            // Default sorting if folder was closed
            if (SortImagesBy == SortBy.FolderDefault)
                SortImagesBy = SortBy.Name;
            if (SortImagesByDir == SortDirection.FolderDefault)
                SortImagesByDir = SortDirection.Ascending;

            // Create Context Menu
            ContextMenu = new ContextMenu(this);
            ContextMenu.LoadItems(Config.ContextMenu, Config.ContextMenu_Animation, Config.ContextMenu_Animation_InsertAtIndex);
            ContextMenu.Setup(false);

            // Create Window
            Window = new RenderWindow(new VideoMode(Image.Texture.Size.X, Image.Texture.Size.Y), File + " - vimage", Styles.None);
            Window.SetActive();

            // Make Window Transparent (can only tell if image being viewed has transparency)
            DWM_BLURBEHIND bb = new DWM_BLURBEHIND(false);
            bb.dwFlags = DWM_BB.Enable;
            bb.fEnable = true;
            bb.hRgnBlur = new IntPtr();
            DWM.DwmEnableBlurBehindWindow(Window.SystemHandle, ref bb);

            bool _forceAlwaysOnTop = false;

            // Get Bounds
            IntRect bounds = ImageViewerUtils.GetCurrentBounds(mousePos);

            // Resize Window
            if (Config.Setting_LimitImagesToMonitor != Config.NONE)
            {
                // Fit to monitor height/width
                int limit = Config.Setting_LimitImagesToMonitor;

                if (limit == Config.AUTO)
                {
                    if (bounds.Height < bounds.Width)
                        limit = Config.HEIGHT;
                    else
                        limit = Config.WIDTH;
                }

                if (limit == Config.HEIGHT && Image.Texture.Size.Y > bounds.Height)
                {
                    Zoom(1 + (((float)bounds.Height - Image.Texture.Size.Y) / Image.Texture.Size.Y), true);
                    FitToMonitorHeightForced = true;
                }
                else if (limit == Config.WIDTH && Image.Texture.Size.X > bounds.Width)
                {
                    Zoom(1 + (((float)bounds.Width - Image.Texture.Size.X) / Image.Texture.Size.X), true);
                    AutomaticallyZoomed = true;
                }
            }
            if (Math.Min(Image.Texture.Size.X, Image.Texture.Size.Y) < Config.Setting_MinImageSize)
            {
                // Reisze images smaller than min size to min size
                AutomaticallyZoomed = true;
                Zoom(Config.Setting_MinImageSize / Math.Min(Image.Texture.Size.X, Image.Texture.Size.Y), true);
            }
                // Use Texture Size * Zoom instead of Window.Size since it wouldn't have updated yet
            Vector2i winSize = new Vector2i((int)(Image.Texture.Size.X * CurrentZoom), (int)(Image.Texture.Size.Y * CurrentZoom));

            // Position Window
            Vector2i winPos;

            if (Config.Setting_PositionLargeWideImagesInCorner && CurrentImageSize().X > CurrentImageSize().Y && CurrentImageSize().X * CurrentZoom >= bounds.Width)
            {
                // Position Window in top-left if the image is wide (ie: a Desktop Wallpaper / Screenshot)
                winPos = new Vector2i(bounds.Left, bounds.Top);
            }
            else if (Config.Setting_OpenAtMousePosition)
            {
                // At Mouse Position
                winPos = new Vector2i(mousePos.X - (int)(winSize.X / 2), mousePos.Y - (int)(winSize.Y / 2));

                if (!FitToMonitorHeightForced)
                {
                    if (winPos.Y < bounds.Top)
                        winPos.Y = 0;
                    else if (winPos.Y + winSize.Y > bounds.Height)
                        winPos.Y = bounds.Height - (int)winSize.Y;
                }
                else
                    winPos.Y = bounds.Top;

                if (winPos.X < bounds.Left)
                    winPos.X = bounds.Left;
                else if (winPos.X + winSize.X > bounds.Left + bounds.Width)
                    winPos.X = bounds.Left + bounds.Width - (int)winSize.X;
            }
            else
            {
                // At Monitor Center
                IntRect monitorBounds = ImageViewerUtils.GetCurrentBounds(mousePos);
                winPos = new Vector2i(monitorBounds.Left + (int)((monitorBounds.Width - winSize.X) / 2), monitorBounds.Top + (int)((monitorBounds.Height - winSize.Y) / 2));
            }

            Window.Position = winPos;

            // Force Always On Top Mode (so it's above the task bar)
            if (FitToMonitorHeightForced || (Image.Texture.Size.Y >= bounds.Height && Image.Texture.Size.X < bounds.Width))
                _forceAlwaysOnTop = true;

            // Defaults
                // Rotation (some images have a rotation set in their exif data)
            RotateImage(DefaultRotation, false);
                // Smoothing
            if (Image is AnimatedImage)
                Image.Data.Smooth = Math.Min(Image.Texture.Size.X, Image.Texture.Size.Y) < Config.Setting_SmoothingMinImageSize ? false : Config.Setting_SmoothingDefault;
            else
                Image.Texture.Smooth = Math.Min(Image.Texture.Size.X, Image.Texture.Size.Y) < Config.Setting_SmoothingMinImageSize ? false : Config.Setting_SmoothingDefault;
                // Backgrounds For Images With Transparency
            BackgroundsForImagesWithTransparency = Config.Setting_BackgroundForImagesWithTransparencyDefault;

            ForceAlwaysOnTopNextTick = _forceAlwaysOnTop;

            Redraw();
            NextWindowPos = Window.Position;

            // Interaction
            Window.Closed += OnWindowClosed;
            Window.MouseButtonPressed += OnMouseDown;
            Window.MouseButtonReleased += OnMouseUp;
            Window.MouseWheelScrolled += OnMouseWheelScrolled;
            Window.MouseMoved += OnMouseMoved;
            Window.KeyReleased += OnKeyUp;
            Window.KeyPressed += OnKeyDown;

            // Loop
            Stopwatch clock = new Stopwatch();
            clock.Start();

            while (Window.IsOpen)
            {
                // Add in some idle time to not thrash the CPU
                Thread.Sleep(1);

                if (CloseNextTick)
                {
                    Window.Close();
                    break;
                }

                // Process events
                Window.DispatchEvents();

                if (ReloadConfigNextTick)
                {
                    ReloadConfig();
                    ReloadConfigNextTick = false;
                }

                // Animated Image?
                if (Image is AnimatedImage)
                {
                    bool imageUpdated = Image.Update((float)clock.Elapsed.TotalMilliseconds);
                    if (!Updated && imageUpdated)
                        Update();
                }
                clock.Restart();

                // Drag Window
                if (Dragging)
                    Window.Position = new Vector2i(Mouse.GetPosition().X - DragPos.X, Mouse.GetPosition().Y - DragPos.Y);

                // Update
                if (Updated)
                {
                    Updated = false;
                    Redraw();
                    Window.Position = NextWindowPos;
                }

                if (ForceAlwaysOnTopNextTick)
                {
                    bounds = ImageViewerUtils.GetCurrentBounds(Window.Position);
                    if (Window.Size.Y >= bounds.Height && Window.Size.X < bounds.Width)
                        ForceAlwaysOnTop();
                    else
                        ForceAlwaysOnTopNextTick = false;
                }

                if (PreloadNextImageStart)
                    PreloadNextImage();
            }
        }
Ejemplo n.º 16
0
            public void Run()
            {
                var mode   = new SFML.Window.VideoMode(800, 600);
                var window = new SFML.Graphics.RenderWindow(mode, "SFML works!");



                window.KeyPressed += Window_KeyPressed;

                var circle = new SFML.Graphics.CircleShape(100f)
                {
                    FillColor = SFML.Graphics.Color.Blue
                };
                Clock clock = new Clock();


                window.SetActive(true);
                //window.PushGLStates();
                GuiImpl.Init(window);
                //window.PopGLStates();
                window.SetActive(false);


                Image   image   = new Image(100, 100, Color.Red);
                Texture texture = new Texture(image);

                // Start the game loop
                while (window.IsOpen)
                {
                    // Process events
                    window.DispatchEvents();
                    window.SetActive(true);
                    //window.PushGLStates();

                    GuiImpl.Update(window, clock.Restart());
                    ImGui.BeginMainMenuBar();
                    if (ImGui.BeginMenu("File"))
                    {
                        ImGui.MenuItem("Open");
                        ImGui.EndMenu();
                    }
                    ImGui.EndMainMenuBar();

                    ImGui.Begin("Hello, world!");
                    if (ImGui.Button("Look at this pretty button"))
                    {
                        System.Console.WriteLine("Hi!");
                    }

                    //System.Console.WriteLine(texture.NativeHandle);
                    ImGui.Image(new IntPtr(texture.NativeHandle), new System.Numerics.Vector2(200, 200));
                    ImGui.End();

                    ImGui.Begin("Hello, world!2");
                    if (ImGui.Button("Look at this pretty button22"))
                    {
                        System.Console.WriteLine("Hi2!");
                    }
                    ImGui.Text("Hallo");
                    ImGui.End();
                    ImGui.Button("lll");

                    //window.PopGLStates();
                    window.SetActive(false);


                    window.Clear();
                    window.Draw(circle);
                    GuiImpl.Render();
                    // Finally, display the rendered frame on screen
                    window.Display();
                }
                GuiImpl.Shutdown();
            }
Ejemplo n.º 17
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Request a 24-bits depth buffer when creating the window
            ContextSettings contextSettings = new ContextSettings();
            contextSettings.DepthBits = 24;

            // Create the main window
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML graphics with OpenGL", Styles.Default, contextSettings);
            window.SetVerticalSyncEnabled(true);

            // Initialize OpenTK
            Toolkit.Init();
            GraphicsContext context = new GraphicsContext(new ContextHandle(IntPtr.Zero), null);

            // Setup event handlers
            window.Closed     += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.Resized    += new EventHandler<SizeEventArgs>(OnResized);

            // Create a sprite for the background
            Sprite background = new Sprite(new Texture("resources/background.jpg"));

            // Create a text to display on top of the OpenGL object
            Text text = new Text("SFML / OpenGL demo", new Font("resources/sansation.ttf"));
            text.Position = new Vector2f(250, 450);
            text.Color = new Color(255, 255, 255, 170);

            // Make the window the active target for OpenGL calls
            window.SetActive();

            // Load an OpenGL texture.
            // We could directly use a SFML.Graphics.Texture as an OpenGL texture (with its Bind() member function),
            // but here we want more control on it (generate mipmaps, ...) so we create a new one
            int texture = 0;
            using (Image image = new Image("resources/texture.jpg"))
            {
                GL.GenTextures(1, out texture);
                GL.BindTexture(TextureTarget.Texture2D, texture);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)image.Size.X, (int)image.Size.Y, 0, PixelFormat.Rgba, PixelType.UnsignedByte, image.Pixels);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            }

            // Enable Z-buffer read and write
            GL.Enable(EnableCap.DepthTest);
            GL.DepthMask(true);
            GL.ClearDepth(1);

            // Disable lighting
            GL.Disable(EnableCap.Lighting);

            // Configure the viewport (the same size as the window)
            GL.Viewport(0, 0, (int)window.Size.X, (int)window.Size.Y);

            // Setup a perspective projection
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            float ratio = (float)(window.Size.X) / window.Size.Y;
            GL.Frustum(-ratio, ratio, -1, 1, 1, 500);

            // Bind the texture
            GL.Enable(EnableCap.Texture2D);
            GL.BindTexture(TextureTarget.Texture2D, texture);

            // Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
            float[] cube = new float[]
            {
                // positions    // texture coordinates
                -20, -20, -20,  0, 0,
                -20,  20, -20,  1, 0,
                -20, -20,  20,  0, 1,
                -20, -20,  20,  0, 1,
                -20,  20, -20,  1, 0,
                -20,  20,  20,  1, 1,

                 20, -20, -20,  0, 0,
                 20,  20, -20,  1, 0,
                 20, -20,  20,  0, 1,
                 20, -20,  20,  0, 1,
                 20,  20, -20,  1, 0,
                 20,  20,  20,  1, 1,

                -20, -20, -20,  0, 0,
                 20, -20, -20,  1, 0,
                -20, -20,  20,  0, 1,
                -20, -20,  20,  0, 1,
                 20, -20, -20,  1, 0,
                 20, -20,  20,  1, 1,

                -20,  20, -20,  0, 0,
                 20,  20, -20,  1, 0,
                -20,  20,  20,  0, 1,
                -20,  20,  20,  0, 1,
                 20,  20, -20,  1, 0,
                 20,  20,  20,  1, 1,

                -20, -20, -20,  0, 0,
                 20, -20, -20,  1, 0,
                -20,  20, -20,  0, 1,
                -20,  20, -20,  0, 1,
                 20, -20, -20,  1, 0,
                 20,  20, -20,  1, 1,

                -20, -20,  20,  0, 0,
                 20, -20,  20,  1, 0,
                -20,  20,  20,  0, 1,
                -20,  20,  20,  0, 1,
                 20, -20,  20,  1, 0,
                 20,  20,  20,  1, 1
            };

            // Enable position and texture coordinates vertex components
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.VertexPointer(3, VertexPointerType.Float, 5 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 0));
            GL.TexCoordPointer(2, TexCoordPointerType.Float, 5 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 3));

            // Disable normal and color vertex components
            GL.DisableClientState(ArrayCap.NormalArray);
            GL.DisableClientState(ArrayCap.ColorArray);

            Clock clock = new Clock();

            // Start game loop
            while (window.IsOpen)
            {
                // Process events
                window.DispatchEvents();

                // Clear the window
                GL.Clear(ClearBufferMask.DepthBufferBit);

                // Draw background
                window.PushGLStates();
                window.Draw(background);
                window.PopGLStates();

                // Clear the depth buffer
                GL.Clear(ClearBufferMask.DepthBufferBit);

                // We get the position of the mouse cursor, so that we can move the box accordingly
                float x =  Mouse.GetPosition(window).X * 200.0F / window.Size.X - 100.0F;
                float y = -Mouse.GetPosition(window).Y * 200.0F / window.Size.Y + 100.0F;

                // Apply some transformations
                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadIdentity();
                GL.Translate(x, y, -100.0F);
                GL.Rotate(clock.ElapsedTime.AsSeconds() * 50, 1.0F, 0.0F, 0.0F);
                GL.Rotate(clock.ElapsedTime.AsSeconds() * 30, 0.0F, 1.0F, 0.0F);
                GL.Rotate(clock.ElapsedTime.AsSeconds() * 90, 0.0F, 0.0F, 1.0F);

                // Draw the cube
                GL.DrawArrays(OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, 0, 36);

                // Draw some text on top of our OpenGL object
                window.PushGLStates();
                window.Draw(text);
                window.PopGLStates();

                // Finally, display the rendered frame on screen
                window.Display();
            }

            // Don't forget to destroy our texture
            GL.DeleteTextures(1, ref texture);
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            Texture textureBack = new Texture(File.ReadAllBytes(@"assets/back.png"));

            textureBack.Smooth = true;

            Sprite spriteBack = new Sprite(textureBack, new IntRect(0, 0, 800, 500));

            Texture textureLock = new Texture(File.ReadAllBytes(@"assets/lock.png"));

            textureLock.Smooth = true;

            Sprite spriteLock = new Sprite(textureLock, new IntRect(0, 0, 80, 80));

            spriteLock.Position = new Vector2f(76, 68);

            icons = new List<Sprite>();

            for (int index = 0; index < 15; index++)
            {
                int col = index % 5;

                int row = (index - col) / 5;

                Texture textureIcon = new Texture(File.ReadAllBytes(String.Format(@"assets/buttons/{0:00}.png", index + 1)));

                textureIcon.Smooth = true;

                Sprite spriteIcon = new Sprite(textureIcon, new IntRect(0, 0, 72, 72));

                spriteIcon.Position = new Vector2f(80 + col * 72 + col * 70, 72 + row * 72 + row * 70);

                icons.Add(spriteIcon);
            }

            ContextSettings context = new ContextSettings();

            context.DepthBits = 32;

            RenderWindow window = new RenderWindow(new VideoMode(800, 500), String.Empty, Styles.Default, context);

            window.SetActive();

            window.SetVisible(true);

            window.SetKeyRepeatEnabled(true);

            window.SetMouseCursorVisible(true);

            window.SetVerticalSyncEnabled(false);

            window.Closed += new EventHandler(
                delegate(object sender, EventArgs e)
                {
                    window.Close();

                    window.Dispose();
                }
            );

            window.GainedFocus += new EventHandler(
                delegate(object sender, EventArgs e)
                {

                }
            );

            window.LostFocus += new EventHandler(
                delegate(object sender, EventArgs e)
                {

                }
            );

            window.KeyPressed += new EventHandler<KeyEventArgs>(
                delegate(object sender, KeyEventArgs e)
                {
                    if (e.Code == Keyboard.Key.Escape)
                    {
                        /*
                        sound.Stop();

                        sound.Dispose();

                        buffer.Dispose();
                        */

                        window.Close();

                        window.Dispose();
                    }

                    if (e.Code == Keyboard.Key.Right)
                    {
                        if (col < 4)
                        {
                            col += 1;
                        }
                    }

                    if (e.Code == Keyboard.Key.Left)
                    {
                        if (col > 0)
                        {
                            col -= 1;
                        }
                    }

                    if (e.Code == Keyboard.Key.Up)
                    {
                        if (row > 0)
                        {
                            row -= 1;
                        }
                    }

                    if (e.Code == Keyboard.Key.Down)
                    {
                        if (row < 2)
                        {
                            row += 1;
                        }
                    }

                    spriteLock.Position = new Vector2f(80 + col * 72 + col * 70 - 4, 72 + row * 72 + row * 70 - 4);
                }
            );

            window.KeyReleased += new EventHandler<KeyEventArgs>(
                delegate(object sender, KeyEventArgs e)
                {

                }
            );

            window.TouchBegan += new EventHandler<TouchEventArgs>(
                delegate(object sender, TouchEventArgs e)
                {

                }
            );

            window.TouchEnded += new EventHandler<TouchEventArgs>(
                delegate(object sender, TouchEventArgs e)
                {

                }
            );

            window.TouchMoved += new EventHandler<TouchEventArgs>(
                delegate(object sender, TouchEventArgs e)
                {

                }
            );

            window.JoystickConnected += new EventHandler<JoystickConnectEventArgs>(
                delegate(object sender, JoystickConnectEventArgs e)
                {

                }
            );

            window.JoystickDisconnected += new EventHandler<JoystickConnectEventArgs>(
                delegate(object sender, JoystickConnectEventArgs e)
                {

                }
            );

            window.JoystickButtonPressed += new EventHandler<JoystickButtonEventArgs>(
                delegate(object sender, JoystickButtonEventArgs e)
                {
                    //File.AppendAllText(@"joystick.log", Convert.ToString(e.Button) + ":JoystickButtonPressed\n");

                    // A		0
                    // B		1
                    // X		2
                    // Y		3
                    // BACK		6
                    // START	7
                }
            );

            window.JoystickButtonReleased += new EventHandler<JoystickButtonEventArgs>(
                delegate(object sender, JoystickButtonEventArgs e)
                {
                    //File.AppendAllText(@"joystick.log", Convert.ToString(e.Button) + ":JoystickButtonReleased\n");
                }
            );

            window.JoystickMoved += new EventHandler<JoystickMoveEventArgs>(
                delegate(object sender, JoystickMoveEventArgs e)
                {
                    //File.AppendAllText(@"joystick.log", Convert.ToString(e.Axis) + ":" + Convert.ToString(e.JoystickId) + ":" + Convert.ToString(e.Position) + "\n");

                    // RIGHT	PovX	+100
                    // LEFT		PovX	-100
                    if (e.Axis == Joystick.Axis.PovX)
                    {
                        if (e.Position.Equals(+100.0f))
                        {
                            // RIGHT
                            if (col < 4)
                            {
                                col += 1;
                            }
                        }

                        if (e.Position.Equals(-100.0f))
                        {
                            // LEFT
                            if (col > 0)
                            {
                                col -= 1;
                            }
                        }
                    }

                    // UP		PovY	+100
                    // DOWN		PovY	-100
                    if (e.Axis == Joystick.Axis.PovY)
                    {
                        if (e.Position.Equals(+100.0f))
                        {
                            // UP
                            if (row > 0)
                            {
                                row -= 1;
                            }
                        }

                        if (e.Position.Equals(-100.0f))
                        {
                            // DOWN
                            if (row < 2)
                            {
                                row += 1;
                            }
                        }
                    }

                    spriteLock.Position = new Vector2f(80 + col * 72 + col * 70 - 4, 72 + row * 72 + row * 70 - 4);
                }
            );

            while (window.IsOpen)
            {
                window.DispatchEvents();

                window.Clear();

                window.Draw(spriteBack);

                foreach (Sprite icon in icons)
                {
                    window.Draw(icon);
                }

                window.Draw(spriteLock);

                window.Display();
            }
        }
Ejemplo n.º 19
0
        private void Init()
        {
            Console.WriteLine ("Entering Initialization");
            //TODO: add startup stuff//
            //setup the window//
            gameWindow = new RenderWindow(new VideoMode(ScreenWidth,ScreenHeight),GameName,Styles.Close);
            gameWindow.SetActive ();

            //event handlers//
            gameWindow.Closed += new EventHandler(onClosed);

            onInit(new EventArgs ());
            Console.WriteLine ("Finished Initialization");
        }
Ejemplo n.º 20
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Create main window
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net OpenGL", Styles.Default, new ContextSettings(32, 0));
            window.SetVerticalSyncEnabled(true);

            // Setup event handlers
            window.Closed     += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.Resized    += new EventHandler<SizeEventArgs>(OnResized);

            // Create a sprite for the background
            Sprite background = new Sprite(new Texture("resources/background.jpg"));

            // Create a text to display
            Text text = new Text("SFML / OpenGL demo", new Font("resources/sansation.ttf"));
            text.Position = new Vector2f(250.0F, 450.0F);
            text.Color = new Color(255, 255, 255, 170);

            // Load an OpenGL texture.
            // We could directly use a sf::Texture as an OpenGL texture (with its Bind() member function),
            // but here we want more control on it (generate mipmaps, ...) so we create a new one
            int texture = 0;
            using (Image image = new Image("resources/texture.jpg"))
            {
                Gl.glGenTextures(1, out texture);
                Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture);
                Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGBA, (int)image.Size.X, (int)image.Size.Y, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, image.Pixels);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_LINEAR);
            }

            // Enable Z-buffer read and write
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthMask(Gl.GL_TRUE);
            Gl.glClearDepth(1.0F);

            // Setup a perspective projection
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F);

            // Bind our texture
            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture);
            Gl.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

            int startTime = Environment.TickCount;

            // Start game loop
            while (window.IsOpen())
            {
                // Process events
                window.DispatchEvents();

                // Clear the window
                window.Clear();

                // Draw background
                window.PushGLStates();
                window.Draw(background);
                window.PopGLStates();

                // Activate the window before using OpenGL commands.
                // This is useless here because we have only one window which is
                // always the active one, but don't forget it if you use multiple windows
                window.SetActive();

                // Clear depth buffer
                Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT);

                // We get the position of the mouse cursor, so that we can move the box accordingly
                float x =  Mouse.GetPosition(window).X * 200.0F / window.Size.X - 100.0F;
                float y = -Mouse.GetPosition(window).Y * 200.0F / window.Size.Y + 100.0F;

                // Apply some transformations
                float time = (Environment.TickCount - startTime) / 1000.0F;
                Gl.glMatrixMode(Gl.GL_MODELVIEW);
                Gl.glLoadIdentity();
                Gl.glTranslatef(x, y, -100.0F);
                Gl.glRotatef(time * 50, 1.0F, 0.0F, 0.0F);
                Gl.glRotatef(time * 30, 0.0F, 1.0F, 0.0F);
                Gl.glRotatef(time * 90, 0.0F, 0.0F, 1.0F);

                // Draw a cube
                float size = 20.0F;
                Gl.glBegin(Gl.GL_QUADS);

                    Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-size, -size, -size);
                    Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-size,  size, -size);
                    Gl.glTexCoord2f(1, 1); Gl.glVertex3f( size,  size, -size);
                    Gl.glTexCoord2f(1, 0); Gl.glVertex3f( size, -size, -size);

                    Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-size, -size, size);
                    Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-size,  size, size);
                    Gl.glTexCoord2f(1, 1); Gl.glVertex3f( size,  size, size);
                    Gl.glTexCoord2f(1, 0); Gl.glVertex3f( size, -size, size);

                    Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-size, -size, -size);
                    Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-size,  size, -size);
                    Gl.glTexCoord2f(1, 1); Gl.glVertex3f(-size,  size,  size);
                    Gl.glTexCoord2f(1, 0); Gl.glVertex3f(-size, -size,  size);

                    Gl.glTexCoord2f(0, 0); Gl.glVertex3f(size, -size, -size);
                    Gl.glTexCoord2f(0, 1); Gl.glVertex3f(size,  size, -size);
                    Gl.glTexCoord2f(1, 1); Gl.glVertex3f(size,  size,  size);
                    Gl.glTexCoord2f(1, 0); Gl.glVertex3f(size, -size,  size);

                    Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-size, -size,  size);
                    Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-size, -size, -size);
                    Gl.glTexCoord2f(1, 0); Gl.glVertex3f( size, -size, -size);
                    Gl.glTexCoord2f(1, 1); Gl.glVertex3f( size, -size,  size);

                    Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-size, size,  size);
                    Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-size, size, -size);
                    Gl.glTexCoord2f(1, 0); Gl.glVertex3f( size, size, -size);
                    Gl.glTexCoord2f(1, 1); Gl.glVertex3f( size, size,  size);

                Gl.glEnd();

                // Draw some text on top of our OpenGL object
                window.PushGLStates();
                window.Draw(text);
                window.PopGLStates();

                // Finally, display the rendered frame on screen
                window.Display();
            }

            // Don't forget to destroy our texture
            Gl.glDeleteTextures(1, ref texture);
        }
Ejemplo n.º 21
0
        void RecreateWindow()
        {
            if (window != null)
            {
                window.Close();
                window.Dispose();
            }

            window = new RenderWindow(VideoMode.DesktopMode, "N'oubliez pas les paroles", windowStyle);
            window.SetActive();
            window.SetVisible(true);
            window.Closed += new EventHandler(OnClose);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);

            guiStyle = GuiStyle.LoadFromFile("configihm.xml");

            activeComponent.Initialize();
            activeComponent.LoadContent();
        }