Esempio n. 1
0
        public void Render()
        {
            // Enable blending for transparency
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Blend);

            GL.Color4(color);
            GL.LineWidth(lineWidth);

            var matrix = GameObject?.Transform?.GetTransformationMatrixCached(!GameObject.IsUiElement) ??
                         System.Numerics.Matrix3x2.Identity;
            var fromPoint = FastVector2Transform.Transform(from.X, from.Y, matrix);
            var toPoint   = FastVector2Transform.Transform(to.X, to.Y, matrix);

            GL.Begin(PrimitiveType.Lines);
            GL.Vertex2(fromPoint);
            GL.Vertex2(toPoint);
            GL.End();

            if (FrameworkDebug.Enabled)
            {
                GL.Color4(Color.Red);
                GL.PointSize(lineWidth);
                GL.Begin(PrimitiveType.Points);
                GL.Vertex2(fromPoint);
                GL.Vertex2(toPoint);
                GL.End();
            }
        }
Esempio n. 2
0
        public void Render()
        {
            // Enable blending for transparency in textures
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Blend);

            // Color is multiplied with the texture color
            // White means no color change in the texture will be applied
            GL.Color4(Color.White);

            var matrix = GameObject?.Transform?.GetTransformationMatrixCached(!GameObject.IsUiElement) ??
                         System.Numerics.Matrix3x2.Identity;
            var minXminY = FastVector2Transform.Transform(Rect.MinX, Rect.MinY, matrix);
            var maxXminY = FastVector2Transform.Transform(Rect.MaxX, Rect.MinY, matrix);
            var maxXmaxY = FastVector2Transform.Transform(Rect.MaxX, Rect.MaxY, matrix);
            var minXmaxY = FastVector2Transform.Transform(Rect.MinX, Rect.MaxY, matrix);

            shader.Activate();
            GL.Begin(PrimitiveType.Quads);
            GL.TexCoord2(0.0f, 0.0f);
            GL.Vertex2(minXminY);
            GL.TexCoord2(1.0f, 0.0f);
            GL.Vertex2(maxXminY);
            GL.TexCoord2(1.0f, 1.0f);
            GL.Vertex2(maxXmaxY);
            GL.TexCoord2(0.0f, 1.0f);
            GL.Vertex2(minXmaxY);
            GL.End();
            shader.Deactivate();

            GL.Disable(EnableCap.Blend);
        }
Esempio n. 3
0
        public override object GetTransformedShape(Transform transform)
        {
            var matrix = transform.GetTransformationMatrixCached(false);
            var center = FastVector2Transform.Transform(Circle.CenterX, Circle.CenterY, matrix);

            return(new Circle(center.X, center.Y, Circle.Radius));
        }
Esempio n. 4
0
        public void Render()
        {
            // Enable blending for transparency
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Blend);

            var matrix = GameObject?.Transform?.GetTransformationMatrixCached(!GameObject.IsUiElement) ??
                         System.Numerics.Matrix3x2.Identity;
            var centerT = FastVector2Transform.Transform(center.X, center.Y, matrix);
            var radiusT = radius;             // NOTE We need to transform this with scaling later

            // Render filling
            if (fillColor != Color.Empty)
            {
                GL.Color4(fillColor);
                GL.Begin(PrimitiveType.TriangleFan);
                for (var angle = 0.0f; angle <= 360.0f; angle += anglePrecision)
                {
                    GL.Vertex2(
                        centerT.X + Math.Sin(angle) * radiusT,
                        centerT.Y + Math.Cos(angle) * radiusT);
                }
                GL.End();
            }

            GL.Disable(EnableCap.Blend);
        }
