Wrapper for pixel shaders
상속: SFML.System.ObjectBase
예제 #1
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct a set of render states with all its attributes
 /// </summary>
 /// <param name="blendMode">Blend mode to use</param>
 /// <param name="transform">Transform to use</param>
 /// <param name="texture">Texture to use</param>
 /// <param name="shader">Shader to use</param>
 ////////////////////////////////////////////////////////////
 public RenderStates(BlendMode blendMode, Transform transform, Texture texture, Shader shader)
 {
     BlendMode = blendMode;
     Transform = transform;
     Texture = texture;
     Shader = shader;
 }
        public void Initialize()
        {
            SelectedShader = new Shader(null, "Shader/SelectedShader.frag");
            SelectedState = new RenderStates(SelectedShader);

            AddControls();
        }
예제 #3
0
        public Edge()
            : base("edge post-effect")
        {
            // Create the off-screen surface
            mySurface = new RenderTexture(800, 600);
            mySurface.Smooth = true;

            // Load the textures
            myBackgroundTexture = new Texture("resources/sfml.png");
            myBackgroundTexture.Smooth = true;
            myEntityTexture = new Texture("resources/devices.png");
            myEntityTexture.Smooth = true;

            // Initialize the background sprite
            myBackgroundSprite = new Sprite(myBackgroundTexture);
            myBackgroundSprite.Position = new Vector2f(135, 100);

            // Load the moving entities
            myEntities = new Sprite[6];
            for (int i = 0; i < myEntities.Length; ++i)
            {
                myEntities[i] = new Sprite(myEntityTexture, new IntRect(96 * i, 0, 96, 96));
            }

            // Load the shader
            myShader = new Shader(null, "resources/edge.frag");
            myShader.SetParameter("texture", Shader.CurrentTexture);
        }
예제 #4
0
        public BloomTest(RenderTexture target_tex, RenderTarget target)
        {
            _target = target;

            _bloom = new Shader(null, "bloom.glsl");
            _texture = new RenderTexture((uint)GlobalProps.Width, (uint)GlobalProps.Height);
            _states.BlendMode = BlendMode.Alpha;
            _states.Shader = _bloom;
            _states.Transform = Transform.Identity;
            _states.Texture = target_tex.Texture;
            _bloom.SetParameter("referenceTex", Shader.CurrentTexture);
            _bloom.SetParameter("pixelWidth", 4);
            _bloom.SetParameter("pixelHeight", 4);

            int w = GlobalProps.Width, h = GlobalProps.Height;
            Vector2f v0 = new Vector2f(0, 0);
            Vector2f v1 = new Vector2f(w, 0);
            Vector2f v2 = new Vector2f(w, h);
            Vector2f v3 = new Vector2f(0, h);

            _verts = new Vertex[4];
            _verts[0] = new Vertex(v0, Color.White, v0);
            _verts[1] = new Vertex(v1, Color.White, v1);
            _verts[2] = new Vertex(v2, Color.White, v2);
            _verts[3] = new Vertex(v3, Color.White, v3);
        }
