public void InitRootGraphics(
            RootGraphic rootgfx,
            ITopWindowEventRoot topWinEventRoot,
            InnerViewportKind innerViewportKind)
        {
            //create a proper bridge****

            this.rootgfx           = rootgfx;
            this.topWinEventRoot   = topWinEventRoot;
            this.innerViewportKind = innerViewportKind;
            switch (innerViewportKind)
            {
            case InnerViewportKind.GL:
            {
                //temp not suppport
                //TODO: review here
                //PixelFarm.Drawing.DrawingGL.CanvasGLPortal.Start();

                var bridge = new OpenGL.MyTopWindowBridgeOpenGL(rootgfx, topWinEventRoot);
                var view   = new OpenGL.GpuOpenGLSurfaceView();

                view.Width        = 800;
                view.Height       = 600;
                openGLSurfaceView = view;
                //view.Dock = DockStyle.Fill;
                this.Controls.Add(view);
                //---------------------------------------
                view.Bind(bridge);
                this.winBridge = bridge;
                //---------------------------------------
                view.SetGLPaintHandler(HandleGLPaint);
                hh1 = view.Handle;         //force real window handle creation
                view.MakeCurrent();
                //int max = Math.Max(this.Width, this.Height);
                int max = Math.Max(view.Width, view.Height);
                canvas2d = PixelFarm.Drawing.GLES2.GLES2Platform.CreateCanvasGL2d(max, max);
                //---------------
                //canvas2d.FlipY = true;//
                //---------------
                canvasPainter = new GLCanvasPainter(canvas2d, max, max);

                //canvasPainter.SmoothingMode = PixelFarm.Drawing.SmoothingMode.HighQuality;
                //----------------------
                //1. win gdi based
                //var printer = new WinGdiFontPrinter(canvas2d, view.Width, view.Height);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //2. raw vxs
                //var printer = new PixelFarm.Drawing.Fonts.VxsTextPrinter(canvasPainter);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //3. agg texture based font texture
                //var printer = new AggTextSpanPrinter(canvasPainter, 400, 50);
                //printer.HintTechnique = Typography.Rendering.HintTechnique.TrueTypeInstruction_VerticalOnly;
                //printer.UseSubPixelRendering = true;
                //canvasPainter.TextPrinter = printer;

                var printer = new GLBmpGlyphTextPrinter(canvasPainter, YourImplementation.BootStrapOpenGLES2.myFontLoader);
                canvasPainter.TextPrinter = printer;

                //
                //var myGLCanvas1 = new PixelFarm.Drawing.GLES2.MyGLCanvas(canvasPainter, 0, 0, view.Width, view.Height);
                var myGLCanvas1 = new PixelFarm.Drawing.GLES2.MyGLCanvas(canvasPainter, 0, 0, view.Width, view.Height);
                bridge.SetCanvas(myGLCanvas1);
            }
            break;

#if __SKIA__
            case InnerViewportKind.Skia:
            {
                //skiasharp ***

                var bridge = new Skia.MyTopWindowBridgeSkia(rootgfx, topWinEventRoot);
                var view   = new CpuSurfaceView();
                view.Dock = DockStyle.Fill;
                this.Controls.Add(view);
                //---------------------------------------
                view.Bind(bridge);
                this.winBridge = bridge;
            }
            break;
#endif
            case InnerViewportKind.GdiPlus:
            default:
            {
                var bridge = new GdiPlus.MyTopWindowBridgeGdiPlus(rootgfx, topWinEventRoot);
                var view   = new CpuSurfaceView();
                view.Dock = DockStyle.Fill;
                this.Controls.Add(view);
                //---------------------------------------
                view.Bind(bridge);
                this.winBridge = bridge;
            }
            break;
            }
        }
