Exemplo n.º 1
0
        public override void Render(IVertexSource vertexSource, int pathIndexToRender, IColorType colorIn)
        {
            PushOrthoProjection();

            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Blend);

            vertexSource.rewind(pathIndexToRender);

            RGBA_Bytes colorBytes = colorIn.GetAsRGBA_Bytes();

            GL.Color4(colorBytes.red, colorBytes.green, colorBytes.blue, colorBytes.alpha);

            Affine transform = GetTransform();

            if (!transform.is_identity())
            {
                vertexSource = new VertexSourceApplyTransform(vertexSource, transform);
            }

            if (DoEdgeAntiAliasing)
            {
                DrawAAShape(vertexSource);
            }
            else
            {
                renderNowTesselator.Clear();
                Graphics2DOpenGL.SendShapeToTesselator(renderNowTesselator, vertexSource);
            }

            PopOrthoProjection();
        }
Exemplo n.º 2
0
        private void DrawAAShape(IVertexSource vertexSource)
        {
            CheckLineImageCache();
            GL.Enable(EnableCap.Texture2D);
            GL.BindTexture(TextureTarget.Texture2D, RenderOpenGl.ImageGlPlugin.GetImageGlPlugin(AATextureImage, false).GLTextureHandle);

            triangleEddgeInfo.Clear();
            Graphics2DOpenGL.SendShapeToTesselator(triangleEddgeInfo, vertexSource);

            // now render it
            triangleEddgeInfo.RenderLastToGL();
        }
Exemplo n.º 3
0
        public static Mesh Extrude(IVertexSource vertexSource, double zHeight)
        {
            vertexSource.rewind();
            CachedTesselator teselatedSource = new CachedTesselator();

            Graphics2DOpenGL.SendShapeToTesselator(teselatedSource, vertexSource);

            Mesh extrudedVertexSource = new Mesh();

            int numIndicies = teselatedSource.IndicesCache.Count;

            // build the top first so it will render first when we are translucent
            for (int i = 0; i < numIndicies; i += 3)
            {
                Vector2 v0 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 0].Index].Position;
                Vector2 v1 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 1].Index].Position;
                Vector2 v2 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 2].Index].Position;
                if (v0 == v1 || v1 == v2 || v2 == v0)
                {
                    continue;
                }

                Vertex topVertex0 = extrudedVertexSource.CreateVertex(new Vector3(v0, zHeight));
                Vertex topVertex1 = extrudedVertexSource.CreateVertex(new Vector3(v1, zHeight));
                Vertex topVertex2 = extrudedVertexSource.CreateVertex(new Vector3(v2, zHeight));

                extrudedVertexSource.CreateFace(new Vertex[] { topVertex0, topVertex1, topVertex2 });
            }

            // then the outside edge
            for (int i = 0; i < numIndicies; i += 3)
            {
                Vector2 v0 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 0].Index].Position;
                Vector2 v1 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 1].Index].Position;
                Vector2 v2 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 2].Index].Position;
                if (v0 == v1 || v1 == v2 || v2 == v0)
                {
                    continue;
                }

                Vertex bottomVertex0 = extrudedVertexSource.CreateVertex(new Vector3(v0, 0));
                Vertex bottomVertex1 = extrudedVertexSource.CreateVertex(new Vector3(v1, 0));
                Vertex bottomVertex2 = extrudedVertexSource.CreateVertex(new Vector3(v2, 0));

                Vertex topVertex0 = extrudedVertexSource.CreateVertex(new Vector3(v0, zHeight));
                Vertex topVertex1 = extrudedVertexSource.CreateVertex(new Vector3(v1, zHeight));
                Vertex topVertex2 = extrudedVertexSource.CreateVertex(new Vector3(v2, zHeight));

                if (teselatedSource.IndicesCache[i + 0].IsEdge)
                {
                    extrudedVertexSource.CreateFace(new Vertex[] { bottomVertex0, bottomVertex1, topVertex1, topVertex0 });
                }

                if (teselatedSource.IndicesCache[i + 1].IsEdge)
                {
                    extrudedVertexSource.CreateFace(new Vertex[] { bottomVertex1, bottomVertex2, topVertex2, topVertex1 });
                }

                if (teselatedSource.IndicesCache[i + 2].IsEdge)
                {
                    extrudedVertexSource.CreateFace(new Vertex[] { bottomVertex2, bottomVertex0, topVertex0, topVertex2 });
                }
            }

            // then the bottom
            for (int i = 0; i < numIndicies; i += 3)
            {
                Vector2 v0 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 0].Index].Position;
                Vector2 v1 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 1].Index].Position;
                Vector2 v2 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 2].Index].Position;
                if (v0 == v1 || v1 == v2 || v2 == v0)
                {
                    continue;
                }

                Vertex bottomVertex0 = extrudedVertexSource.CreateVertex(new Vector3(v0, 0));
                Vertex bottomVertex1 = extrudedVertexSource.CreateVertex(new Vector3(v1, 0));
                Vertex bottomVertex2 = extrudedVertexSource.CreateVertex(new Vector3(v2, 0));

                extrudedVertexSource.CreateFace(new Vertex[] { bottomVertex2, bottomVertex1, bottomVertex0 });
            }

            return(extrudedVertexSource);
        }