예제 #5
0
        /// <summary>
        /// Initializes the <see cref="WaterRefractionEffect"/> class.
        /// </summary>
        static WaterRefractionEffect()
        {
            // Set the default values
            DefaultWaterAlpha = _defaultWaterAlpha;
            DefaultWaveSpeed = _defaultWaveSpeed;
            DefaultWaveIntensity = _defaultWaveIntensity;
            DefaultMagnification = _defaultMagnification;

            // Check if shaders are supported
            if (!Shader.IsAvailable)
            {
                const string msg =
                    "Unable to construct shader for `WaterRefractionEffect` - shaders are not supported on this system.";
                if (log.IsInfoEnabled)
                    log.InfoFormat(msg);
                return;
            }

            // Try to create the default shader
            try
            {
                var code = Resources.WaterRefractionEffectShader;
                _defaultShader = ShaderExtensions.LoadFromMemory(code);
            }
            catch (LoadingFailedException ex)
            {
                const string errmsg = "Failed to load the default Shader for WaterRefractionEffect. Exception: {0}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, ex);
                Debug.Fail(string.Format(errmsg, ex));
            }
        }
        /// <summary>
        /// Initializes the <see cref="ExplosionRefractionEffect"/> class.
        /// </summary>
        static ExplosionRefractionEffect()
        {
            // Set the default values
            DefaultLifeSpan = _defaultLifeSpan;
            DefaultExpansionRate = new Vector2(1.5f, 1.5f);
            DefaultIntensity = _defaultIntensity;

            // Check if shaders are supported
            if (!Shader.IsAvailable)
            {
                const string msg =
                    "Unable to construct shader for `ExplosionRefractionEffect` - shaders are not supported on this system.";
                if (log.IsInfoEnabled)
                    log.InfoFormat(msg);
                return;
            }

            // Try to create the default shader
            try
            {
                var code = Resources.ExplosionRefractionEffectShader;
                _defaultShader = ShaderExtensions.LoadFromMemory(code);
            }
            catch (LoadingFailedException ex)
            {
                const string errmsg = "Failed to load the default Shader for ExplosionRefractionEffect. Exception: {0}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, ex);
                Debug.Fail(string.Format(errmsg, ex));
            }
        }
예제 #7
0
파일: Shader.cs 프로젝트: SFML/SFML.Net
        public Pixelate() : base("pixelate")
        {
            // Load the texture and initialize the sprite
            myTexture = new Texture("resources/background.jpg");
            mySprite = new Sprite(myTexture);

            // Load the shader
            myShader = new Shader(null, null, "resources/pixelate.frag");
            myShader.SetUniform("texture", Shader.CurrentTexture);
        }
예제 #8
0
파일: Shader.cs 프로젝트: AlexSolari/Evo
 /// <summary>
 /// Creates a shader using a file path and a ShaderType parameter.
 /// </summary>
 /// <param name="shaderType">The shader type (fragment or vertex)</param>
 /// <param name="source">The file path.</param>
 public Shader(ShaderType shaderType, string source)
 {
     if (shaderType == ShaderType.Vertex)
     {
         shader = new SFML.Graphics.Shader(source, null);
     }
     else
     {
         shader = new SFML.Graphics.Shader(null, source);
     }
 }
예제 #9
0
파일: Shader.cs 프로젝트: AlexSolari/Evo
 /// <summary>
 /// Creates a Shader using a file path source, and auto detects which type of shader
 /// it is.  If the file path contains ".frag" or ".fs" it is assumed to be a fragment shader.
 /// </summary>
 /// <param name="source">The file path.</param>
 public Shader(string source)
 {
     if (source.Contains(".frag") || source.Contains(".fs"))
     {
         shader = new SFML.Graphics.Shader(null, source);
     }
     else
     {
         shader = new SFML.Graphics.Shader(source, null);
     }
 }
예제 #10
0
        public PointLight(Color color, float power, float radius, Vector2f position)
        {
            Position = position;
            Color = color;
            Power = power;
            Radius = radius;

            VisMap = new VisbilityMap(Position, Radius);

            _shader = new Shader("shaders/lightShader.vert", "shaders/lightShader.frag");
        }
예제 #11
0
        /// <summary>
        /// Loads a <see cref="Shader"/> using code in memory.
        /// </summary>
        /// <param name="code">The GLSL code to use.</param>
        /// <returns>The loaded <see cref="Shader"/>.</returns>
        public static Shader LoadFromMemory(string code)
        {
            Shader ret;

            // To bypass the requirement of having to load from file, write the code to a temporary file then load the shader
            using (var tmpFile = new TempFile())
            {
                File.WriteAllText(tmpFile.FilePath, code);
                ret = new Shader(tmpFile.FilePath);
            }

            return ret;
        }
예제 #12
0
        public GraphicsDisplay(uint width, uint height)
        {
            Width = width;
            Height = height;

            _data = new Image(width, height, Color.Black);
            _dataTexture = new Texture(_data);
            _palette = new Image("Data/palette.png");
            _paletteTexture = new Texture(_palette);

            _display = new Sprite(_dataTexture);

            _renderer = new Shader("Data/display.vert", "Data/display.frag");
            _renderer.SetParameter("data", _dataTexture);
            _renderer.SetParameter("dataSize", width, height);
            _renderer.SetParameter("palette", _paletteTexture);
        }