Esempio n. 5
0
        public void Render()
        {
            // Enable blending for transparency
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Blend);

            var matrix = GameObject?.Transform?.GetTransformationMatrixCached(!GameObject.IsUiElement) ??
                         System.Numerics.Matrix3x2.Identity;
            var p1Fill = FastVector2Transform.Transform(p1.X, p1.Y, matrix);
            var p2Fill = FastVector2Transform.Transform(p2.X, p2.Y, matrix);
            var p3Fill = FastVector2Transform.Transform(p3.X, p3.Y, matrix);
            var p4Fill = FastVector2Transform.Transform(p4.X, p4.Y, matrix);

            // Render filling
            if (fillColor != Color.Empty)
            {
                GL.Color4(fillColor);
                GL.Begin(PrimitiveType.Quads);
                GL.Vertex2(p1Fill);
                GL.Vertex2(p2Fill);
                GL.Vertex2(p3Fill);
                GL.Vertex2(p4Fill);
                GL.End();
            }

            // Render stroke / outline
            if (strokeColor != Color.Empty && Math.Abs(strokeWidth) > 0.001f)
            {
                // NOTE The stroke is not drawed "outside" of the rectangle, but directly on the edges
                // NOTE Is this good?
                GL.LineWidth(strokeWidth);
                GL.Color4(strokeColor);
                GL.Begin(PrimitiveType.LineLoop);
                GL.Vertex2(p1Fill);
                GL.Vertex2(p2Fill);
                GL.Vertex2(p3Fill);
                GL.Vertex2(p4Fill);
                GL.End();
            }

            GL.Disable(EnableCap.Blend);

            // NOTE Maybe debug draw?
            //if (FrameworkDebugMode.IsEnabled) {
            //	GL.Color4(Color.Red);
            //	GL.PointSize(lineWidth);
            //	GL.Begin(PrimitiveType.Points);
            //	GL.Vertex2(fromPoint);
            //	GL.Vertex2(toPoint);
            //	GL.End();
            //}
        }
Esempio n. 6
0
        internal override void DebugRender(Transform transform, bool isUiElement)
        {
            var matrix  = transform.GetTransformationMatrixCached(!isUiElement);
            var centerT = FastVector2Transform.Transform(Circle.CenterX, Circle.CenterY, matrix);
            var radiusT = Circle.Radius;             // NOTE We need to transform this with scaling later

            GL.Color4(Color.Red);
            GL.Begin(PrimitiveType.LineStripAdjacency);
            for (var angle = 0.0f; angle <= 360.0f; angle += 0.2f)
            {
                GL.Vertex2(
                    centerT.X + Math.Sin(angle) * radiusT,
                    centerT.Y + Math.Cos(angle) * radiusT);
            }
            GL.End();
        }
        public void Render()
        {
            // Relevant for non shader pipelines
            // Got from: https://github.com/danielscherzer/Framework/blob/72fec5c85e6f21b868c41141ed1c8105f5252e5e/CG/
            // ... Examples/TextureExample/TextureExample.cs
            GL.Enable(EnableCap.Texture2D);

            // Enable blending for transparency in textures
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Blend);

            // Color is multiplied with the texture color
            // White means no color change in the texture will be applied
            GL.Color4(ColorFilter);

            var matrix = GameObject?.Transform?.GetTransformationMatrixCached(!GameObject.IsUiElement) ??
                         System.Numerics.Matrix3x2.Identity;
            var minXminY = FastVector2Transform.Transform(Rect.MinX, Rect.MinY, matrix);
            var maxXminY = FastVector2Transform.Transform(Rect.MaxX, Rect.MinY, matrix);
            var maxXmaxY = FastVector2Transform.Transform(Rect.MaxX, Rect.MaxY, matrix);
            var minXmaxY = FastVector2Transform.Transform(Rect.MinX, Rect.MaxY, matrix);

            texture.Activate();
            GL.Begin(PrimitiveType.Quads);
            GL.TexCoord2(0.0f, 0.0f);
            GL.Vertex2(minXminY);
            GL.TexCoord2(1.0f, 0.0f);
            GL.Vertex2(maxXminY);
            GL.TexCoord2(1.0f, 1.0f);
            GL.Vertex2(maxXmaxY);
            GL.TexCoord2(0.0f, 1.0f);
            GL.Vertex2(minXmaxY);
            GL.End();
            texture.Deactivate();

            GL.Disable(EnableCap.Blend);
            GL.Disable(EnableCap.Texture2D);
        }