예제 #1
0
        private void button7_Click(object sender, EventArgs e)
        {
            var builder = new PixelFarm.CpuBlit.VertexProcessing.SimpleRectBorderBuilder();

            builder.SetBorderWidth(6);
            builder.RightBorderWidth   = 14;
            builder.BottomBorderHeight = 3;
            float[] coords = new float[16];

            builder.BuildAroundInnerRefBounds(0, 0, 30, 30, coords);
            //builder.BuildAroundOuterRefBounds(10, 10, 30, 30, coords);
            //builder.BuildOverRefBounds(10, 10, 30, 30, coords);

            //
            TessTest.TessListener t01      = new TessTest.TessListener();
            Tesselate.Tesselator  tess     = new Tesselate.Tesselator();
            List <Vertex>         vertexts = new List <Vertex>();

            for (int i = 0; i < coords.Length;)
            {
                vertexts.Add(new Vertex(coords[i], coords[i + 1]));
                i += 2;
            }
            //------------------

            t01.Connect(vertexts, tess, Tesselate.Tesselator.WindingRuleType.Odd, true);

            //polygon1
            tess.BeginPolygon();
            //------------------------------------
            //contour1
            tess.BeginContour();
            int start_at  = 0;
            int endBefore = start_at + 4;

            for (int i = start_at; i < endBefore; ++i)
            {
                Vertex v = vertexts[i];
                tess.AddVertex(v.m_X, v.m_Y, 0, i);
            }
            tess.EndContour();
            //------------------------------------
            //contour 2
            tess.BeginContour();
            start_at  = 4;
            endBefore = vertexts.Count;
            for (int i = start_at; i < endBefore; ++i)
            {
                Vertex v = vertexts[i];
                tess.AddVertex(v.m_X, v.m_Y, 0, i);
            }
            tess.EndContour();
            tess.EndPolygon();
            //---------------------------
            //save final images
            SaveToImage(null, t01.resultVertexList, 1, 0, 0);
            //---------------------------
        }
예제 #2
0
        void RunTest(int instructionStreamIndex, Tesselator.WindingRuleType windingRule, bool setEdgeFlag)
        {
            Tesselate.Tesselator  tesselator = new Tesselate.Tesselator();
            TessTest.TessListener listner    = new TessTest.TessListener();
            tesselator.WindingRule = windingRule;
            listner.Connect(tesselator, setEdgeFlag);

            //tesselator.callBegin += new Tesselate.Tesselator.CallBeginDelegate(BeginCallBack);
            //tesselator.callEnd += new Tesselate.Tesselator.CallEndDelegate(EndCallBack);
            //tesselator.callVertex += new Tesselate.Tesselator.CallVertexDelegate(VertexCallBack);
            //tesselator.callCombine += new Tesselate.Tesselator.CallCombineDelegate(CombineCallBack);

            //tesselator.windingRule = windingRule;
            //if (setEdgeFlag)
            //{
            //    tesselator.callEdgeFlag += new Tesselate.Tesselator.CallEdgeFlagDelegate(EdgeFlagCallBack);
            //}

            //ParseStreamForTesselator(tesselator, instructionStreamIndex);
        }