예제 #13
0
        public LightLayer(Vector2u gameRez, Vector2u windowRez)
        {
            Lights = new List<Light>();
            Polygons = new List<Polygon>();

            renText = new RenderTexture(gameRez.X, gameRez.Y);
            lightMap = new RenderTexture(gameRez.X, gameRez.Y);
            lightMap.Smooth = true;
            scene = new Texture(windowRez.X, windowRez.Y);

            lightShader = new Shader(null, "Content/shaders/light.frag");
            lightShader.SetParameter("screenHeight", gameRez.Y);
            lightState = new RenderStates(BlendMode.Add, Transform.Identity, renText.Texture, lightShader);

            shadowShader = new Shader(null, "Content/shaders/shadows.frag");
            //shadowState = new RenderStates(shadowShader);
            shadowState = new RenderStates(BlendMode.Multiply);
        }
예제 #14
0
파일: Game.cs 프로젝트: endert/Intro2D
        public Game()
        {
            win = win = new RenderWindow(new SFML.Window.VideoMode(800, 670), "Shader^^");
            win.Closed += (sender, e) => { ((RenderWindow)sender).Close(); };

            BackgroundGrayScale = new Sprite(new Texture("bg.png"));

            BackgroundMult = new Sprite(new Texture("wall.png"));
            Overlay = new Sprite(new Texture("lightMask.png"));
            t = new GameTime();

            GrayScaleShader = new Shader(null, "GrayScale.frag");
            GrayScaleState = new RenderStates(GrayScaleShader);

            MultTexture = new RenderTexture(800, 670);
            MultShader = new Shader(null, "Mult.frag");
            MultState = new RenderStates(MultShader);
            Add = new RenderStates(BlendMode.Add);
        }
예제 #15
0
        public LightEffectManager(Map parent)
        {
            Parent = parent;

            DynamicEffects = new List<LightEffect>();
            StaticEffects = new List<LightEffect>();

            GlobalColor = DEFAUT_GLOBAL_COLOR;

            IsRefreshed = false;

            RenderTexture = new RenderTexture(GameData.WINDOW_WIDTH, GameData.WINDOW_HEIGHT);
            BlurEffect = new Shader(GameData.DATAS_DEFAULT_PATH + "gfx/blur.sfx");
            BlurEffect.SetCurrentTexture("texture");
            BlurEffect.SetParameter("offset", 0.005F * SMOOTHNESS);

            Walls = null;
            OpacityBoxes = null;
        }
예제 #16
0
        public static void load_batch_shaders(string folder)
        {
            //Debug.Log("Loading shaders from folder " + folder);
            Debug.StartLogGroup();
                DirectoryInfo dir = new DirectoryInfo(folder);

                if (dir.Exists)
                {
                    FileInfo[] files = dir.GetFiles("*.sfx", System.IO.SearchOption.AllDirectories);

                    for (int f = 0; f < files.Length; f++)
                    {
                        Debug.Log("Loading " + files[f].FullName);
                        bool succeeded = true;
                        Shader shader = null;
                        try
                        {
                            shader = new Shader(files[f].FullName);
                        }
                        catch (SFML.LoadingFailedException e)
                        {
                            succeeded = false;
                            throw;
                        }

                        if (succeeded)
                        {
                            Debug.Log("Success!");
                            var temp = files[f].Name;
                            var identifier = files[f].Name.Remove(files[f].Name.LastIndexOf('.'));
                            shaders.Add(identifier, shader);
                        }
                        else
                        {
                            Debug.Log("Shader loading failed");
                        }

                    }
                }
            Debug.EndLogGroup();
        }
