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); }
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(ITessellator tessellator, int tileIndex, bool mirrorX = false, bool mirrorY = false) { var tile = _tiles[tileIndex]; var minU = mirrorX ? tile.URight : tile.ULeft; var maxU = mirrorX ? tile.ULeft : tile.URight; var minV = mirrorY ? tile.VBottom : tile.VTop; var maxV = mirrorY ? tile.VTop : tile.VBottom; var width = IsNormalized ? 1 : Width; var height = IsNormalized ? 1 : Height; tessellator.BindTexture(_texture); tessellator.AddPoint(0, 0, minU, minV); tessellator.AddPoint(0, height, minU, maxV); tessellator.AddPoint(width, height, maxU, maxV); tessellator.AddPoint(width, 0, maxU, minV); }
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(); }
/// <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(); }
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(); }