예제 #3
0
파일: Form1.cs 프로젝트: asmboom/PixelFarm
        private void button5_Click(object sender, EventArgs e)
        {
            //ref: http://www.songho.ca/opengl/gl_tessellation.html
            //==============================================================================
            //song ho's tessellation examples 2
            //==============================================================================
            //          // define self-intersecting star shape (with color)
            ////      0
            ////     / \
            ////3---+---+---2
            ////  \ |   | /
            ////   \|   |/
            ////    +   +
            ////    |\ /|
            ////    | + |
            ////    |/ \|
            ////    1   4
            //GLdouble star[5][6] = { { 0.0, 3.0, 0,  1, 0, 0},       // 0: x,y,z,r,g,b
            //                        {-1.0, 0.0, 0,  0, 1, 0},       // 1:
            //                        { 1.6, 1.9, 0,  1, 0, 1},       // 2:
            //                        {-1.6, 1.9, 0,  1, 1, 0},       // 3:
            //                        { 1.0, 0.0, 0,  0, 0, 1} };     // 4:

            //// register callback functions
            //// This polygon is self-intersecting, so GLU_TESS_COMBINE callback function
            //// must be registered. The combine callback will process the intersecting vertices.
            //gluTessCallback(tess, GLU_TESS_BEGIN, (void (__stdcall*)(void))tessBeginCB);
            //gluTessCallback(tess, GLU_TESS_END, (void (__stdcall*)(void))tessEndCB);
            //gluTessCallback(tess, GLU_TESS_ERROR, (void (__stdcall*)(void))tessErrorCB);
            //gluTessCallback(tess, GLU_TESS_VERTEX, (void (__stdcall*)(void))tessVertexCB2);
            //gluTessCallback(tess, GLU_TESS_COMBINE, (void (__stdcall*)(void))tessCombineCB);

            //// tessellate and compile a concave quad into display list
            //// Pay attention to winding rules if multiple contours are overlapped.
            //// The winding rules determine which parts of polygon will be filled(interior)
            //// or not filled(exterior). For each enclosed region partitioned by multiple
            //// contours, tessellator assigns a winding number to the region by using
            //// given winding rule. The default winding rule is GLU_TESS_WINDING_ODD,
            //// but, here we are using non-zero winding rule to fill the middle area.
            //// BTW, the middle region will not be filled with the odd winding rule.
            //gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO);
            //glNewList(id, GL_COMPILE);
            //gluTessBeginPolygon(tess, 0);                   // with NULL data
            //    gluTessBeginContour(tess);
            //        gluTessVertex(tess, star[0], star[0]);
            //        gluTessVertex(tess, star[1], star[1]);
            //        gluTessVertex(tess, star[2], star[2]);
            //        gluTessVertex(tess, star[3], star[3]);
            //        gluTessVertex(tess, star[4], star[4]);
            //    gluTessEndContour(tess);
            //gluTessEndPolygon(tess);
            //glEndList();
            //gluDeleteTess(tess);        // safe to delete after tessellation

            //======================================================
            //GLdouble star[5][6] = { { 0.0, 3.0, 0,  1, 0, 0},       // 0: x,y,z,r,g,b
            //                        {-1.0, 0.0, 0,  0, 1, 0},       // 1:
            //                        { 1.6, 1.9, 0,  1, 0, 1},       // 2:
            //                        {-1.6, 1.9, 0,  1, 1, 0},       // 3:
            //                        { 1.0, 0.0, 0,  0, 0, 1} };     // 4:

            TessTest.TessListener t01      = new TessTest.TessListener();
            Tesselate.Tesselator  tess     = new Tesselate.Tesselator();
            List <Vertex>         vertexts = new List <Vertex>()
            {
                //use only coord (not include rgb color)
                new Vertex(0, 3),
                new Vertex(-1, 0),
                new Vertex(1.6, 1.9),
                new Vertex(-1.6, 1.9),
                new Vertex(1, 0)
            };

            //------------------

            t01.Connect(vertexts, tess, Tesselate.Tesselator.WindingRuleType.NonZero, true);

            //polygon1
            tess.BeginPolygon();
            //------------------------------------
            //contour1
            tess.BeginContour();
            int start_at  = 0;
            int endBefore = vertexts.Count;

            for (int i = start_at; i < endBefore; ++i)
            {
                Vertex v = vertexts[i];
                tess.AddVertex(v.m_X, v.m_Y, 0, i);
            }
            tess.EndContour();
            //------------------------------------

            tess.EndPolygon();
            //---------------------------
            //save final images
            SaveToImage(null, t01.resultVertexList);
            //---------------------------
        }
예제 #4
0
파일: Form1.cs 프로젝트: asmboom/PixelFarm
        private void button4_Click(object sender, EventArgs e)
        {
            //ref: http://www.songho.ca/opengl/gl_tessellation.html
            //==============================================================================
            //song ho's tessellation examples 2
            //==============================================================================
            // define concave quad with a hole
            //  0--------3
            //  | 4----7 |
            //  | |    | |
            //  | 5----6 |
            //  1--------2
            //GLdouble quad2[8][3] = { {-2,3,0}, {-2,0,0}, {2,0,0}, { 2,3,0},
            //                         {-1,2,0}, {-1,1,0}, {1,1,0}, { 1,2,0} };
            //gluTessCallback(tess, GLU_TESS_BEGIN, (void (__stdcall*)(void))tessBeginCB);
            //gluTessCallback(tess, GLU_TESS_END, (void (__stdcall*)(void))tessEndCB);
            //gluTessCallback(tess, GLU_TESS_ERROR, (void (__stdcall*)(void))tessErrorCB);
            //gluTessCallback(tess, GLU_TESS_VERTEX, (void (__stdcall*)())tessVertexCB);

            //// tessellate and compile a concave quad into display list
            //glNewList(id, GL_COMPILE);
            //glColor3f(1,1,1);
            //gluTessBeginPolygon(tess, 0);                       // with NULL data
            //    gluTessBeginContour(tess);                      // outer quad
            //        gluTessVertex(tess, quad2[0], quad2[0]);
            //        gluTessVertex(tess, quad2[1], quad2[1]);
            //        gluTessVertex(tess, quad2[2], quad2[2]);
            //        gluTessVertex(tess, quad2[3], quad2[3]);
            //    gluTessEndContour(tess);
            //    gluTessBeginContour(tess);                      // inner quad (hole)
            //        gluTessVertex(tess, quad2[4], quad2[4]);
            //        gluTessVertex(tess, quad2[5], quad2[5]);
            //        gluTessVertex(tess, quad2[6], quad2[6]);
            //        gluTessVertex(tess, quad2[7], quad2[7]);
            //    gluTessEndContour(tess);
            //gluTessEndPolygon(tess);
            //glEndList();
            //==============================================================================

            TessTest.TessListener t01      = new TessTest.TessListener();
            Tesselate.Tesselator  tess     = new Tesselate.Tesselator();
            List <Vertex>         vertexts = new List <Vertex>()
            {
                new Vertex(-2, 3),
                new Vertex(-2, 0),
                new Vertex(2, 0),
                new Vertex(2, 3),
                //------------------
                new Vertex(-1, 2),
                new Vertex(-1, 1),
                new Vertex(1, 1),
                new Vertex(1, 2),
            };

            //------------------

            t01.Connect(vertexts, tess, Tesselate.Tesselator.WindingRuleType.Odd, true);

            //polygon1
            tess.BeginPolygon();
            //------------------------------------
            //contour1
            tess.BeginContour();
            int start_at  = 0;
            int endBefore = start_at + 4;

            for (int i = start_at; i < endBefore; ++i)
            {
                Vertex v = vertexts[i];
                tess.AddVertex(v.m_X, v.m_Y, 0, i);
            }
            tess.EndContour();
            //------------------------------------
            //contour 2
            tess.BeginContour();
            start_at  = 4;
            endBefore = vertexts.Count;
            for (int i = start_at; i < endBefore; ++i)
            {
                Vertex v = vertexts[i];
                tess.AddVertex(v.m_X, v.m_Y, 0, i);
            }
            tess.EndContour();


            tess.EndPolygon();
            //---------------------------
            //save final images
            SaveToImage(null, t01.resultVertexList);
            //---------------------------
        }