예제 #17
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");

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

            // Check that the system can use shaders
            if (Shader.IsAvailable == false)
            {
                DisplayError(window);
                return;
            }

            // Create the render image
            RenderImage image = new RenderImage(window.Width, window.Height);

            // Load a background image to display
            Sprite background = new Sprite(new Image("resources/background.jpg"));
            background.Image.Smooth = false;

            // Load a sprite which we'll move into the scene
            Sprite entity = new Sprite(new Image("resources/sprite.png"));

            // Load the text font
            Font font = new Font("resources/arial.ttf");

            // Load the image needed for the wave effect
            Image waveImage = new Image("resources/wave.jpg");

            // Load all effects
            shaders = new Dictionary<string, Shader>();
            shaders["nothing"]  = new Shader("resources/nothing.sfx");
            shaders["blur"]     = new Shader("resources/blur.sfx");
            shaders["colorize"] = new Shader("resources/colorize.sfx");
            shaders["fisheye"]  = new Shader("resources/fisheye.sfx");
            shaders["wave"]     = new Shader("resources/wave.sfx");
            shaders["pixelate"] = new Shader("resources/pixelate.sfx");
            backgroundShader = new ShaderSelector(shaders);
            entityShader     = new ShaderSelector(shaders);
            globalShader     = new ShaderSelector(shaders);

            // Do specific initializations
            shaders["nothing"].SetTexture("texture", Shader.CurrentTexture);
            shaders["blur"].SetTexture("texture", Shader.CurrentTexture);
            shaders["blur"].SetParameter("offset", 0.0F);
            shaders["colorize"].SetTexture("texture", Shader.CurrentTexture);
            shaders["colorize"].SetParameter("color", 1.0F, 1.0F, 1.0F);
            shaders["fisheye"].SetTexture("texture", Shader.CurrentTexture);
            shaders["wave"].SetTexture("texture", Shader.CurrentTexture);
            shaders["wave"].SetTexture("wave", waveImage);
            shaders["pixelate"].SetTexture("texture", Shader.CurrentTexture);

            // Define a string for displaying current effect description
            shaderText = new Text();
            shaderText.Font = font;
            shaderText.Size = 20;
            shaderText.Position = new Vector2(5.0F, 0.0F);
            shaderText.Color = new Color(250, 100, 30);
            shaderText.DisplayedString = "Background shader: \"" + backgroundShader.Name + "\"\n" +
                                         "Flower shader: \"" + entityShader.Name + "\"\n" +
                                         "Global shader: \"" + globalShader.Name + "\"\n";

            // Define a string for displaying help
            Text infoText = new Text();
            infoText.Font = font;
            infoText.Size = 20;
            infoText.Position = new Vector2(5.0F, 500.0F);
            infoText.Color = new Color(250, 100, 30);
            infoText.DisplayedString = "Move your mouse to change the shaders' parameters\n" +
                                       "Press numpad 1 to change the background shader\n" +
                                       "Press numpad 2 to change the flower shader\n" +
                                       "Press numpad 3 to change the global shader";

            // Start the game loop
            float time = 0.0F;
            while (window.IsOpened())
            {
                // Process events
                window.DispatchEvents();

                // TOFIX -- using window.Input together with image.Draw apparently causes a memory corruption
                // Get the mouse position in the range [0, 1]
                //float x = window.Input.GetMouseX() / (float)window.Width;
                //float y = window.Input.GetMouseY() / (float)window.Height;
                float x = (float)(Math.Cos(time * 1.3) + 1) * 0.5F;
                float y = (float)(Math.Sin(time * 0.8) + 1) * 0.5F;

                // Update the shaders
                backgroundShader.Update(x, y);
                entityShader.Update(x, y);
                globalShader.Update(x, y);

                // Animate the sprite
                time += window.GetFrameTime();
                float entityX = (float)(Math.Cos(time * 1.3) + 1.2) * 300;
                float entityY = (float)(Math.Cos(time * 0.8) + 1.2) * 200;
                entity.Position = new Vector2(entityX, entityY);
                entity.Rotation = time * 100;

                // Draw the background and the moving entity to the render image
                image.Draw(background, backgroundShader.Shader);
                image.Draw(entity, entityShader.Shader);
                image.Display();

                // Draw the contents of the render image to the window
                window.Draw(new Sprite(image.Image), globalShader.Shader);

                // Draw interface texts
                window.Draw(shaderText);
                window.Draw(infoText);

                // Finally, display the rendered frame on screen
                window.Display();
            }
        }
