public void Render(ITessellator tessellator) { var color = tessellator.CurrentColor; // TODO: If this is an entity tile, then don't adjust the color...? // This will cause tile images to become darker as they move into the background layers. var layer = -tessellator.Transform(Vector3.Zero).Z; if (layer < _numChunkLayers) { var multiplier = 1.0 - (_numChunkLayers - layer) / (_numChunkLayers * 2); // + 0.25f; tessellator.BindColor(Color.FromArgb((int)MathHelper.Clamp(color.R * multiplier, 0, 255), (int)MathHelper.Clamp(color.G * multiplier, 0, 255), (int)MathHelper.Clamp(color.B * multiplier, 0, 255))); } if (Transform != null) { tessellator.PushTransform(); Transform.Apply(tessellator); _tileSet.Render(tessellator, TileIndex, Transform.MirrorX, Transform.MirrorY); tessellator.PopTransform(); } else { _tileSet.Render(tessellator, TileIndex); } tessellator.BindColor(color); }
public override void Render() { base.Render(); _hudCamera.Apply(); _tessellator.Begin(PrimitiveType.Quads); _tessellator.LoadIdentity(); _tessellator.Translate(0, 0, -10); _tessellator.BindTexture(null); _tessellator.BindColor(Color.FromArgb(64, Color.Black)); _tessellator.AddPoint(_hudCamera.Projection.Left, _hudCamera.Projection.Top); _tessellator.AddPoint(_hudCamera.Projection.Left, _hudCamera.Projection.Bottom); _tessellator.AddPoint(_hudCamera.Projection.Right, _hudCamera.Projection.Bottom); _tessellator.AddPoint(_hudCamera.Projection.Right, _hudCamera.Projection.Top); _tessellator.BindColor(Color.White); var scale = new Vector2(_ascii.Width, _ascii.Height) * 4; _tessellator.Scale(scale.X, scale.Y); _tessellator.Translate(-scale.X * PAUSE_MESSAGE.Length / 2, -scale.Y / 2); _ascii.RenderText(_tessellator, PAUSE_MESSAGE); _tessellator.End(); //_writer.Write(PAUSE_MESSAGE); }
public override void Render(ITessellator tessellator, IChunkAccess chunk, ChunkLayer layer, int x, int y) { base.Render(tessellator, chunk, layer, x, y); var color = tessellator.CurrentColor; tessellator.BindColor(OutlineColor); if (chunk[layer, x - 1, y] != chunk[layer, x, y]) { _connectedWallTiles.Render(tessellator, _connectedWallTiles.GetTileIndexFromName(_westWall)); } if (chunk[layer, x + 1, y] != chunk[layer, x, y]) { _connectedWallTiles.Render(tessellator, _connectedWallTiles.GetTileIndexFromName(_eastWall)); } if (chunk[layer, x, y - 1] != chunk[layer, x, y]) { _connectedWallTiles.Render(tessellator, _connectedWallTiles.GetTileIndexFromName(_northWall)); } if (chunk[layer, x, y + 1] != chunk[layer, x, y]) { _connectedWallTiles.Render(tessellator, _connectedWallTiles.GetTileIndexFromName(_southWall)); } tessellator.BindColor(color); }
protected override void RenderContent(ITessellator tessellator) { if (Shadowed) { tessellator.Translate(1, 1); tessellator.BindColor(ShadowColor); UI_ASCII.RenderText(tessellator, Text); tessellator.Translate(-1, -1); } tessellator.BindColor(TextColor); UI_ASCII.RenderText(tessellator, Text); }
public override void Render() { base.Render(); _hudCamera.Apply(); _tessellator.Begin(PrimitiveType.Quads); _tessellator.LoadIdentity(); _tessellator.Translate(0, 0, 10); var scale = new Vector2(_ascii.Width, _ascii.Height) * 2; _tessellator.Scale(scale.X, scale.Y); var alpha = 255; _tessellator.Translate(_hudCamera.Projection.Left, _hudCamera.Projection.Bottom - scale.Y); foreach (var message in _progressMessages) { _tessellator.BindColor(Color.FromArgb(alpha, Color.White)); _ascii.RenderText(_tessellator, message); _tessellator.Translate(0, -scale.Y); alpha = MathHelper.Clamp(alpha - 8, 0, 255); } _tessellator.End(); }
private void RenderFieldOfView(int[,] fovMap, ITessellator tessellator, Camera <OrthographicProjection> camera, IChunkAccess chunk, int minX, int maxX, int minY, int maxY) { tessellator.PushTransform(); tessellator.Translate(0, 0, -1 * (int)ChunkLayer.Lights); tessellator.BindTexture(null); for (var y = 0; y < fovMap.GetLength(0); y++) { for (var x = 0; x < fovMap.GetLength(1); x++) { if (fovMap[y, x] == 255) { continue; } tessellator.BindColor(Color.FromArgb(255 - fovMap[y, x], 0, 0, 0)); tessellator.Translate(minX + x, minY + y); tessellator.AddPoint(0, 0); tessellator.AddPoint(0, 1); tessellator.AddPoint(1, 1); tessellator.AddPoint(1, 0); tessellator.Translate(-(minX + x), -(minY + y)); } } tessellator.PopTransform(); }
public void Render(Camera <OrthographicProjection> camera, PlayerEntity player, IChunkAccess chunk) { var topLeft = Vector3.Transform(new Vector3(camera.Projection.Left, camera.Projection.Top, 0), camera.ModelViewMatrix.Inverted()); var bottomRight = Vector3.Transform(new Vector3(camera.Projection.Right, camera.Projection.Bottom, 0), camera.ModelViewMatrix.Inverted()); var minX = (int)Math.Floor(topLeft.X); var maxX = (int)Math.Ceiling(bottomRight.X); var minY = (int)Math.Floor(topLeft.Y); var maxY = (int)Math.Ceiling(bottomRight.Y); _tessellator.BindColor(Color.White); _tessellator.LoadIdentity(); _tessellator.Begin(PrimitiveType.Quads); RenderLayer(_tessellator, chunk, ChunkLayer.Background, minX, maxX, minY, maxY); RenderLayer(_tessellator, chunk, ChunkLayer.Floor, minX, maxX, minY, maxY); RenderEntities(_tessellator, chunk, minX, maxX, minY, maxY); RenderLayer(_tessellator, chunk, ChunkLayer.Blocking, minX, maxX, minY, maxY); RenderLayer(_tessellator, chunk, ChunkLayer.Ceiling, minX, maxX, minY, maxY); var fov = CalculateFieldOfView(_tessellator, camera, player, chunk, minX, maxX, minY, maxY); RenderFieldOfView(fov, _tessellator, camera, chunk, minX, maxX, minY, maxY); _tessellator.End(); }
protected override void RenderContent(ITessellator tessellator) { base.RenderContent(tessellator); if ((ItemStack != null) && (ItemStack.StackSize > 1)) { tessellator.BindColor(Color.Yellow); tessellator.Translate(-6, 16, -1); ASCII.RenderText(tessellator, ItemStack.StackSize.ToString()); tessellator.Translate(6, -16, 1); } }
public override void Render() { base.Render(); GL.ClearColor(Color.FromArgb(48, 48, 48)); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _worldManager.Render(); if (!_uiManager.HasMouseHover) { if (_worldManager.Player.CanReach((int)_mouseBlockPosition.X, (int)_mouseBlockPosition.Y)) { _tessellator.Begin(PrimitiveType.Quads); _tessellator.LoadIdentity(); _tessellator.Translate(0, 0, -9); // map overlay render layer // Render the tile selector. _tessellator.BindTexture(null); _tessellator.BindColor(Color.FromArgb(64, Color.Black)); _tessellator.Translate(_mouseBlockPosition.X, _mouseBlockPosition.Y); _tessellator.AddPoint(0, 0); _tessellator.AddPoint(0, 1); _tessellator.AddPoint(1, 1); _tessellator.AddPoint(1, 0); if (_uiManager.SelectedToolbarSlot != null) { _tessellator.BindColor(Color.FromArgb(128, Color.White)); ItemRenderManager.Instance.Render(_tessellator, _uiManager.SelectedToolbarSlot.GetItem()); } _tessellator.End(); } } _uiManager.Render(); }
private void Render(ITessellator tessellator, BlockEntity entity) { var color = tessellator.CurrentColor; tessellator.BindColor(Color.FromArgb(196, entity.IsSelected ? Color.Red : Color.White)); tessellator.PushTransform(); var origin = tessellator.Transform(Vector3.Zero); tessellator.LoadIdentity(); tessellator.Scale(entity.Size, entity.Size); tessellator.Translate(-entity.Size / 2, -entity.Size / 2); // center the rotation tessellator.Rotate(entity.Rotation, 0, 0, 1); tessellator.Translate(entity.Size, entity.Size); tessellator.Translate(origin); //tessellator.Translate(entity.Size, entity.Size); // center on the current tile position tessellator.Translate(entity.Position); // move to the entity's position BlockRegistry.Instance.GetById(entity.BlockID).Renderer.Render(tessellator); tessellator.PopTransform(); tessellator.BindColor(color); // TODO: Is this still needed? }
/// <summary> /// Render a solid rectangle. /// </summary> protected void RenderRectangle(ITessellator tessellator, Color color, int tileWidth, int tileHeight) { tessellator.PushTransform(); tessellator.BindColor(color); for (var y = 0; y < tileHeight; y++) { for (var x = 0; x < tileWidth; x++) { UI_ASCII.Render(tessellator, ASCII_SOLID); tessellator.Translate(UI_ASCII.Width, 0); } tessellator.Translate(-UI_ASCII.Width * tileWidth, UI_ASCII.Height); } tessellator.PopTransform(); }
protected override void RenderContent(ITessellator tessellator) { base.RenderContent(tessellator); // TODO: Item.Renderer.Color = ModifyColorByState(_itemColor); tessellator.Translate(UI_ASCII.Width * 1.5f, UI_ASCII.Height * 1.5f); Scale(tessellator, 8.0f * 2.0f); if (Renderable != null) { tessellator.BindColor(Color.White); Renderable.Render(tessellator); } if (Hotkey.HasValue) { tessellator.BindColor(Color.White); Scale(tessellator, 8f); tessellator.Translate(16, 16, -1); ASCII.RenderText(tessellator, ConvertEx.ChangeType <char>(Hotkey.Value).ToString()); tessellator.Translate(-16, -16, 1); } }
private void RenderEntities(ITessellator tessellator, IChunkAccess chunk, int minX, int maxX, int minY, int maxY) { tessellator.Translate(0, 0, -1 * (int)ChunkLayer.Blocking); foreach (var entity in chunk.Entities) { if (CommonCore.Math.MathHelper.IsInRange(entity.Position.X, minX, maxX + 1) && CommonCore.Math.MathHelper.IsInRange(entity.Position.Y, minY, maxY + 1)) { tessellator.BindColor(Color.White); EntityRenderManager.Instance.Render(tessellator, entity); } } tessellator.Translate(0, 0, (int)ChunkLayer.Blocking); }
protected override void RenderContent(ITessellator tessellator) { RenderRectangle(tessellator, BackgroundColor, _tileWidth, _tileHeight); tessellator.BindColor(BorderColor); UI_ASCII.Render(tessellator, DOUBLELINED ? ASCII_DOUBLELINE_TOPLEFT : ASCII_SINGLELINE_TOPLEFT); for (var n = 0; n < _tileWidth - 2; n++) { tessellator.Translate(UI_ASCII.Width, 0); UI_ASCII.Render(tessellator, DOUBLELINED ? ASCII_DOUBLELINE_HORIZONTAL : ASCII_SINGLELINE_HORIZONTAL); // top } tessellator.Translate(UI_ASCII.Width, 0); UI_ASCII.Render(tessellator, DOUBLELINED ? ASCII_DOUBLELINE_TOPRIGHT : ASCII_SINGLELINE_TOPRIGHT); tessellator.Translate(0, UI_ASCII.Height * (_tileHeight - 1)); UI_ASCII.Render(tessellator, DOUBLELINED ? ASCII_DOUBLELINE_BOTTOMRIGHT : ASCII_SINGLELINE_BOTTOMRIGHT); for (var n = 0; n < _tileWidth - 2; n++) { tessellator.Translate(-UI_ASCII.Width, 0); UI_ASCII.Render(tessellator, DOUBLELINED ? ASCII_DOUBLELINE_HORIZONTAL : ASCII_SINGLELINE_HORIZONTAL); // bottom } tessellator.Translate(-UI_ASCII.Width, 0); UI_ASCII.Render(tessellator, DOUBLELINED ? ASCII_DOUBLELINE_BOTTOMLEFT : ASCII_SINGLELINE_BOTTOMLEFT); for (var n = 0; n < _tileHeight - 2; n++) { tessellator.Translate(0, -UI_ASCII.Height); UI_ASCII.Render(tessellator, DOUBLELINED ? ASCII_DOUBLELINE_VERTICAL : ASCII_SINGLELINE_VERTICAL); // left } tessellator.Translate(UI_ASCII.Width * (_tileWidth - 1), 0); for (var n = 0; n < _tileHeight - 2; n++) { UI_ASCII.Render(tessellator, DOUBLELINED ? ASCII_DOUBLELINE_VERTICAL : ASCII_SINGLELINE_VERTICAL); // right tessellator.Translate(0, UI_ASCII.Height); } }
protected override void RenderContent(ITessellator tessellator) { base.RenderContent(tessellator); // TODO: Item.Renderer.Color = ModifyColorByState(_itemColor); tessellator.Translate(UI_ASCII.Width * 1.5f, UI_ASCII.Height * 1.5f); Scale(tessellator, 8.0f * 2.0f); if (Renderable != null) { tessellator.BindColor(Color.White); Renderable.Render(tessellator); } if (Hotkey.HasValue) { tessellator.BindColor(Color.White); Scale(tessellator, 8f); tessellator.Translate(16, 16, -1); ASCII.RenderText(tessellator, ConvertEx.ChangeType<char>(Hotkey.Value).ToString()); tessellator.Translate(-16, -16, 1); } }
private void RenderFieldOfView(int[,] fovMap, ITessellator tessellator, Camera<OrthographicProjection> camera, IChunkAccess chunk, int minX, int maxX, int minY, int maxY) { tessellator.PushTransform(); tessellator.Translate(0, 0, -1 * (int)ChunkLayer.Lights); tessellator.BindTexture(null); for (var y = 0; y < fovMap.GetLength(0); y++) { for (var x = 0; x < fovMap.GetLength(1); x++) { if (fovMap[y, x] == 255) { continue; } tessellator.BindColor(Color.FromArgb(255 - fovMap[y, x], 0, 0, 0)); tessellator.Translate(minX + x, minY + y); tessellator.AddPoint(0, 0); tessellator.AddPoint(0, 1); tessellator.AddPoint(1, 1); tessellator.AddPoint(1, 0); tessellator.Translate(-(minX + x), -(minY + y)); } } tessellator.PopTransform(); }
/// <summary> /// Renders a light map around each entity. /// </summary> /// <remarks> /// Also takes line-of-sight into account. /// </remarks> private void RenderLightMap(ITessellator tessellator, IChunkAccess chunk, int minX, int maxX, int minY, int maxY) { tessellator.PushTransform(); tessellator.Translate(0, 0, -1 * (int)ChunkLayer.Lights); tessellator.BindTexture(null); int[,] lightMap = new int[maxY - minY + 1, maxX - minX + 1]; foreach (var entity in chunk.Entities) { var originX = (int)(entity.Position.X); var originY = (int)(entity.Position.Y); var considered = new List<Vector2I>(); //for (var angle = 0.0f; angle < 360.0f; angle += (9.0f - distance)) // hit more angles as you move further out for (var angle = 0.0f; angle < 360.0f; angle += 1.0f) { for (var distance = 0.0f; distance < chunk.AmbientLightLevel * 2.0f; distance++) { var x = (int)(originX + distance * Math.Cos(OpenTK.MathHelper.DegreesToRadians(angle))); var y = (int)(originY + distance * Math.Sin(OpenTK.MathHelper.DegreesToRadians(angle))); var vector = new Vector2I(y - minY, x - minX); if (!considered.Contains(vector)) { considered.Add(vector); if (CommonCore.Math.MathHelper.IsInRange(y - minY, 0, maxY - minY + 1) && CommonCore.Math.MathHelper.IsInRange(x - minX, 0, maxX - minX + 1)) { //var alpha = (8.0f - distance) / 8.0f; var alpha = 1.0f / Math.Pow((distance + 1) / chunk.AmbientLightLevel, 2); lightMap[y - minY, x - minX] = OpenTK.MathHelper.Clamp((int)(lightMap[y - minY, x - minX] + alpha * 255.0f), 0, 255); } else { break; } } if (chunk[ChunkLayer.Blocking, x, y] != 0) { break; } } } } for (var y = 0; y < lightMap.GetLength(0); y++) { for (var x = 0; x < lightMap.GetLength(1); x++) { tessellator.BindColor(Color.FromArgb(255 - lightMap[y, x], 0, 0, 0)); tessellator.Translate(minX + x, minY + y); tessellator.AddPoint(0, 0); tessellator.AddPoint(0, 1); tessellator.AddPoint(1, 1); tessellator.AddPoint(1, 0); tessellator.Translate(-(minX + x), -(minY + y)); } } tessellator.PopTransform(); }
/// <summary> /// Renders a light map around each entity. /// </summary> /// <remarks> /// Also takes line-of-sight into account. /// </remarks> private void RenderLightMap(ITessellator tessellator, IChunkAccess chunk, int minX, int maxX, int minY, int maxY) { tessellator.PushTransform(); tessellator.Translate(0, 0, -1 * (int)ChunkLayer.Lights); tessellator.BindTexture(null); int[,] lightMap = new int[maxY - minY + 1, maxX - minX + 1]; foreach (var entity in chunk.Entities) { var originX = (int)(entity.Position.X); var originY = (int)(entity.Position.Y); var considered = new List <Vector2I>(); //for (var angle = 0.0f; angle < 360.0f; angle += (9.0f - distance)) // hit more angles as you move further out for (var angle = 0.0f; angle < 360.0f; angle += 1.0f) { for (var distance = 0.0f; distance < chunk.AmbientLightLevel * 2.0f; distance++) { var x = (int)(originX + distance * Math.Cos(OpenTK.MathHelper.DegreesToRadians(angle))); var y = (int)(originY + distance * Math.Sin(OpenTK.MathHelper.DegreesToRadians(angle))); var vector = new Vector2I(y - minY, x - minX); if (!considered.Contains(vector)) { considered.Add(vector); if (CommonCore.Math.MathHelper.IsInRange(y - minY, 0, maxY - minY + 1) && CommonCore.Math.MathHelper.IsInRange(x - minX, 0, maxX - minX + 1)) { //var alpha = (8.0f - distance) / 8.0f; var alpha = 1.0f / Math.Pow((distance + 1) / chunk.AmbientLightLevel, 2); lightMap[y - minY, x - minX] = OpenTK.MathHelper.Clamp((int)(lightMap[y - minY, x - minX] + alpha * 255.0f), 0, 255); } else { break; } } if (chunk[ChunkLayer.Blocking, x, y] != 0) { break; } } } } for (var y = 0; y < lightMap.GetLength(0); y++) { for (var x = 0; x < lightMap.GetLength(1); x++) { tessellator.BindColor(Color.FromArgb(255 - lightMap[y, x], 0, 0, 0)); tessellator.Translate(minX + x, minY + y); tessellator.AddPoint(0, 0); tessellator.AddPoint(0, 1); tessellator.AddPoint(1, 1); tessellator.AddPoint(1, 0); tessellator.Translate(-(minX + x), -(minY + y)); } } tessellator.PopTransform(); }