예제 #5
0
파일: Form1.cs 프로젝트: asmboom/PixelFarm
        private void button3_Click(object sender, EventArgs e)
        {
            //ref: http://www.songho.ca/opengl/gl_tessellation.html
            //==============================================================================
            //song ho's tessellation examples 1
            //==============================================================================

            // // define concave quad data (vertices only)
            ////  0    2
            ////  \ \/ /
            ////   \3 /
            ////    \/
            ////    1
            //GLdouble quad1[4][3] = { {-1,3,0}, {0,0,0}, {1,3,0}, {0,2,0} };

            //// register callback functions
            //gluTessCallback(tess, GLU_TESS_BEGIN, (void (CALLBACK *)())tessBeginCB);
            //gluTessCallback(tess, GLU_TESS_END, (void (CALLBACK *)())tessEndCB);
            //gluTessCallback(tess, GLU_TESS_ERROR, (void (CALLBACK *)())tessErrorCB);
            //gluTessCallback(tess, GLU_TESS_VERTEX, (void (CALLBACK *)())tessVertexCB);

            //// tessellate and compile a concave quad into display list
            //// gluTessVertex() takes 3 params: tess object, pointer to vertex coords,
            //// and pointer to vertex data to be passed to vertex callback.
            //// The second param is used only to perform tessellation, and the third
            //// param is the actual vertex data to draw. It is usually same as the second
            //// param, but It can be more than vertex coord, for example, color, normal
            //// and UV coords which are needed for actual drawing.
            //// Here, we are looking at only vertex coods, so the 2nd and 3rd params are
            //// pointing same address.
            //glNewList(id, GL_COMPILE);
            //glColor3f(1,1,1);
            //gluTessBeginPolygon(tess, 0);                   // with NULL data
            //    gluTessBeginContour(tess);
            //        gluTessVertex(tess, quad1[0], quad1[0]);
            //        gluTessVertex(tess, quad1[1], quad1[1]);
            //        gluTessVertex(tess, quad1[2], quad1[2]);
            //        gluTessVertex(tess, quad1[3], quad1[3]);
            //    gluTessEndContour(tess);
            //gluTessEndPolygon(tess);
            //glEndList();

            TessTest.TessListener t01  = new TessTest.TessListener();
            Tesselate.Tesselator  tess = new Tesselate.Tesselator();

            List <Vertex> vertexts = new List <Vertex>()
            {
                new Vertex(-1, 3),
                new Vertex(0, 0),
                new Vertex(1, 3),
                new Vertex(0, 2),
            };

            t01.Connect(vertexts, tess, Tesselate.Tesselator.WindingRuleType.Odd, true);


            tess.BeginPolygon();
            tess.BeginContour();

            int j = vertexts.Count;

            for (int i = 0; i < j; ++i)
            {
                Vertex v = vertexts[i];
                tess.AddVertex(v.m_X, v.m_Y, 0, i);
            }
            tess.EndContour();
            tess.EndPolygon();

            //---------------------------
            //save final images
            SaveToImage(null, t01.resultVertexList);
            //---------------------------
        }