예제 #18
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Draw something into the window with a shader
 /// </summary>
 /// <param name="objectToDraw">Object to draw</param>
 /// <param name="shader">Shader to apply</param>
 ////////////////////////////////////////////////////////////
 public void Draw(Drawable objectToDraw, Shader shader)
 {
     objectToDraw.Render(this, shader);
 }
예제 #19
0
        public WaveBlur()
            : base("wave + blur")
        {
            // Create the text
            myText = new Text();
            myText.DisplayedString = "Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n" +
                                     "Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n" +
                                     "Praesent cursus ultrices justo, ut feugiat ante vehicula quis.\n" +
                                     "Donec fringilla scelerisque mauris et viverra.\n" +
                                     "Maecenas adipiscing ornare scelerisque. Nullam at libero elit.\n" +
                                     "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n" +
                                     "Nullam leo urna, tincidunt id semper eget, ultricies sed mi.\n" +
                                     "Morbi mauris massa, commodo id dignissim vel, lobortis et elit.\n" +
                                     "Fusce vel libero sed neque scelerisque venenatis.\n" +
                                     "Integer mattis tincidunt quam vitae iaculis.\n" +
                                     "Vivamus fringilla sem non velit venenatis fermentum.\n" +
                                     "Vivamus varius tincidunt nisi id vehicula.\n" +
                                     "Integer ullamcorper, enim vitae euismod rutrum, massa nisl semper ipsum,\n" +
                                     "vestibulum sodales sem ante in massa.\n" +
                                     "Vestibulum in augue non felis convallis viverra.\n" +
                                     "Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n" +
                                     "Duis erat eros, porta in accumsan in, blandit quis sem.\n" +
                                     "In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n";
            myText.Font = GetFont();
            myText.CharacterSize = 22;
            myText.Position = new Vector2f(30, 20);

            // Load the shader
            myShader = new Shader("resources/wave.vert", "resources/blur.frag");
        }
예제 #20
0
        public StormBlink()
            : base("storm + blink")
        {
            Random random = new Random();

            // Create the points
            myPoints = new VertexArray(PrimitiveType.Points);
            for (int i = 0; i < 40000; ++i)
            {
                float x = (float)random.Next(0, 800);
                float y = (float)random.Next(0, 600);
                byte r = (byte)random.Next(0, 255);
                byte g = (byte)random.Next(0, 255);
                byte b = (byte)random.Next(0, 255);
                myPoints.Append(new Vertex(new Vector2f(x, y), new Color(r, g, b)));
            }

            // Load the shader
            myShader = new Shader("resources/storm.vert", "resources/blink.frag");
        }
예제 #21
0
파일: Shader.cs 프로젝트: AlexSolari/Evo
 /// <summary>
 /// Creates a Shader using a file as the source for the vertex and fragment shader.
 /// </summary>
 /// <param name="vertexFile">The file path to the vertex shader.</param>
 /// <param name="fragmentFile">The file path to the fragment shader.</param>
 public Shader(string vertexFile, string fragmentFile)
 {
     shader = new SFML.Graphics.Shader(vertexFile, fragmentFile);
 }
예제 #22
0
        /// <summary>
        /// Draws a raw <see cref="SFML.Graphics.Sprite"/>. Recommended to avoid using when possible, but when needed,
        /// can provide a slight performance boost when drawing a large number of sprites with identical state.
        /// </summary>
        /// <param name="sprite">The <see cref="SFML.Graphics.Sprite"/> to draw.</param>
        /// <param name="shader">The <see cref="Shader"/> to use while drawing.</param>
        public virtual void Draw(SFML.Graphics.Sprite sprite, Shader shader = null)
        {
            if (sprite == null || !IsAssetValid(sprite.Image))
                return;

            _rt.Draw(sprite, shader);
        }
