Base class for effects
Inheritance: Drawable
Ejemplo n.º 1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Create the main window
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net Shader");

            window.SetVerticalSyncEnabled(true);

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

            // Load the application font and pass it to the Effect class
            Font font = new Font("resources/sansation.ttf");

            Effect.SetFont(font);

            // Create the effects
            effects = new Effect[]
            {
                new Pixelate(),
                new WaveBlur(),
                new StormBlink(),
                new Edge()
            };
            current = 0;

            // Create the messages background
            Texture textBackgroundTexture = new Texture("resources/text-background.png");
            Sprite  textBackground        = new Sprite(textBackgroundTexture);

            textBackground.Position = new Vector2f(0, 520);
            textBackground.Color    = new Color(255, 255, 255, 200);

            // Create the description text
            description          = new Text("Current effect: " + effects[current].Name, font, 20);
            description.Position = new Vector2f(10, 530);
            description.Color    = new Color(80, 80, 80);

            // Create the instructions text
            Text instructions = new Text("Press left and right arrows to change the current shader", font, 20);

            instructions.Position = new Vector2f(280, 555);
            instructions.Color    = new Color(80, 80, 80);

            // Start the game loop
            int startTime = Environment.TickCount;

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

                // Update the current example
                float time = (Environment.TickCount - startTime) / 1000.0F;
                float x    = (float)Mouse.GetPosition(window).X / window.Size.X;
                float y    = (float)Mouse.GetPosition(window).Y / window.Size.Y;
                effects[current].Update(time, x, y);

                // Clear the window
                window.Clear(new Color(255, 128, 0));

                // Draw the current example
                window.Draw(effects[current]);

                // Draw the text
                window.Draw(textBackground);
                window.Draw(instructions);
                window.Draw(description);

                // Finally, display the rendered frame on screen
                window.Display();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Create the main window
            var window = new RenderWindow(new VideoMode(800, 600), "SFML.Net Shader");

            window.SetVerticalSyncEnabled(true);

            // Setup event handlers
            window.Closed     += OnClosed;
            window.KeyPressed += OnKeyPressed;

            // Load the application font and pass it to the Effect class
            var font = new Font("resources/sansation.ttf");

            Effect.SetFont(font);

            // Create the effects
            effects = new Effect[]
            {
                new Pixelate(),
                new WaveBlur(),
                new StormBlink(),
                new Edge()
            };
            current = 0;

            // Create the messages background
            var textBackgroundTexture = new Texture("resources/text-background.png");
            var textBackground        = new Sprite(textBackgroundTexture)
            {
                Position = new Vector2f(0, 520),
                Color    = new Color(255, 255, 255, 200)
            };

            // Create the description text
            description = new Text("Current effect: " + effects[current].Name, font, 20)
            {
                Position  = new Vector2f(10, 530),
                FillColor = new Color(80, 80, 80)
            };

            // Create the instructions text
            var instructions = new Text("Press left and right arrows to change the current shader", font, 20)
            {
                Position  = new Vector2f(280, 555),
                FillColor = new Color(80, 80, 80)
            };

            // Start the game loop
            var clock = new Clock();

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

                // Update the current example
                var x = (float)Mouse.GetPosition(window).X / window.Size.X;
                var y = (float)Mouse.GetPosition(window).Y / window.Size.Y;
                effects[current].Update(clock.ElapsedTime.AsSeconds(), x, y);

                // Clear the window
                window.Clear(new Color(255, 128, 0));

                // Draw the current example
                window.Draw(effects[current]);

                // Draw the text
                window.Draw(textBackground);
                window.Draw(instructions);
                window.Draw(description);

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