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 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 void Apply(ITessellator tessellator) { var position = tessellator.Transform(Vector2.Zero); tessellator.Translate(-position); tessellator.Scale(Scale.X, Scale.Y); tessellator.Rotate(Rotation, 0, 0, 1); tessellator.Translate(Translation); tessellator.Translate(position); }
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); } }
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 void RenderText(ITessellator tessellator, string format, params object[] args) { Vector2 unitX = tessellator.Transform(Vector2.UnitX * (IsNormalized ? 1 : Width)) - tessellator.Transform(Vector2.Zero); format = string.Format(format, args); for (var index = 0; index < format.Length; index++) { Render(tessellator, (int)format[index]); tessellator.Translate(unitX); } tessellator.Translate(-unitX * format.Length); }
/// <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(); }
private void Render(ITessellator tessellator, PlayerEntity entity) { tessellator.PushTransform(); var origin = tessellator.Transform(Vector3.Zero); tessellator.LoadIdentity(); tessellator.Scale(entity.Size, entity.Size); tessellator.Translate(origin); //tessellator.Translate(0.1f, 0.1f); // center on the current tile position tessellator.Translate(entity.Position); // move to the entity's position _playerTile.Render(tessellator); tessellator.PopTransform(); }
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); }
/// <summary> /// Calculate a scale according to the current position. /// </summary> /// <remarks> /// This assumes you are inside of RenderContent, and handles pushing and popping the current transformation accordingly. /// </remarks> protected void Scale(ITessellator tessellator, float scale) { var position = tessellator.Transform(Vector2.Zero); tessellator.PopTransform(); tessellator.PushTransform(); tessellator.Scale(scale, scale); tessellator.Translate(position); }
public void Render(ITessellator tessellator) { tessellator.PushTransform(); tessellator.Translate(Bounds.X, Bounds.Y); RenderContent(tessellator); tessellator.PopTransform(); }
private void RenderLayer(ITessellator tessellator, IChunkAccess chunk, ChunkLayer layer, int minX, int maxX, int minY, int maxY) { for (var y = minY; y < maxY; y++) { for (var x = minX; x < maxX; x++) { if ((chunk[layer, x, y] > 0) && chunk.CanSeeSky(layer, x, y)) { //var position = tessellator.WorldToScreenPoint(new Vector3(column, row, (int)layer)); var position = new Vector3(x, y, -1 * (int)layer); tessellator.Translate(position); var id = BlockRegistry.Instance.GetById(chunk[layer, x, y]); BlockRegistry.Instance.GetById(chunk[layer, x, y]).Renderer.Render(tessellator, chunk, layer, x, y); tessellator.Translate(-position); } } } }
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? }
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); } }
public void Render() { _hudCamera.Apply(); _tessellator.LoadIdentity(); _tessellator.Translate(0, 0, -10); // hud render layer _tessellator.Begin(PrimitiveType.Quads); foreach (var child in _children) { child.Render(_tessellator); } _tessellator.End(); }
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(); }