예제 #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WaterRefractionEffect"/> class.
        /// </summary>
        /// <param name="waveNoise">The sprite to use for the wave noise.</param>
        /// <param name="position">The initial world position of the effect.</param>
        /// <param name="size">The size of the effect in pixels.</param>
        /// <param name="shader">The <see cref="Shader"/> to use to draw the water's refraction map. If null, the
        /// <see cref="WaterRefractionEffect.DefaultShader"/> will be used. If you provide your own shader, you must
        /// make sure that you either use the same effect parameters the default shader uses, or override this class
        /// so you can override the <see cref="WaterRefractionEffect.SetShaderParameters"/> method and set the parameters
        /// you require.</param>
        /// <exception cref="ArgumentNullException"><paramref name="waveNoise"/> is null.</exception>
        public WaterRefractionEffect(Grh waveNoise, Vector2 position, Vector2 size, Shader shader = null)
        {
            if (waveNoise == null)
                throw new ArgumentNullException("waveNoise");

            _waveNoise = waveNoise;
            _position = position;
            _size = size;

            _shader = shader ?? DefaultShader;

            // Copy over the default values
            WaveIntensity = DefaultWaveIntensity;
            WaveSpeed = DefaultWaveSpeed;
            WaterAlpha = DefaultWaterAlpha;
            Magnification = DefaultMagnification;
            IsEnabled = true;

            // Ensure we are able to use the effect
            if (_shader == null)
            {
                const string errmsg =
                    "Shaders not supported or unable to acquire a valid default shader. Expiring effect `{0}`...";
                if (log.IsInfoEnabled)
                    log.InfoFormat(errmsg, this);
                Dispose();
            }
        }
예제 #24
0
        /// <summary>
        /// Adds a mutable sprite string to the batch of sprites to be rendered, specifying the font, output text,
        /// screen position, color tint, rotation, origin, scale, effects, and depth.
        /// </summary>
        /// <param name="font">The <see cref="Font"/> to use to draw.</param>
        /// <param name="text">The string to draw.</param>
        /// <param name="position">The location, in screen coordinates, where the text will be drawn.</param>
        /// <param name="color">The desired color of the text.</param>
        /// <param name="rotation">The angle, in radians, to rotate the text around the origin.</param>
        /// <param name="origin">The origin of the string. Specify (0,0) for the upper-left corner.</param>
        /// <param name="scale">Vector containing separate scalar multiples for the x- and y-axes of the sprite.</param>
        /// <param name="style">How to style the drawn string.</param>
        /// <param name="shader">The shader to use on the text being drawn.</param>
        public virtual void DrawString(Font font, string text, Vector2 position, Color color, float rotation, Vector2 origin,
                                       Vector2 scale, Text.Styles style = Text.Styles.Regular, Shader shader = null)
        {
            if (!IsAssetValid(font) || string.IsNullOrEmpty(text))
                return;

            _str.Font = font;
            _str.DisplayedString = text;
            _str.Position = position;
            _str.Color = color;
            _str.Rotation = rotation;
            _str.Origin = origin;
            _str.Scale = scale;
            _str.Style = style;
            _str.CharacterSize = font.DefaultSize;

            _rt.Draw(_str, shader);
        }
예제 #25
0
 /// <summary>
 /// Adds a sprite to the batch of sprites to be rendered, specifying the texture, destination, and source rectangles,
 /// color tint, rotation, origin, effects, and sort depth.
 /// </summary>
 /// <param name="texture">The sprite texture.</param>
 /// <param name="position">The location, in screen coordinates, where the sprite will be drawn.</param>
 /// <param name="color">The color channel modulation to use. Use <see cref="Color.White"/> for full color with
 /// no tinting.</param>
 /// <param name="shader">The shader to use on the text being drawn.</param>
 public virtual void Draw(Image texture, Vector2 position, Color color, Shader shader = null)
 {
     Draw(texture, position, null, color, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, shader);
 }
