コード例 #1
0
        //Zum Schnee einsammeln von der MAP!
        public bool CollectSnow(Vector2 position)
        {
            if (!CheckPosition(position))
            {
                return(false);
            }

            if (!CheckSnow(position))
            {
                return(false);
            }

            rendTarget.SetData(0, new Rectangle((int)position.X, (int)position.Y, 2, 2), new[] { new Color(0, 0, 0, 0) }, 0, 1);
            snowTiles[(int)position.X, (int)position.Y] = null;

            if (CheckSnow(position + new Vector2(0, -1)))
            {
                AddSnowToMap(GetSnowParticle(position + new Vector2(0, -1)), position);
                CollectSnow(position + new Vector2(0, -1));
            }
            else
            {
                if (CheckSnow(position + new Vector2(-1, -1)))
                {
                    AddSnowToMap(GetSnowParticle(position - new Vector2(1, 1)), position);
                    CollectSnow(position + new Vector2(-1, -1));
                }
                if (CheckSnow(position + new Vector2(1, -1)))
                {
                    AddSnowToMap(GetSnowParticle(position + new Vector2(1, -1)), position);
                    CollectSnow(position + new Vector2(1, -1));
                }
            }
            return(true);
        }
コード例 #2
0
        private void PopulateTileTextureScrolling(Vector2 start, int yToStart, int yToEnd)
        {
            GettingColors = true;
            Color[] tileLightingBuffer = new Color[TileLightingTempTexture.Width * (yToEnd - yToStart)];

            for (int x = 0; x < TileLightingTempTexture.Width; x++)
            {
                for (int y = yToStart; y < yToEnd; y++)
                {
                    int index = (y - yToStart) * TileLightingTempTexture.Width + x;
                    if (tileLightingBuffer.Length > index)
                    {
                        tileLightingBuffer[index] = Lighting.GetColor((int)start.X / 16 + x, (int)start.Y / 16 + y);
                    }
                }
            }

            if (tileLightingBuffer is null || tileLightingBuffer.Length == 0)
            {
                return;
            }

            TileLightingTempTexture.SetData(0, new Rectangle(0, yToStart, TileLightingTempTexture.Width, yToEnd - yToStart), tileLightingBuffer, 0, TileLightingTempTexture.Width * (yToEnd - yToStart));

            if (refreshTimer % config.LightingPollRate == 0)
            {
                TileLightingCenter = start;
            }

            GettingColors = false;
        }
