public void Render(float partialTicks) { GL.Color3(1, 1, 1f); var tex = TextureManager.GetOrRegister("wall"); GL.BindTexture(TextureTarget.Texture2D, tex); for (var index = 0; index < _collisionBoxes.Count; index++) { var box = _collisionBoxes[index]; var center = box.GetCenter(); GL.Translate(center.X, center.Y, 0); GL.Scale(box.Size.X, box.Size.Y, 1); GL.Begin(PrimitiveType.Quads); VertexUtil.PutQuad(); GL.End(); GL.Scale(1 / box.Size.X, 1 / box.Size.Y, 1); GL.Translate(-center.X, -center.Y, 0); } GL.BindTexture(TextureTarget.Texture2D, 0); }
public override void Render(float partialTicks) { if (!IsAlive) { return; } var partialPos = LastPos + (Pos - LastPos) * partialTicks; GL.Color3(1, 1, 1f); GL.BindTexture(TextureTarget.Texture2D, TextureManager.GetOrRegister("red")); var x = Game.Instance.MouseLast.X - Game.Instance.Width / 2f; var y = Game.Instance.MouseLast.Y - Game.Instance.Height / 2f; Rotation = Vector2.Normalize(new Vector2(x, y)); var ratio = Rotation.X == 0 ? (Rotation.Y > 0 ? 90 : -90) : Rotation.Y / Rotation.X; var atan = Math.Atan(float.IsNaN(ratio) || float.IsInfinity(ratio) ? 0 : ratio); var angle = 90 + (float)MathHelper.RadiansToDegrees(Rotation.X < 0 ? atan + MathHelper.Pi : atan); GL.Translate(partialPos.X, partialPos.Y, 0); GL.Scale(_size, _size, 1); GL.Rotate(angle, 0, 0, 1); GL.Begin(PrimitiveType.Quads); VertexUtil.PutQuad(); GL.End(); GL.Rotate(angle, 0, 0, -1); GL.Scale(1 / _size, 1 / _size, 1); GL.Translate(-partialPos.X, -partialPos.Y, 0); GL.BindTexture(TextureTarget.Texture2D, 0); }
public void RenderShadows(Vector2 viewingPos) { GL.PushAttrib(AttribMask.ColorBufferBit); GL.ClearColor(0, 0, 0, 0); //important Game.Instance.ShadowFbo.Bind(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Color4(0, 0, 0, 1f); //shadow color GL.Disable(EnableCap.Blend); GL.Begin(PrimitiveType.Quads); //render shadows var dist = (float)Math.Sqrt(Game.Instance.Width * Game.Instance.Width + Game.Instance.Height * Game.Instance.Height); for (var i = 0; i < _collisionBoxes.Count; i++) { var box = _collisionBoxes[i]; for (var index = 0; index < 4; index++) { //if last index, this is the first point var pointNext = box[index == 3 ? 0 : index + 1]; var point = box[index]; //sum of dat magic if (IsLeft(pointNext, point, viewingPos)) { GL.Vertex2(point); var dir = Vector2.Normalize(point - viewingPos); var projectedPoint = point + dir * dist; GL.Vertex2(projectedPoint); dir = Vector2.Normalize(pointNext - viewingPos); projectedPoint = pointNext + dir * dist; GL.Vertex2(projectedPoint); GL.Vertex2(pointNext); } } } GL.End(); GL.PopAttrib(); Game.Instance.ShadowFbo.Unbind(); Game.Instance.ShadowFbo.BindTexture(); GL.Enable(EnableCap.Blend); var w = Game.Instance.Width; var h = Game.Instance.Height; GL.Color4(1, 1, 1, 0.875f); GL.Translate(viewingPos.X, viewingPos.Y, 0); GL.Scale(w, -h, 1); GL.Begin(PrimitiveType.Quads); VertexUtil.PutQuad(); GL.End(); GL.Scale(1f / w, -1f / h, 1); GL.Translate(-viewingPos.X, -viewingPos.Y, 0); GL.BindTexture(TextureTarget.Texture2D, 0); }