예제 #26
0
 /// <summary>
 /// Adds a sprite to the batch of sprites to be rendered, specifying the texture, destination, and source rectangles,
 /// color tint, rotation, origin, effects, and sort depth.
 /// </summary>
 /// <param name="texture">The sprite texture.</param>
 /// <param name="position">The location, in screen coordinates, where the sprite will be drawn.</param>
 /// <param name="sourceRectangle">A rectangle specifying, in texels, which section of the rectangle to draw.
 /// Use null to draw the entire texture.</param>
 /// <param name="color">The color channel modulation to use. Use <see cref="Color.White"/> for full color with
 /// no tinting.</param>
 /// <param name="rotation">The angle, in radians, to rotate the sprite around the origin.</param>
 /// <param name="origin">The origin of the sprite. Specify (0,0) for the upper-left corner.</param>
 /// <param name="scale">Uniform multiple by which to scale the sprite width and height.</param>
 /// <param name="effects">Rotations to apply prior to rendering.</param>
 /// <param name="shader">The shader to use on the text being drawn.</param>
 public virtual void Draw(Image texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation,
                          Vector2 origin, float scale, SpriteEffects effects = SpriteEffects.None, Shader shader = null)
 {
     Draw(texture, position, sourceRectangle, color, rotation, origin, new Vector2(scale), effects, shader);
 }
예제 #27
0
            ////////////////////////////////////////////////////////////
            /// <summary>
            /// Construct a default set of render states with a custom shader
            /// </summary>
            /// <param name="shader">Shader to use</param>
            ////////////////////////////////////////////////////////////
            public RenderStates(Shader shader) :
                this(BlendMode.Alpha, Transform.Identity, null, shader)
            {

            }
예제 #28
0
        /// <summary>
        /// Draws a raw <see cref="Drawable"/> object.
        /// </summary>
        /// <param name="drawable">The object to draw.</param>
        /// <param name="shader">The shader to use on the text being drawn.</param>
        public void Draw(Drawable drawable, Shader shader = null)
        {
            if (drawable == null)
                return;

            _rt.Draw(drawable, shader);
        }
예제 #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WaterRefractionEffect"/> class.
 /// </summary>
 /// <param name="waveNoise">The sprite to use for the wave noise.</param>
 /// <param name="positionProvider">The <see cref="ISpatial"/> that will provide the positioning.</param>
 /// <param name="size">The size of the effect in pixels.</param>
 /// <param name="shader">The <see cref="Shader"/> to use to draw the water's refraction map. If null, the
 /// <see cref="WaterRefractionEffect.DefaultShader"/> will be used. If you provide your own shader, you must
 /// make sure that you either use the same effect parameters the default shader uses, or override this class
 /// so you can override the <see cref="WaterRefractionEffect.SetShaderParameters"/> method and set the parameters
 /// you require.</param>
 /// <exception cref="ArgumentNullException"><paramref name="waveNoise"/> is null.</exception>
 /// <exception cref="NullReferenceException"><paramref name="positionProvider"/> is null.</exception>
 public WaterRefractionEffect(Grh waveNoise, ISpatial positionProvider, Vector2 size, Shader shader = null)
     : this(waveNoise, positionProvider.Position, size, shader)
 {
     PositionProvider = positionProvider;
 }
예제 #30
0
파일: Shader.cs 프로젝트: AlexSolari/Evo
 internal Shader(SFML.Graphics.Shader shader)
 {
     this.shader = shader;
 }
예제 #31
0
        /// <summary>
        /// Adds a mutable sprite string to the batch of sprites to be rendered, specifying the font, output text,
        /// screen position, color tint, rotation, origin, scale, effects, and depth.
        /// </summary>
        /// <param name="font">The <see cref="Font"/> to use to draw.</param>
        /// <param name="text">The string to draw.</param>
        /// <param name="position">The location, in screen coordinates, where the text will be drawn.</param>
        /// <param name="color">The desired color of the text.</param>
        /// <param name="rotation">The angle, in radians, to rotate the text around the origin.</param>
        /// <param name="origin">The origin of the string. Specify (0,0) for the upper-left corner.</param>
        /// <param name="scale">Vector containing separate scalar multiples for the x- and y-axes of the sprite.</param>
        /// <param name="style">How to style the drawn string.</param>
        /// <param name="shader">The shader to use on the text being drawn.</param>
        public virtual void DrawString(Font font, string text, Vector2 position, Color color, float rotation, Vector2 origin,
                                       float scale, Text.Styles style = Text.Styles.Regular, Shader shader = null)
        {
            if (!IsAssetValid(font))
                return;

            DrawString(font, text, position, color, rotation, origin, new Vector2(scale), style, shader);
        }
