private void DrawBackground(Graphics.Graphics graphics) { var texture = graphics.GetTexture2DByName("terrain"); int tx, ty; tx = (int)Math.Ceiling((double)graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width / 32); ty = (int)Math.Ceiling((double)graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height / 32); Vector2 textureIndex = new Vector2(13 * Constants.SpriteSize, 7 * Constants.SpriteSize); for (int x = 0; x < tx; x++) for (int y = 0; y < ty; y++) graphics.GetSpriteBatch().Draw(texture, new Vector2(x * Constants.TileSize, y * Constants.TileSize).ToRectangle(), textureIndex.ToRectangle(Constants.SpriteSize), Color.White); }
public BasicLightableSceneWithMap(Graphics.Graphics graphics) : base(graphics) { Map = new MinecraftMap(); _Map.GenerateTestMap(); Camera = new Camera2D(); int x = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width / 2; int y = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height / 2; //minX = x; //minY = y; //maxX = (int)world.WorldSize.X - (MainGame.GlobalGraphicsDeviceManager.PreferredBackBufferWidth / 2); //maxY = (int)world.WorldSize.Y - (MainGame.GlobalGraphicsDeviceManager.PreferredBackBufferHeight / 2); Camera.Position = new Vector2(x + (32 * 32), y + (25 * 32)); }
public BasicLightableScene(Graphics.Graphics graphics) { int width, height; width = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width; height = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height; Camera = new Camera2D(); LightScene = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, width, height); BaseScene = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, width, height); _Entities = new List<IAnimatedEntity>(); _StaticLights = new List<LightSource>(); if (!Minecraft2D.ScaleGame) { graphics.ResolutionChanged += (sender, e) => { Console.WriteLine("[BasicLightableScene] Destroying and recreating render targets."); width = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width; height = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height; LightScene.Dispose(); BaseScene.Dispose(); LightScene = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, width, height); BaseScene = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, width, height); }; } }
public void DrawBaseScene(Graphics.Graphics graphics) { graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(BaseScene); graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(Color.CornflowerBlue); graphics.GetSpriteBatch().Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, transformMatrix: Camera.Transformation(graphics.GetGraphicsDeviceManager().GraphicsDevice)); Map.Draw(graphics, Camera); //Draws the regular entites and their sprites and whatnot. ((List<IAnimatedEntity>)Entities).ForEach(entity => { entity.Draw(graphics); }); graphics.GetSpriteBatch().End(); graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(null); }
public override void Draw(Graphics.Graphics graphics) { graphics.GetSpriteBatch().Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(Color.Black); DrawBackground(graphics); DrawControls(graphics); DrawCursor(graphics); graphics.GetSpriteBatch().End(); }
public void Draw(Graphics.Graphics graphics) { graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(Color.CornflowerBlue); graphics.GetSpriteBatch().Begin(sortMode: Microsoft.Xna.Framework.Graphics.SpriteSortMode.Deferred, /*transformMatrix: Camera.Transformation(graphics.GetGraphicsDeviceManager().GraphicsDevice) ,*/ depthStencilState: DepthStencilState.None, samplerState: SamplerState.PointClamp); Map.Draw(graphics); int tx, ty; tx = (int)Math.Floor(Minecraft2D.InputHelper.MousePosition.X / Constants.TileSize); ty = (int)Math.Floor(Minecraft2D.InputHelper.MousePosition.Y / Constants.TileSize); if(Map.GetTileAtIndex(tx, ty) != null) graphics.GetSpriteBatch().Draw(GetRectangle(graphics), new Rectangle(tx * Constants.TileSize, ty * Constants.TileSize, Constants.TileSize, Constants.TileSize), Color.Gray * .32f); TestPlayer.Draw(graphics); graphics.GetSpriteBatch().End(); }
public new void Draw(Graphics.Graphics graphics) { DrawBaseScene(graphics); DrawLights(graphics); graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(Color.White); graphics.GetSpriteBatch().Begin(blendState: Lighted.Multiply, samplerState: SamplerState.PointClamp); var screenRect = graphics.ScreenRectangle(); graphics.GetSpriteBatch().Draw(BaseScene, screenRect, Color.White); ScreenRect = screenRect; if (RenderLights) graphics.GetSpriteBatch().Draw(LightScene, screenRect, Color.White); graphics.GetSpriteBatch().End(); }
public LightingTest(Graphics.Graphics graphics) { int width, height; width = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width; height = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height; FullyLitWorld = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, width, height); Lightpass = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, width, height); Lights = new List<QuadLightSource>(); graphics.ResolutionChanged += (sender, e) => { width = e.Width; height = e.Height; Console.WriteLine("Destroying lighting test textures."); FullyLitWorld.Dispose(); FullyLitWorld = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, width, height); Lightpass.Dispose(); Lightpass = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, width, height); }; }
public void DrawLights(Graphics.Graphics graphics) { graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(LightScene); graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(AmbientLight); graphics.GetSpriteBatch().Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, transformMatrix: Camera.Transformation(graphics.GetGraphicsDeviceManager().GraphicsDevice)); var texture = graphics.GetTexture2DByName("circle"); ((List<LightSource>)StaticLights).ForEach(light => { graphics.GetSpriteBatch().Draw( texture, light.Size, light.Color ); }); //The dynamic lights foreach (var entity in Entities.Where(x => x is IDynamicLightEntity)) { if (entity is IDynamicLightEntity) { var entityAsLight = (IDynamicLightEntity)entity; var drawingPoint = entityAsLight.Position.ToRectangle(); drawingPoint.Width = texture.Width; drawingPoint.Height = texture.Height; if (entityAsLight.LightSize != 1.0f) { drawingPoint.Width = (int)(drawingPoint.Width * entityAsLight.LightSize); drawingPoint.Height = (int)(drawingPoint.Height * entityAsLight.LightSize); } if (entityAsLight.LightOffset != null) { drawingPoint.X += (int)(entityAsLight.LightOffset.X - (drawingPoint.Width / 2)); drawingPoint.Y += (int)(entityAsLight.LightOffset.Y - (drawingPoint.Height / 2)); } graphics.GetSpriteBatch().Draw(texture, drawingPoint, entityAsLight.LightColor); } } graphics.GetSpriteBatch().End(); graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(null); }
public Texture2D GetRectangle(Graphics.Graphics graphics) { if (_Rectangle == null) { _Rectangle = new Texture2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, 1, 1); _Rectangle.SetData<Color>(new Color[] { Color.White }); } return _Rectangle; }
private Texture2D MakeRectangle(Graphics.Graphics graphics, Color color) { var rectangle = new Texture2D(graphics.GetGraphicsDeviceManager().GraphicsDevice, 1, 1); rectangle.SetData(new[] { color }); return rectangle; }
private void DrawLight(Graphics.Graphics graphics) { graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(Lightpass); graphics.GetSpriteBatch().Begin(blendState: BlendState.Additive); graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(new Color(75, 75, 75, 100)); //ambient light Lights.ForEach(light => { graphics.GetSpriteBatch().Draw(graphics.GetTexture2DByName("circle"), light.rectangle, light.color); }); var point = Minecraft2D.InputHelper.MousePosition.ToPoint(); point.X -= (graphics.GetTexture2DByName("circle").Width / 2); point.Y -= (graphics.GetTexture2DByName("circle").Height / 2); graphics.GetSpriteBatch().Draw(graphics.GetTexture2DByName("circle"), point.ToVector2(), Color.White); graphics.GetSpriteBatch().End(); graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(null); }
private void DrawFullyLit(Graphics.Graphics graphics) { graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(FullyLitWorld); graphics.GetSpriteBatch().Begin(); graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(Color.CornflowerBlue); graphics.GetSpriteBatch().Draw(graphics.GetTexture2DByName("trivium"), new Rectangle(0, 0, 800, 350), Color.White); graphics.GetSpriteBatch().End(); graphics.GetGraphicsDeviceManager().GraphicsDevice.SetRenderTarget(null); }
public override void Draw(Graphics.Graphics graphics) { DrawFullyLit(graphics); DrawLight(graphics); graphics.GetGraphicsDeviceManager().GraphicsDevice.Clear(Color.White); //graphics.GetSpriteBatch().Begin(SpriteSortMode.Deferred, Multiply, null, null, null, null, null); graphics.GetSpriteBatch().Begin(blendState: Multiply, sortMode: SpriteSortMode.Immediate); graphics.GetSpriteBatch().Draw(FullyLitWorld, graphics.ScreenRectangle(), Color.White); if(RenderLight) graphics.GetSpriteBatch().Draw(Lightpass, graphics.ScreenRectangle(), Color.White); graphics.GetSpriteBatch().End(); }