Beispiel #2
0
        public static void Start()
        {
            if (!Glfw.Init())
            {
                Console.WriteLine("can't init glfw");
                return;
            }
            //---------------------------------------------------
            //specific OpenGLES ***
            Glfw.WindowHint(WindowHint.GLFW_CLIENT_API, (int)OpenGLAPI.OpenGLESAPI);
            Glfw.WindowHint(WindowHint.GLFW_CONTEXT_CREATION_API, (int)OpenGLContextCreationAPI.GLFW_EGL_CONTEXT_API);
            Glfw.WindowHint(WindowHint.GLFW_CONTEXT_VERSION_MAJOR, 2);
            Glfw.WindowHint(WindowHint.GLFW_CONTEXT_VERSION_MINOR, 0);
            //---------------------------------------------------


            Glfw.SwapInterval(1);
            GlFwForm form1 = GlfwApp.CreateGlfwForm(
                800,
                600,
                "PixelFarm + Skia on GLfw and OpenGLES2");

            form1.MakeCurrent();
            //------------------------------------
            //***
            GLFWPlatforms.CreateGLESContext();
            //------------------------------------
            form1.Activate();

            int ww_w = 800;
            int ww_h = 600;
            int max  = Math.Max(ww_w, ww_h);

            canvasGL2d = PixelFarm.Drawing.GLES2.GLES2Platform.CreateCanvasGL2d(max, max);

            //------------------------------------
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.ClearColor(1, 1, 1, 1);
            //--------------------------------------------------------------------------------
            //setup viewport size
            //set up canvas
            needUpdateContent = true;

            //GL.Viewport(0, 0, 800, 600);
            GL.Viewport(0, 0, max, max);

            FormRenderUpdateEventArgs formRenderUpdateEventArgs = new FormRenderUpdateEventArgs();

            formRenderUpdateEventArgs.form = form1;

            LayoutFarm.Ease.EaseHost.StartGraphicsHost();

            var rootgfx = new MyRootGraphic(
                LayoutFarm.UI.UIPlatformWinNeutral.platform,
                LayoutFarm.UI.UIPlatformWinNeutral.platform.GetIFonts(),
                ww_w, ww_h);

            var surfaceViewportControl = new LayoutFarm.UI.WinNeutral.UISurfaceViewportControl();

            surfaceViewportControl.InitRootGraphics(rootgfx, rootgfx.TopWinEventPortal, InnerViewportKind.GL);


            //lion fill sample
            OpenTkEssTest.T108_LionFill lionFill = new OpenTkEssTest.T108_LionFill();
            lionFill.Init2(canvasGL2d);
            GLCanvasPainter painter1 = lionFill.Painter;

            var myCanvasGL = new PixelFarm.Drawing.GLES2.MyGLCanvas(painter1, 0, 0, 800, 600);

            //(PixelFarm.Drawing.GLES2.GLES2Platform.CreateCanvas(0, 0, 800, 600, canvasGL2d, painter1);

            surfaceViewportControl.SetupCanvas(myCanvasGL);

            SampleViewport viewport = new LayoutFarm.SampleViewport(surfaceViewportControl);
            HtmlHost       htmlHost;

            htmlHost = HtmlHostCreatorHelper.CreateHtmlHost(viewport, null, null);
            ////==================================================
            //html box
            HtmlBox lightHtmlBox = new HtmlBox(htmlHost, 800, 50);

            {
                lightHtmlBox.SetLocation(50, 450);
                viewport.AddContent(lightHtmlBox);
                //light box can't load full html
                //all light boxs of the same lightbox host share resource with the host
                string html = @"<div>OK1</div><div>OK2</div>";
                //if you want to use full html-> use HtmlBox instead
                lightHtmlBox.LoadHtmlString(html);
            }

            form1.SetDrawFrameDelegate(() =>
            {
                //render each frame
                if (needUpdateContent)
                {
                    UpdateViewContent(formRenderUpdateEventArgs);
                }
                canvasGL2d.Clear(Color.White);

                //canvasGL2d.DrawRect(0, 0, 200, 200);
                ////canvasGL2d.DrawImage(glBmp, 0, 600);
                //int tmp_x = lightHtmlBox.Left;
                //int tmp_y = lightHtmlBox.Top;
                //myCanvasGL.SetCanvasOrigin(tmp_x, tmp_y);

                canvasGL2d.SmoothMode = CanvasSmoothMode.No;
                //---------
                //flip y axis for html box (and other UI)
                canvasGL2d.FlipY = true;
                lightHtmlBox.CurrentPrimaryRenderElement.DrawToThisCanvas(
                    myCanvasGL, new Rectangle(0, 0, 800, 600));
                canvasGL2d.FlipY = false;
                //myCanvasGL.SetCanvasOrigin(tmp_x, -tmp_y);
                //lion use canvas coordinate system
                lionFill.TestRender();

                //surfaceViewportControl.PaintMe(canvasGL2d);
            });



            while (!GlfwApp.ShouldClose())
            {
                //---------------
                //render phase and swap
                GlfwApp.UpdateWindowsFrame();
                /* Poll for and process events */
                Glfw.PollEvents();
            }

            Glfw.Terminate();
        }