예제 #32
0
파일: Shader.cs 프로젝트: wtfcolt/game
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the shader from another shader
 /// </summary>
 /// <param name="copy">Shader to copy</param>
 ////////////////////////////////////////////////////////////
 public Shader(Shader copy) :
     base(sfShader_Copy(copy.This))
 {
     foreach (KeyValuePair<string, Image> pair in copy.myTextures)
         myTextures[pair.Key] = copy.myTextures[pair.Key];
 }
예제 #33
0
파일: Shader.cs 프로젝트: AlexSolari/Evo
 /// <summary>
 /// Create a Shader using a stream as the source of the vertex and fragment shader.
 /// </summary>
 /// <param name="vertexStream">The stream for the vertex shader.</param>
 /// <param name="fragmentStream">The stream for the fragment shader.</param>
 public Shader(Stream vertexStream, Stream fragmentStream)
 {
     shader = new SFML.Graphics.Shader(vertexStream, fragmentStream);
 }
예제 #34
0
 /// <summary>
 /// Adds a sprite to the batch of sprites to be rendered, specifying the texture, destination, and source rectangles,
 /// color tint, rotation, origin, effects, and sort depth.
 /// </summary>
 /// <param name="texture">The sprite texture.</param>
 /// <param name="destinationRectangle">A rectangle specifying, in screen coordinates, where the sprite will be drawn.
 /// If this rectangle is not the same size as sourceRectangle, the sprite is scaled to fit.</param>
 /// <param name="color">The color channel modulation to use. Use <see cref="Color.White"/> for full color with
 /// no tinting.</param>
 /// <param name="shader">The shader to use on the text being drawn.</param>
 public virtual void Draw(Image texture, Rectangle destinationRectangle, Color color, Shader shader = null)
 {
     Draw(texture, destinationRectangle, null, color, 0f, Vector2.Zero, SpriteEffects.None, shader);
 }
예제 #35
0
        /// <summary>
        /// Adds a sprite to the batch of sprites to be rendered, specifying the texture, destination, and source rectangles,
        /// color tint, rotation, origin, effects, and sort depth.
        /// </summary>
        /// <param name="texture">The sprite texture.</param>
        /// <param name="position">The location, in screen coordinates, where the sprite will be drawn.</param>
        /// <param name="sourceRectangle">A rectangle specifying, in texels, which section of the rectangle to draw.
        /// Use null to draw the entire texture.</param>
        /// <param name="color">The color channel modulation to use. Use <see cref="Color.White"/> for full color with
        /// no tinting.</param>
        /// <param name="rotation">The angle, in radians, to rotate the sprite around the origin.</param>
        /// <param name="origin">The origin of the sprite. Specify (0,0) for the upper-left corner.</param>
        /// <param name="scale">Vector containing separate scalar multiples for the x- and y-axes of the sprite.</param>
        /// <param name="effects">Rotations to apply prior to rendering.</param>
        /// <param name="shader">The shader to use on the text being drawn.</param>
        public virtual void Draw(Image texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation,
                                 Vector2 origin, Vector2 scale, SpriteEffects effects = SpriteEffects.None, Shader shader = null)
        {
            if (!IsAssetValid(texture))
                return;

            _sprite.Image = texture;
            _sprite.Position = position;
            _sprite.SubRect = sourceRectangle.HasValue
                                  ? (IntRect)sourceRectangle
                                  : new IntRect(0, 0, (int)_sprite.Image.Width, (int)_sprite.Image.Height);
            _sprite.Color = color;
            _sprite.Rotation = MathHelper.ToDegrees(rotation);
            _sprite.Origin = origin;
            _sprite.FlipX((effects & SpriteEffects.FlipHorizontally) != 0);
            _sprite.FlipY((effects & SpriteEffects.FlipVertically) != 0);
            _sprite.Scale = scale;

            _rt.Draw(_sprite, shader);
        }