コード例 #3
0
ファイル: Lighting.cs プロジェクト: Cyral/Zarknorth
        /// <summary>
        /// Takes the lighting values for each onscreen tile and draws them to a render target 1/24th (Tile Size) the Size of the scree, to be scaled
        /// and draw later
        /// </summary>
        private void RenderLightingToRT2D(SpriteBatch spriteBatch)
        {
            Stopwatch drawWatch = new Stopwatch();

            drawWatch.Start();

            //If the rendertarget is null, create it at the width and height of the viewport in tiles
            if (LightingTarget == null)
            {
                LightingTarget = new RenderTarget2D(game.GraphicsDevice, MainCamera.Right - MainCamera.Left, MainCamera.Bottom - MainCamera.Top, false, game.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
                spriteBatch.GraphicsDevice.DepthStencilState = new DepthStencilState()
                {
                    DepthBufferEnable = true
                };
                LightingBufferData = new Color[(MainCamera.Right - MainCamera.Left) * (MainCamera.Bottom - MainCamera.Top)];
            }

            //Foreach tile on screen
            for (int x = MainCamera.Left; x < MainCamera.Right; ++x)
            {
                for (int y = MainCamera.Top; y < MainCamera.Bottom; ++y)
                {
                    Tile tile = tiles[x, y, true]; //Get the tile

                    LightingBufferData[(x - MainCamera.Left) + (y - MainCamera.Top) * (MainCamera.Right - MainCamera.Left)] = tile.Light;
                }
            }

            LightingTarget.SetData <Color>(LightingBufferData);
            drawWatch.Stop();
            //if (Interface.MainWindow.DebugList != null)
            //    Interface.MainWindow.DebugList.Items[20] = "   -RenderLigtingToRT2D() " + drawWatch.ElapsedMilliseconds;
        }
コード例 #4
0
ファイル: DrawHelper.cs プロジェクト: Xiro234/StarlightRiver
        private void PopulateTileTexture(Vector2 start)
        {
            try
            {
                gettingColors = true;
                GraphicsDevice graphics           = Main.instance.GraphicsDevice;
                Color[]        tileLightingBuffer = new Color[(XMax) * (YMax)];

                for (int x = 0; x < XMax; x++)
                {
                    for (int y = 0; y < YMax; y++)
                    {
                        int index = y * XMax + x;
                        if (tileLightingBuffer.Length > index)
                        {
                            tileLightingBuffer[index] = Lighting.GetColor((int)start.X / 16 + x, (int)start.Y / 16 + y);
                        }
                    }
                }

                tileLightingTexture.SetData(tileLightingBuffer);
                tileLightingCenter = start + new Vector2(Main.screenWidth, Main.screenHeight) / 2;
                gettingColors      = false;
            }
            catch
            {
                ResizeBuffers();
            }
        }
コード例 #5
0
ファイル: RenderTarget2DTest.cs プロジェクト: zad15c/MonoGame
        public void GetDataMSAA()
        {
            const int size  = 100;
            const int size2 = size * size;
            var       rt    = new RenderTarget2D(gd, size, size, false, SurfaceFormat.Color, DepthFormat.None, 8, RenderTargetUsage.DiscardContents);
            var       data  = new Color[size2];

            // create some arbitrary data here
            for (var i = 0; i < size2; i++)
            {
                data[i] = new Color(new Vector3(1f / (i + 1)));
            }

            rt.SetData(data);

            var returnedData = new Color[size2];

            rt.GetData(returnedData);
            // verify that the gotten data is the same as the data we attempt to set
            for (var i = 0; i < size2; i++)
            {
                Assert.AreEqual(data[i], returnedData[i]);
            }

            rt.Dispose();
        }
コード例 #6
0
        /// <summary>
        /// Return a texture2D of a circle
        /// </summary>
        public static Texture2D Circle(GraphicsDevice gd, Color color, int radius)
        {
            // Create a new texture
            RenderTarget2D boardTexture = new RenderTarget2D(gd, radius * 2, radius * 2);

            Color[] pixarr = new Color[radius * radius * 4];

            for (int x = 0; x < radius * 2; x++)
            {
                for (int y = 0; y < radius * 2; y++)
                {
                    // If the distance from the center is smaller than the radius, fill the pixel
                    float len = new Vector2(x - radius, y - radius).Length();
                    if (len <= radius)
                    {
                        pixarr[x * radius * 2 + y] = color;
                    }
                    else
                    {
                        pixarr[x * radius * 2 + y] = Color.Transparent;
                    }
                }
            }

            boardTexture.SetData(pixarr);
            return(boardTexture);
        }
コード例 #7
0
        RenderTarget2D RenderScreen(GraphicsDevice device, byte[,] screenBuffer, int scaleFactor)
        {
            int            width   = screenBuffer.GetLength(0);
            int            height  = screenBuffer.GetLength(1);
            RenderTarget2D texture = new RenderTarget2D(device, width, height);

            Color[] textureData = new Color[width * height];

            for (int i = 0; i < textureData.Length; i++)
            {
                int textureX = i % width;
                int textureY = i / width;


                if (screenBuffer[textureX, textureY] != 0)
                {
                    textureData[i] = Color.White;
                }
                else
                {
                    textureData[i] = Color.Black;
                }
            }


            GraphicsDevice.Textures[0] = null;
            texture.SetData(textureData);


            return(texture);
        }
コード例 #8
0
ファイル: Recorder.cs プロジェクト: wert007/StealthyGame
        public static RenderTarget2D CopyRenderTarget(RenderTarget2D origin)
        {
            RenderTarget2D result = new RenderTarget2D(origin.GraphicsDevice, origin.Width, origin.Height);

            Color[] data = new Color[origin.Width * origin.Height];
            origin.GetData(data);
            result.SetData(data);
            return(result);
        }
コード例 #9
0
        public void UpdateView()
        {
            if (!_viewDirty)
            {
                return;
            }
            _viewDirty = false;

            _view.SetData <Color>(_colors);
        }
コード例 #10
0
ファイル: Game.cs プロジェクト: MarcStan/renderer
        private static RenderTarget2D CreateRenderTarget(GraphicsDevice device, int w, int h)
        {
            var rt     = new RenderTarget2D(device, w, h, false, SurfaceFormat.Color, DepthFormat.Depth24, 1, RenderTargetUsage.PreserveContents);
            var colors =
                Enumerable.Range(0, w * h)
                .Select(i => Color.White)
                .ToArray();

            rt.SetData(colors);
            return(rt);
        }
コード例 #11
0
        private void PopulateTileTexture(Vector2 start)
        {
            GettingColors = true;
            Color[] tileLightingBuffer = new Color[TileLightingTexture.Width * TileLightingTexture.Height];

            for (int x = 0; x < TileLightingTexture.Width; x++)
            {
                for (int y = 0; y < TileLightingTexture.Height; y++)
                {
                    int index = y * TileLightingTexture.Width + x;
                    if (tileLightingBuffer.Length > index)
                    {
                        tileLightingBuffer[index] = Lighting.GetColor((int)start.X / 16 + x, (int)start.Y / 16 + y);
                    }
                }
            }
            TileLightingTexture.SetData(tileLightingBuffer);
            TileLightingCenter = start;
            GettingColors      = false;
        }
コード例 #12
0
ファイル: Extensions.cs プロジェクト: llenroc/KinectScan
 public static IOEventArgs LoadFromFile(this RenderTarget2D target, string path)
 {
     try
     {
         target.SetData <byte>(File.ReadAllBytes(path));
         return(new IOEventArgs(path, true, null));
     }
     catch (Exception e)
     {
         return(new IOEventArgs(path, false, e.Message));
     }
 }
コード例 #13
0
        /// <summary>
        /// Return a texture2D of a rectangle
        /// </summary>
        public static Texture2D Rect(GraphicsDevice gd, Color color, int width, int height)
        {
            // Create a new texture
            RenderTarget2D boardTexture = new RenderTarget2D(gd, width, height);

            Color[] pixarr = new Color[width * height];
            for (int x = 0; x < width * height; x++)
            {
                pixarr[x] = color;
            }
            boardTexture.SetData(pixarr);
            return(boardTexture);
        }
コード例 #14
0
        public void ShrinkPlatform(int radius)
        {
            List <Rectangle> testRects = new List <Rectangle>();

            int j = -1;

            for (int i = 90; i < 270; i++)
            {
                j++;
                if ((int)(Math.Cos(MathHelper.ToRadians(90 - j)) * radius) + middleWidth - (int)((Math.Cos(MathHelper.ToRadians(i)) * radius) + middleWidth) < 2)
                {
                    continue;
                }

                if (i < 180)
                {
                    testRects.Add(new Rectangle((int)(Math.Cos(MathHelper.ToRadians(i)) * radius) + middleWidth, (int)(Math.Sin(MathHelper.ToRadians(i)) * radius) + middleHeight, (int)(Math.Cos(MathHelper.ToRadians(90 - j)) * radius) * 2, RECT_HEIGHT));
                }
                else if (i < 270)
                {
                    testRects.Add(new Rectangle((int)(Math.Cos(MathHelper.ToRadians(i)) * radius) + middleWidth, (int)(Math.Sin(MathHelper.ToRadians(i)) * radius) + middleHeight, (int)(Math.Cos(MathHelper.ToRadians(90 - j)) * radius) * 2, RECT_HEIGHT));
                }
            }

            Color[] transparentField = new Color[renderTarget.Width * renderTarget.Height];
            renderTarget.GetData <Color>(transparentField);
            for (int i = 0; i < transparentField.Length; i++)
            {
                transparentField[i] = Color.Transparent;
            }

            renderTarget.SetData <Color>(originalLava);

            foreach (Rectangle lavaRects in testRects)
            {
                renderTarget.SetData(0, lavaRects, transparentField, 0, lavaRects.Width * lavaRects.Height);
            }
        }
コード例 #15
0
ファイル: WebView.cs プロジェクト: CarimA/RPG
        private void Update()
        {
            _renderer.Update();
            _renderer.Render();

            var surface     = _view.GetSurface();
            var dirtyBounds = surface.GetDirtyBounds();

            if (!dirtyBounds.IsEmpty())
            {
                surface.ClearDirtyBounds();

                var bitmap = surface.GetBitmap();
                var pixels = bitmap.LockPixels();
                var size   = (int)(bitmap.GetWidth() * bitmap.GetHeight() * bitmap.GetBpp());

                if (_pixels == null || _pixels.Length != size)
                {
                    _pixels = new byte[size];
                }

                /*unsafe
                 * {
                 * fixed (byte* dest = &_pixels[0])
                 * {
                 *  // srcPtr and destPtr are IntPtr's pointing to valid memory locations
                 *  // size is the number of long (normally 4 bytes) to copy
                 *  byte* src = (long*) pixels;
                 *  for (int i = 0; i < size / sizeof(long); i++)
                 *  {
                 *      dest[i] = src[i];
                 *  }
                 * }
                 * }*/

                unsafe
                {
                    fixed(void *dest = &_pixels[0])
                    {
                        System.Buffer.MemoryCopy(pixels.ToPointer(), dest, size, size);
                    }
                }

                //Marshal.Copy(pixels, _pixels, 0, size);
                bitmap.UnlockPixels();

                _renderTarget.SetData(_pixels);
                _filter.Filter(ref _finalRenderTarget, _spriteBatch, _renderTarget);
            }
        }
コード例 #16
0
ファイル: LiquidSystem.cs プロジェクト: XZelnar/MicroWorld
        //TODO optimize
        public void Render(RenderTarget2D fbo, RenderTarget2D bufferFBO, Renderer renderer, Texture2D distortionTexture = null)
        {
            if (fbo == null || bufferFBO == null || fbo.Width != W || fbo.Height != H || bufferFBO.Width != W || bufferFBO.Height != H)
            {
                return;
            }
            if (distortionTexture == null)
            {
                distortionTexture = MicroWorld.Graphics.Effects.Effects.liquidDistortionTexture;
            }

            bool b    = renderer.IsDrawing;
            bool s    = renderer.IsScaeld;
            var  cfbo = renderer.CurFBO;

            if (b)
            {
                renderer.End();
            }
            if (cfbo == bufferFBO)
            {
                renderer.DisableFBO();
            }
            renderer.GraphicsDevice.Textures[0] = null;

            Color[] fboarr = new Color[W * H];

            fixed(TileMapElement *ptrmap = tileMap)
            fixed(Color * ptrfbo = fboarr)
            {
                for (int x = 0; x < W; x++)
                {
                    for (int y = 0; y < H; y++)
                    {
                        *(ptrfbo + x + y * W) = (*(ptrmap + y + x * H)).level <= 1 ? Color.Transparent : Color.White;
                    }
                }
            }
            bufferFBO.SetData <Color>(fboarr);

            renderer.EnableFBO(fbo);
            renderer.GraphicsDevice.Clear(Color.Transparent);
            _setUpShader(distortionTexture);
            renderer.BeginUnscaled(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, RasterizerState.CullNone,
                                   MicroWorld.Graphics.Effects.Effects.liquid);
            renderer.Draw(bufferFBO, new Vector2(), new Color(0, 108, 255));
            renderer.End();

            if (cfbo == fbo)
                renderer.EnableFBO(bufferFBO); }
コード例 #17
0
ファイル: Sprite.cs プロジェクト: filgreen3/MonoEmpty
        public override void Inicial()
        {
            base.Inicial();

            GetTransform = gameObject.GetComponent <Transform2D>();
            if (texture != null)
            {
                pic = new Color[texture.Width * texture.Height];
                texture.GetData(pic);
                saveTexture = new RenderTarget2D(texture.GraphicsDevice, texture.Width, texture.Height);

                GetTransform.SetPosition(new Vector2(texture.Width, texture.Height));

                saveTexture.SetData(pic);
            }
        }
コード例 #18
0
        /// <summary>
        /// Generates the specified chunk.
        /// </summary>
        /// <param name="location">Which chunk to generate.</param>
        public void GenerateChunk(Vector2 location)
        {
            // Fill the terrain with a tile
            graphicsDevice.SetRenderTarget(renderTarget);
            spriteBatch.Begin();
            {
                for (int x = 0; x <= renderTarget.Width; x += tile.Width)
                {
                    for (int y = 0; y <= renderTarget.Height; y += tile.Height)
                    {
                        spriteBatch.Draw(tile, new Vector2(x, y), Color.White);
                    }
                }
            }
            spriteBatch.End();

            // Carve out terrain
            var colorData = new Color[renderTarget.Width * renderTarget.Height];

            renderTarget.GetData <Color>(colorData);
            var heightMap = new float[renderTarget.Width];

            for (int x = 0; x < renderTarget.Width; x += 1)
            {
                var pn = noise.Evaluate(0.001f * (x + location.X * Terrain.ChunkWidth), 1f) * 500f + 1000f;
                heightMap[x] = (int)pn;
                // Carve out terrain
                int y;
                for (y = (int)location.Y * Terrain.ChunkHeight; y < pn; y++)
                {
                    colorData[x + y * renderTarget.Width] = Color.Transparent;
                }
            }
            renderTarget.SetData <Color>(colorData);
            colorData = null;

            // Draw borders
            drawBorders(location, heightMap);
            graphicsDevice.SetRenderTarget(null);

            // Create the collider
            createCollider(location);

            Terrain.ApplyTexture(renderTarget, new Vector2(location.X * Terrain.ChunkWidth,
                                                           location.Y * Terrain.ChunkHeight), BlendState.Opaque, null);
        }
コード例 #19
0
        public static void endDrawing()
        {
            spriteBatch.End();

            graphics.GraphicsDevice.SetRenderTarget(null);
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

            Color[] colorArray = new Color[screenDump.Width * screenDump.Height];
            screenDump.GetData <Color>(colorArray);
            colorArray = applyEffect(colorArray);
            screenDump.SetData <Color>(colorArray);
            spriteBatch.Begin();

            spriteBatch.Draw(screenDump, new Vector2(0, 0), Color.White);

            spriteBatch.End();
        }
コード例 #20
0
ファイル: Map.cs プロジェクト: MIUSST/HeatMap_2
        public void GenerateRandomHeight()
        {
            if (_generating)
            {
                return;
            }
            _generating = true;
            Array2D array      = new Array2D(width, height, 0);
            Action  onComplete = () =>
            {
                intensityTexture.SetData(array.AsAlphaMap());
                _dirty      = true;
                _generating = false;
            };

            MapGenerator.ThreadedGenerateRandomHeight(array, MapGenerator.HeightFunction, onComplete);
        }
コード例 #21
0
        private unsafe void UpdateFBO()
        {
            Components.Logics.DelayerLogics l = (Components.Logics.DelayerLogics)parent.Logics;
            bool b = false;

            fixed(Color *a = fboarr)
            {
                for (int x = 0; x < fbo.Width; x++)
                {
                    b = l.signals[x * l.Delay / fbo.Width] > 2.5f;

                    *(a + x) = b ? Color.Red : Color.DarkRed;
                }
            }

            fbo.SetData <Color>(fboarr);
        }
コード例 #22
0
        /// <summary>
        /// Creates an ugly texture that changes color from top to bottom: white, brown, green, light brown (snow, dirt, gras and sand).
        /// Uses noise to make dirt, gras and sand look somewhat ok.
        /// </summary>
        /// <returns></returns>
        public Texture2D CreateTerrainTexture()
        {
            var texture = new RenderTarget2D(_graphicsDevice, 1024, 1024);
            var pixels  = new Color[texture.Width * texture.Height];

            var tc1 = Color.Snow;
            var tc2 = Color.SaddleBrown;
            var tc3 = Color.LawnGreen;
            var tc4 = Color.SandyBrown;

            var targetLevel1 = .8f;
            var targetLevel2 = .5f;
            var targetLevel3 = .2f;

            for (int y = 0; y < texture.Height; y++)
            {
                var   hProgress = y / (float)texture.Height;
                Color color;
                if (hProgress > targetLevel1)
                {
                    color = tc1;
                }
                else if (hProgress > targetLevel2)
                {
                    color = tc2;
                }
                else if (hProgress > targetLevel3)
                {
                    color = tc3;
                }
                else
                {
                    color = tc4;
                }
                for (int x = 0; x < texture.Width; x++)
                {
                    int i = x + y * texture.Width;
                    pixels[i] = color;
                }
            }
            texture.SetData(pixels);
            return(texture);
        }
コード例 #23
0
        internal unsafe void UpdateFBO()
        {
            //Shortcuts.renderer.Push();
            //Shortcuts.renderer.EnableFBO(fbo);
            //Shortcuts.renderer.Clear(Color.Transparent);
            //Shortcuts.renderer.DisableFBO();
            //Shortcuts.renderer.Pop();
            Shortcuts.renderer.GraphicsDevice.Textures[0] = null;

            Components.Logics.VoltageGraphLogics l = (Components.Logics.VoltageGraphLogics)parent.Logics;

            double y = 0;
            double d = l.max - l.min;

            fixed(Color *a = fboarr)
            {
                for (int i = 0; i < fboarr.Length; i++)
                {
                    *(a + i) = Color.Transparent;
                }

                for (int x = 0; x < fbo.Width; x++)
                {
                    y = l.values[x];
                    if (y > l.max)
                    {
                        *(a + x) = Color.White;
                    }
                    else if (y < l.min)
                    {
                        *(a + x + fbo.Width * (fbo.Height - 1)) = Color.White;
                    }
                    else
                    {
                        y = (1 - (y - l.min) / d) * (fbo.Height - 2);
                        *(a + x + fbo.Width * (int)y)       = Color.White;
                        *(a + x + fbo.Width * (int)(y + 1)) = Color.White;
                    }
                }
            }

            fbo.SetData <Color>(fboarr);
        }
コード例 #24
0
        /// <summary>
        /// Creates a skybox texture which is essentially a texture that starts of blue at the bottom and becomes brighter towards the top.
        /// </summary>
        /// <returns></returns>
        public Texture2D CreateSkyboxTexture()
        {
            var texture = new RenderTarget2D(_graphicsDevice, 512, 512);
            var pixels  = new Color[texture.Width * texture.Height];

            for (int y = 0; y < texture.Height; y++)
            {
                for (int x = 0; x < texture.Width; x++)
                {
                    int       i = x + y * texture.Width;
                    const int b = 255;
                    // basic blue gradient from bottom to top for now
                    int g;
                    var r = g = (int)((float)(texture.Height - y) / texture.Height * 128 + 127);
                    pixels[i] = Color.FromNonPremultiplied(r, g, b, 255);
                }
            }
            texture.SetData(pixels);
            return(texture);
        }
コード例 #25
0
        public override void Draw(RenderTarget2D renderTarget, ITracingOptions tracingOptions, GameTime gameTime)
        {
            if (_buffer == null ||
                _buffer.Length != renderTarget.Width * renderTarget.Height)
            {
                _buffer = new Color[renderTarget.Width * renderTarget.Height];
            }

            for (int y = 0; y < renderTarget.Height; y++)
            {
                for (int x = 0; x < renderTarget.Width; x++)
                {
                    var ray = tracingOptions.Camera.GetRayForRasterPosition(x, y, renderTarget.Width - 1, renderTarget.Height - 1);
                    _buffer[x + y * renderTarget.Width] = CastRay(ray, tracingOptions);
                }
            }

            // TODO: SetData perf is "horrible"
            // compare against pixel/line drawing
            renderTarget.SetData(_buffer);
        }
コード例 #26
0
        public void Render(VideoBuffer videoBuffer)
        {
            if (GraphicsDevice == null)
            {
                return;
            }

            if (RenderTarget2D == null)
            {
                RenderTarget2D = RenderTarget2D.New(GraphicsDevice, videoBuffer.Width, videoBuffer.Height, PixelFormat.B8G8R8A8.UNorm);
            }
            else if (RenderTarget2D != null && (RenderTarget2D.Width != videoBuffer.Width || RenderTarget2D.Height != videoBuffer.Height))
            {
                RenderTarget2D.Dispose();
                RenderTarget2D = null;
                RenderTarget2D = RenderTarget2D.New(GraphicsDevice, videoBuffer.Width, videoBuffer.Height, PixelFormat.B8G8R8A8.UNorm);
            }

            if (RenderTarget2D != null)
            {
                var x    = 0;
                var data = videoBuffer.Plane.Data;
                var argb = new int[videoBuffer.Width * videoBuffer.Height];
                for (var i = 0; i < argb.Length; i++)
                {
                    var r = data[x++];
                    var g = data[x++];
                    var b = data[x++];
                    var a = data[x++];
                    argb[i] = ((a & 0xFF) << 24) |
                              ((r & 0xFF) << 16) |
                              ((g & 0xFF) << 8) |
                              ((b & 0xFF) << 0);
                }

                RenderTarget2D.SetData <int>(argb);
            }
        }
コード例 #27
0
ファイル: Graphical.cs プロジェクト: XZelnar/MicroWorld
        public static void InvertGradient(RenderTarget2D textureInput, ref RenderTarget2D textureOutput, float state,
                                          Color c1, Color c2)
        {
            if (textureInput.Width != textureOutput.Width || textureInput.Height != textureOutput.Height)
            {
                throw new Exception("Textures must be the same size!");
            }

            Color[] c = new Color[textureInput.Width * textureInput.Height];
            textureInput.GetData <Color>(c);

            float cr = (float)(c1.R + c2.R) / 2 / 255;
            float cg = (float)(c1.G + c2.G) / 2 / 255;
            float cb = (float)(c1.B + c2.B) / 2 / 255;

            float dr = (float)(c1.R - c2.R) / 255;
            float dg = (float)(c1.G - c2.G) / 255;
            float db = (float)(c1.B - c2.B) / 255;

            float tr, tg, tb;

            for (int i = 0; i < c.Length && c[i].A != 0; i++)
            {
                tr = (float)c[i].R / 255;
                tg = (float)c[i].G / 255;
                tb = (float)c[i].B / 255;

                tr = tr - (tr - cr) * 2 * state;
                tg = tg - (tg - cg) * 2 * state;
                tb = tb - (tb - cb) * 2 * state;

                c[i].R = (byte)(tr * 255);
                c[i].G = (byte)(tg * 255);
                c[i].B = (byte)(tb * 255);
            }

            textureOutput.SetData <Color>(c);
        }
コード例 #28
0
        private RenderTarget2D CloneRenderTarget(RenderTarget2D target)
        {
            var clone = new RenderTarget2D(target.GraphicsDevice, target.Width,
                                           target.Height, target.LevelCount > 1, target.Format,
                                           target.DepthStencilFormat, target.MultiSampleCount,
                                           target.RenderTargetUsage);

            for (int i = 0; i < target.LevelCount; i++)
            {
                double rawMipWidth  = target.Width / Math.Pow(2, i);
                double rawMipHeight = target.Height / Math.Pow(2, i);

                // make sure that mipmap dimensions are always > 0.
                int mipWidth  = (rawMipWidth < 1) ? 1 : (int)rawMipWidth;
                int mipHeight = (rawMipHeight < 1) ? 1 : (int)rawMipHeight;

                var mipData = new Color[mipWidth * mipHeight];
                target.GetData(i, null, mipData, 0, mipData.Length);
                clone.SetData(i, null, mipData, 0, mipData.Length);
            }

            return(clone);
        }
コード例 #29
0
 internal void PrintScreen()
 {
     using (SaveFileDialog dialog = new SaveFileDialog())
     {
         dialog.DefaultExt       = "png";
         dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
         dialog.Filter           = $"{Catalog.GetString("Image files (*.png)")}|*.png";
         if (dialog.ShowDialog() == DialogResult.OK)
         {
             byte[]         backBuffer     = new byte[graphicsDeviceManager.PreferredBackBufferWidth * graphicsDeviceManager.PreferredBackBufferHeight * 4];
             GraphicsDevice graphicsDevice = graphicsDeviceManager.GraphicsDevice;
             using (RenderTarget2D screenshot = new RenderTarget2D(graphicsDevice, graphicsDeviceManager.PreferredBackBufferWidth, graphicsDeviceManager.PreferredBackBufferHeight, false, graphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None))
             {
                 graphicsDevice.GetBackBufferData(backBuffer);
                 screenshot.SetData(backBuffer);
                 using (FileStream stream = File.OpenWrite(dialog.FileName))
                 {
                     screenshot.SaveAsPng(stream, graphicsDeviceManager.PreferredBackBufferWidth, graphicsDeviceManager.PreferredBackBufferHeight);
                 }
             }
         }
     }
 }
コード例 #30
0
        /// <summary>
        /// Render the drawing onto the target.
        /// </summary>
        public void Render()
        {
            //Set data.
            Target.SetData(ColorCache);

            //Start draw batch.
            DrawBatch.Begin(DrawSortMode.Deferred);

            Vector2 origin     = new Vector2(200, 200);
            float   startAngle = (float)(Math.PI / 16) * 25; // 11:20
            float   arcLength  = (float)(Math.PI / 16) * 30;

            DrawBatch.FillCircle(new SolidColorBrush(Color.SkyBlue), origin, 175);
            DrawBatch.FillArc(new SolidColorBrush(Color.LimeGreen), origin, 150,
                              startAngle, arcLength, ArcType.Sector);
            DrawBatch.DrawClosedArc(new Pen(Color.Green, 15), origin, 150,
                                    startAngle, arcLength, ArcType.Sector);

            //Draw active tool.
            ActiveTool.Draw();

            //End draw batch.
            DrawBatch.End();
        }