Advertisement
Guest User

Untitled

a guest
May 22nd, 2016
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1. public void DrawStencil(SpriteBatch spriteBatch, GraphicsDeviceManager graphics, Matrix transformMatrix)
  2.         {
  3.             var m = Matrix.CreateOrthographicOffCenter(0,
  4.                 GameWorld.Instance.Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth,
  5.                 GameWorld.Instance.Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight,
  6.                 0, 0, 1
  7.             );
  8.            
  9.             var a = new AlphaTestEffect(GameWorld.Instance.Graphics.GraphicsDevice)
  10.             {
  11.                 Projection = m,
  12.                 VertexColorEnabled = true,
  13.                 ReferenceAlpha = 0,
  14.             };
  15.  
  16.             var s1 = new DepthStencilState
  17.             {
  18.                 StencilEnable = true,
  19.                 StencilFunction = CompareFunction.Always,
  20.                 StencilPass = StencilOperation.Replace,
  21.                 ReferenceStencil = 1,
  22.                 DepthBufferEnable = false,
  23.             };
  24.  
  25.             var s2 = new DepthStencilState
  26.             {
  27.                 StencilEnable = true,
  28.                 StencilFunction = CompareFunction.LessEqual,
  29.                 StencilPass = StencilOperation.Keep,
  30.                 ReferenceStencil = 1,
  31.             };
  32.  
  33.             var goPos = GameWorld.Instance.CurrentLevel.CurrentCamera.WorldToScreenPoint(Transform.WorldPosition);
  34.             var goSize = new Vector2(.7f);
  35.             var origin = _ownRenderer.Size*_ownRenderer.Pivot;
  36.  
  37.             GameWorld.Instance.SpriteBatch.Begin(SpriteSortMode.FrontToBack, depthStencilState: s1, effect: a);
  38.                 spriteBatch.Draw(_ownRenderer.Sprite.Texture,
  39.                         sourceRectangle: _ownRenderer.Sprite.Rect,
  40.                         position: goPos,
  41.                         rotation: Transform.WorldRotation * MathUtils.DegreeToRadian,
  42.                         origin: origin,
  43.                         scale: goSize,
  44.                         color: _ownRenderer.Color,
  45.                         effects: _ownRenderer.Effect);
  46.             GameWorld.Instance.SpriteBatch.End();
  47.  
  48.             GameWorld.Instance.SpriteBatch.Begin(SpriteSortMode.FrontToBack, depthStencilState: s2);
  49.                 spriteBatch.Draw(GameWorld.Instance.Content.Load<Texture2D>("Sprites/Styles/Stripes"),
  50.                         sourceRectangle: _ownRenderer.Sprite.Rect,
  51.                         position: goPos,
  52.                         rotation: Transform.WorldRotation * MathUtils.DegreeToRadian,
  53.                         origin: origin,
  54.                         scale: goSize,
  55.                         color: _ownRenderer.Color,
  56.                         effects: _ownRenderer.Effect);
  57.             GameWorld.Instance.SpriteBatch.End();
  58.  
  59.             graphics.GraphicsDevice.Clear(ClearOptions.Stencil, Color.Gray, 0, 0);
  60.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement