Exemplo n.º 1
0
        public static void dbugStart_Basic()
        {
            //demonstrate basic setup
            var  bridge         = new MyGlfwTopWindowBridge.GlfwEventBridge();
            Size primScreenSize = UIPlatform.CurrentPlatform.GetPrimaryMonitorSize();
            var  form           = new GlFwForm(primScreenSize.Width, primScreenSize.Height, "GLES_GLFW", bridge);

            Init(form);
            //------

            //this is an app detail
            Box bgBox = new Box(primScreenSize.Width, primScreenSize.Height);

            bgBox.BackColor = Color.White;
            s_myRootGfx.AddChild(bgBox.GetPrimaryRenderElement());

            //----------------------
            dbugMySprite sprite = new dbugMySprite(200, 300);
            dbugMyBoxUI  boxUI  = new dbugMyBoxUI();

            boxUI.SetRenderElement(sprite);
            sprite.SetController(boxUI);

            bgBox.Add(boxUI);
            //---------
        }
Exemplo n.º 2
0
        public static void Start()
        {
            var bridge = new MyGlfwTopWindowBridge.GlfwEventBridge();

            Size primScreenSize = UIPlatform.CurrentPlatform.GetPrimaryMonitorSize();
            var  form           = new GlFwForm(primScreenSize.Width, primScreenSize.Height, "GLES_GLFW", bridge);

            //
            Init(form);
            //------

            AppHost       appHost = new AppHost();
            AppHostConfig config  = new AppHostConfig();

            config.RootGfx = s_myRootGfx;
            config.ScreenW = primScreenSize.Width;
            config.ScreenH = primScreenSize.Height;
            appHost.Setup(config);
            //------
            Box bgBox = new Box(primScreenSize.Width, primScreenSize.Height);

            bgBox.BackColor = Color.White;
            s_myRootGfx.AddChild(bgBox.GetPrimaryRenderElement());
            //------


            //appHost.StartApp(new Demo_BoxEvents3());
            appHost.StartApp(new Demo_ScrollView());
            //appHost.StartApp(new Demo_MultipleLabels());
            //appHost.StartApp(new Demo_MultipleLabels2());
            //---------
        }
Exemplo n.º 3
0
        public static void Start()
        {
            PixelFarm.Platforms.StorageService.RegisterProvider(s_LocalStorageProvider);
            //---------------------------------------------------
            PixelFarm.CpuBlit.MemBitmapExtensions.DefaultMemBitmapIO = new YourImplementation.ImgCodecMemBitmapIO();
            //PixelFarm.CpuBlit.MemBitmapExtensions.DefaultMemBitmapIO = new PixelFarm.Drawing.WinGdi.GdiBitmapIO();

            if (!GLFWPlatforms.Init())
            {
                System.Diagnostics.Debug.WriteLine("can't init glfw");
                return;
            }

            bool useMyGLFWForm = true;

            if (!useMyGLFWForm)
            {
                GlFwForm form1   = new GlFwForm(800, 600, "PixelFarm on GLfw and GLES2");
                MyApp    glfwApp = new MyApp();
                form1.SetDrawFrameDelegate(e => glfwApp.UpdateViewContent(e));
            }
            else
            {
                MyGLFWForm form1   = new MyGLFWForm(800, 600, "PixelFarm on GLfw and GLES2");
                MyApp      glfwApp = new MyApp();
                form1.SetDrawFrameDelegate(e => glfwApp.UpdateViewContent(e));
            }
            GlfwApp.RunMainLoop();
        }
Exemplo n.º 4
0
        public static void Start(string[] args)
        {
            if (!Glfw.Init())
            {
                Console.WriteLine("can't init glfw");
                return;
            }

            //1. load cef before OLE init (eg init winform) ***
            //see more detail ...  MyCef3InitEssential
            if (!MyCef3InitEssential.LoadAndInitCef3(args))
            {
                return;
            }
            //------------------------------------------
            //1. if this is main UI process
            //the code go here, and we just start
            //winform app as usual
            //2. if this is other process
            //mean this process is finish and will terminate soon.
            //so we do noting, just exit!
            //(***please note that
            //*** we call ShutDownCef3 only in main thread ***)

            if (!MyCef3InitEssential.IsInMainProcess)
            {
                MyCef3InitEssential.ClearRemainingCefMsg();
                return;
            }

            //------------------------------------------
            /////////////////////////////////////////////
            //this code is run only in main process
            //------------------------------------------
            GlFwForm glfwForm = GlfwApp.CreateGlfwForm(800, 600, "Native CefBrowser, Press any key to start browse the web");
            ////---------------
            Form f1 = Form.CreateFromNativeWindowHwnd(glfwForm.Handle);

            f1.Width  = glfwForm.Width;
            f1.Height = glfwForm.Height;

            //Glfw.SetWindowSizeCallback(glWindow, (GlfwWindowPtr wnd, int width, int height) =>
            //{
            //    //change window size here
            //});
            AddWbControlToMainWindow(f1);

            while (!GlfwApp.ShouldClose())
            {
                MyCef3InitEssential.CefDoMessageLoopWork();
                Glfw.PollEvents();
            }

            /////////////////////////////////////////////
            MyCef3InitEssential.ClearRemainingCefMsg();
            MyCef3InitEssential.ShutDownCef3();
            /////////////////////////////////////////////
            Glfw.Terminate();
        }
Exemplo n.º 5
0
        public static void Start()
        {
            GlfwWindowEventListener winEventListener = new GlfwWindowEventListener();
            var form = new GlFwForm(800, 600, "hello!", winEventListener);

            form.MakeCurrent();

            string versionStr3 = Marshal.PtrToStringAnsi(Glfw3.glfwGetVersionString());


            OpenTK.Platform.Factory.GetCustomPlatformFactory = () => OpenTK.Platform.Egl.EglAngle.NewFactory();
            OpenTK.Toolkit.Init(new OpenTK.ToolkitOptions {
                Backend = OpenTK.PlatformBackend.PreferNative,
            });
            OpenTK.Graphics.PlatformAddressPortal.GetAddressDelegate = OpenTK.Platform.Utilities.CreateGetAddress();

            //-----------
            IntPtr currentContext = Glfw3.glfwGetCurrentContext();
            var    contextHandler = new OpenTK.ContextHandle(currentContext);

            var glfwContext = new GLFWContextForOpenTK(contextHandler);
            var context     = OpenTK.Graphics.GraphicsContext.CreateExternalContext(glfwContext);


            bool isCurrent   = context.IsCurrent;
            var  demoContext = new Mini.GLDemoContext(800, 600);

            demoContext.LoadDemo(new OpenTkEssTest.T108_LionFill());

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.ClearColor(1, 1, 1, 1);
            //--------------------------------------------------------------------------------
            //setup viewport size
            //set up canvas
            int ww_w = 800;
            int ww_h = 600;
            int max  = Math.Max(ww_w, ww_h);

            GL.Viewport(0, 0, max, max);

            //---------
            form.RenderDel = () =>
            {
                demoContext.Render();
                form.SwapBuffers();
            };
            //---------

            GlfwAppLoop.Run();
        }
Exemplo n.º 6
0
        public void CreateMainForm()
        {
            int           w = 800, h = 600;
            GlFwForm      form1          = new GlFwForm(w, h, "PixelFarm on GLfw and GLES2");
            MyRootGraphic myRootGfx      = new MyRootGraphic(w, h, s_textServices);
            var           canvasViewport = new UISurfaceViewportControl();

            canvasViewport.InitRootGraphics(myRootGfx, myRootGfx.TopWinEventPortal, InnerViewportKind.GLES);
            canvasViewport.SetBounds(0, 0, w, h);
            form1.Controls.Add(canvasViewport);


            //demoContext2.LoadDemo(new T45_TextureWrap());
            //demoContext2.LoadDemo(new T48_MultiTexture());
            //demoContext2.LoadDemo(new T107_1_DrawImages());
            _demoBase = new OpenTkEssTest.T108_LionFill();//new T45_TextureWrap(),T48_MultiTexture()
            //_demoBase = new T110_DrawText();
            //_demoBase = new T107_1_DrawImages();

            _demoContext = new GLDemoContext(w, h);
            _demoContext.SetTextPrinter(painter =>
            {
                var printer         = new PixelFarm.DrawingGL.GLBitmapGlyphTextPrinter(painter, s_textServices);
                painter.TextPrinter = printer;
                //create text printer for opengl
                //----------------------
                //1. win gdi based
                //var printer = new WinGdiFontPrinter(canvas2d, w, h);
                //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 AggFontPrinter(canvasPainter, w, h);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //4. texture atlas based font texture
                //------------
                //resolve request font
                //var printer = new GLBmpGlyphTextPrinter(canvasPainter, YourImplementation.BootStrapWinGdi.myFontLoader);
                //canvasPainter.TextPrinter = printer;
            });


            form1.SetDrawFrameDelegate(e => _demoContext.Render());
            _demoContext.LoadDemo(_demoBase);
        }
Exemplo n.º 7
0
        public static void Start()
        {
            if (!GLFWPlatforms.Init())
            {
                Console.WriteLine("can't init");
                return;
            }


            GlFwForm form1 = new GlFwForm(
                800,
                600,
                "PixelFarm on GLfw and OpenGLES2");

            //----------------
            //this not need if we use glfwcontext for opentk
            // new OpenTK.Graphics.ES20.GL().LoadEntryPoints();
            //----------------

            //var demo = new OpenTkEssTest.T52_HelloTriangle2();
            //var demo = new OpenTkEssTest.T107_SampleDrawImage();
            //var demo = new OpenTkEssTest.T107_SampleDrawImage();
            var demoContext = new Mini.GLDemoContext(800, 600);

            demoContext.LoadDemo(new OpenTkEssTest.T108_LionFill());
            ////var demo = new OpenTkEssTest.T107_SampleDrawImage();

            form1.SetDrawFrameDelegate(e =>
            {
                demoContext.Render();
                //demo.Render();
            });

            //---------------------------------
            GlFwForm f2 = new GlFwForm(800, 600, "Form2");

            f2.SetDrawFrameDelegate(e =>
            {
                //simple draw
                GL.ClearColor(0, 1, 1, 1);
            });

            GlfwApp.RunMainLoop();

            demoContext.Close();
        }
Exemplo n.º 8
0
        public void CreateMainForm(int w, int h)
        {
            GlFwForm      form1          = new GlFwForm(w, h, "PixelFarm on GLfw and GLES2");
            MyRootGraphic myRootGfx      = new MyRootGraphic(w, h, s_textServices);
            var           canvasViewport = new UISurfaceViewportControl();

            canvasViewport.InitRootGraphics(myRootGfx, myRootGfx.TopWinEventPortal, InnerViewportKind.GLES);
            canvasViewport.SetBounds(0, 0, w, h);
            form1.Controls.Add(canvasViewport);


            _surfaceViewport = canvasViewport;
            LayoutFarm.AppHostNeutral appHost = new LayoutFarm.AppHostNeutral(canvasViewport);
            form1.SetDrawFrameDelegate(e =>
            {
                _surfaceViewport.PaintMeFullMode();
            });
            if (_app != null)
            {
                appHost.StartApp(_app);//start app
                canvasViewport.TopDownRecalculateContent();
                canvasViewport.PaintMe();
            }
        }
Exemplo n.º 9
0
        public static void Start()
        {
            if (!GLFWPlatforms.Init())
            {
                Console.WriteLine("can't init");
            }

            Glfw.SwapInterval(1);

            GlFwForm form1 = GlfwApp.CreateGlfwForm(
                800,
                600,
                "PixelFarm on GLfw and OpenGLES2");

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

            //----------------
            //this not need if we use glfwcontext for opentk
            // new OpenTK.Graphics.ES20.GL().LoadEntryPoints();
            //----------------

            //var demo = new OpenTkEssTest.T52_HelloTriangle2();
            //var demo = new OpenTkEssTest.T107_SampleDrawImage();
            //var demo = new OpenTkEssTest.T107_SampleDrawImage();
            var demo = new OpenTkEssTest.T108_LionFill();

            demo.Width  = 800;
            demo.Height = 600;
            demo.InitGLProgram();
            //var demo = new OpenTkEssTest.T107_SampleDrawImage();
            //demo.Width = 800;
            //demo.Height = 600;
            //--------------------------------------------------------------------------------
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.ClearColor(1, 1, 1, 1);
            //--------------------------------------------------------------------------------
            //setup viewport size
            //set up canvas
            int ww_w = 800;
            int ww_h = 600;
            int max  = Math.Max(ww_w, ww_h);

            //GL.Viewport(0, 0, 800, 600);
            GL.Viewport(0, 0, max, max);
            //--------------------------------------------------------------------------------
            form1.SetDrawFrameDelegate(() =>
            {
                demo.Render();
            });

            //---------------------------------
            GlFwForm f2 = GlfwApp.CreateGlfwForm(
                800,
                600,
                "Form 2");

            f2.MakeCurrent();
            f2.Activate();
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.ClearColor(1, 1, 1, 1);
            //GL.Viewport(0, 0, 800, 600);
            GL.Viewport(0, 0, max, max);
            //---------------------------------
            f2.SetDrawFrameDelegate(() =>
            {
                GL.ClearColor(0, 1, 1, 1);
            });
            while (!GlfwApp.ShouldClose())
            {
                //---------------
                //render phase and swap
                GlfwApp.UpdateWindowsFrame();
                /* Poll for and process events */
                Glfw.PollEvents();
            }
            demo.Close();
            Glfw.Terminate();
        }
Exemplo n.º 10
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;

            form1.SetDrawFrameDelegate(() =>
            {
                if (needUpdateContent)
                {
                    UpdateViewContent(formRenderUpdateEventArgs);
                }
                canvasGL2d.Clear(Color.Blue);
                canvasGL2d.DrawImage(glBmp, 0, 600);
            });



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

            Glfw.Terminate();
        }
Exemplo n.º 11
0
        public static void Start(string[] args)
        {
            if (!Glfw.Init())
            {
                Console.WriteLine("can't init glfw");
                return;
            }
            //this is designed for cef UI process.
            //this process starts before any subprocess.
            //so before load anything we should check
            //  if essential libs are available
            //------------------------------------------
            LibFolderManager.CheckNativeLibs();
            //------------------------------------------


            MyCef3InitEssential.SkipPreRun(true);
            //------------------------------------------
            //1. load cef before OLE init (eg init winform) ***
            //see more detail ...  MyCef3InitEssential
            if (!MyCef3InitEssential.LoadAndInitCef3(args))
            {
                return;
            }
            //------------------------------------------
            //1. if this is main UI process
            //the code go here, and we just start
            //winform app as usual
            //2. if this is other process
            //mean this process is finish and will terminate soon.
            //so we do noting, just exit!
            //(***please note that
            //*** we call ShutDownCef3 only in main thread ***)

            if (!MyCef3InitEssential.IsInMainProcess)
            {
                MyCef3InitEssential.ClearRemainingCefMsg();
                return;
            }



            //------------------------------------------
            /////////////////////////////////////////////
            //this code is run only in main process
            //------------------------------------------
            GlFwForm glfwForm = GlfwApp.CreateGlfwForm(
                800, 600,
                "Native CefBrowser, Press any key to start browse the web");
            ////---------------


            MyFormWrapper formMain = new MyFormWrapper(glfwForm.Handle);

            //add cef-browser into glfw form
            cefBrowser = new MyCefBrowser(
                formMain,
                0, 0, 800, 600,
                "about:blank", false);

            //
            //Form f1 = Form.CreateFromNativeWindowHwnd2(glfwForm.Handle);
            //f1.Width = glfwForm.Width;
            //f1.Height = glfwForm.Height;

            //Glfw.SetWindowSizeCallback(glWindow, (GlfwWindowPtr wnd, int width, int height) =>
            //{
            //    //change window size here
            //});
            //AddWbControlToMainWindow(f1);

            bool isCreated = false;

            while (!GlfwApp.ShouldClose())
            {
                //gl
                if (!isCreated)
                {
                    if (cefBrowser.IsBrowserCreated)
                    {
                        cefBrowser.NavigateTo("https://html5test.com");
                        isCreated = true;
                    }
                }
                MyCef3InitEssential.CefDoMessageLoopWork();
                Glfw.PollEvents();
            }

            /////////////////////////////////////////////
            MyCef3InitEssential.ClearRemainingCefMsg();
            MyCef3InitEssential.ShutDownCef3();
            //(***please note that
            //*** we call ShutDownCef3 only in main thread ***)


            Glfw.Terminate();
        }
Exemplo n.º 12
0
        public static void Start()
        {
            //---------------------------------------------------
            //register image loader
            Mini.DemoHelper.RegisterImageLoader(LoadImage);
            PixelFarm.Platforms.StorageService.RegisterProvider(file_storageProvider);
            //---------------------------------------------------
            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);


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

            FormRenderUpdateEventArgs formRenderUpdateEventArgs = new FormRenderUpdateEventArgs();

            formRenderUpdateEventArgs.form = form1;

            GlfwGLES2 glfwApp = new GlfwGLES2();

            form1.SetDrawFrameDelegate(() =>
            {
                glfwApp.UpdateViewContent(formRenderUpdateEventArgs);
            });



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

            Glfw.Terminate();
        }
Exemplo n.º 13
0
        static void Init(GlFwForm form)
        {
            //PART1:
            //1. storage io
            PixelFarm.Platforms.StorageService.RegisterProvider(new YourImplementation.LocalFileStorageProvider(""));

            //2. img-io implementation
            PixelFarm.CpuBlit.MemBitmapExt.DefaultMemBitmapIO = new YourImplementation.ImgCodecMemBitmapIO(); // new PixelFarm.Drawing.WinGdi.GdiBitmapIO();
            //PixelFarm.CpuBlit.MemBitmapExtensions.DefaultMemBitmapIO = new PixelFarm.Drawing.WinGdi.GdiBitmapIO();

            //------------------------------------------------------------------------
            //
            //if we don't set this, it will error on read-write image
            //you can implement this with other lib that can read-write images

            var pars = new PixelFarm.Platforms.ImageIOSetupParameters();

            pars.SaveToPng = (IntPtr imgBuffer, int stride, int width, int height, string filename) =>
            {
                MemBitmap memBmp = new MemBitmap(width, height, imgBuffer);
                using (FileStream fs = new FileStream(filename, FileMode.Create))
                {
                    PixelFarm.CpuBlit.MemBitmapExt.DefaultMemBitmapIO.SaveImage(memBmp, fs,
                                                                                MemBitmapIO.OutputImageFormat.Png,
                                                                                null);
                }

                //---save with GDI+---
                //using (System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                //{
                //    PixelFarm.CpuBlit.BitmapHelper.CopyToGdiPlusBitmapSameSize(imgBuffer, newBmp);
                //    //save
                //    newBmp.Save(filename);
                //}
            };
            pars.ReadFromMemStream = (System.IO.MemoryStream ms, string kind) =>
            {
                return(PixelFarm.CpuBlit.MemBitmapExt.DefaultMemBitmapIO.LoadImage(ms));
                //read/guest img format

                //--- load img with GDI+---
                ////read
                //using (System.Drawing.Bitmap gdiBmp = new System.Drawing.Bitmap(ms))
                //{
                //    PixelFarm.CpuBlit.MemBitmap memBmp = new PixelFarm.CpuBlit.MemBitmap(gdiBmp.Width, gdiBmp.Height);
                //    //#if DEBUG
                //    //                        memBmp._dbugNote = "img;
                //    //#endif

                //    PixelFarm.CpuBlit.BitmapHelper.CopyFromGdiPlusBitmapSameSizeTo32BitsBuffer(gdiBmp, memBmp);
                //    return memBmp;
                //}
            };
            PixelFarm.Platforms.ImageIOPortal.Setup(pars);
            //------------------------------------------------------------------------


            //3. setup text-breaker
            string icu_datadir = "brkitr"; //see brkitr folder, we link data from Typography project and copy to output if newer

            if (!System.IO.Directory.Exists(icu_datadir))
            {
                throw new System.NotSupportedException("dic");
            }
            Typography.TextBreak.CustomBreakerBuilder.Setup(new Typography.TextBreak.IcuSimpleTextFileDictionaryProvider()
            {
                DataDir = icu_datadir
            });

            //---------------------------------------------------------------------------
            //4. Typography TextService
            Typography.Text.OpenFontTextService textService = new Typography.Text.OpenFontTextService();
            textService.LoadFontsFromFolder("Fonts");
            Typography.Text.TextServiceClient serviceClient = textService.CreateNewServiceClient();
            GlobalTextService.TextService = serviceClient;
            //---------------------------------------------------------------------------

            //PART2: root graphics
            Size primScreenSize = UIPlatform.CurrentPlatform.GetPrimaryMonitorSize();

            s_myRootGfx = new MyRootGraphic(primScreenSize.Width, primScreenSize.Height);
            s_viewroot  = new GraphicsViewRoot(primScreenSize.Width, primScreenSize.Height);
            MyGlfwTopWindowBridge bridge1 = new MyGlfwTopWindowBridge(s_myRootGfx, s_myRootGfx.TopWinEventPortal);

            ((MyGlfwTopWindowBridge.GlfwEventBridge)(form.WindowEventListener)).SetWindowBridge(bridge1);


            var glfwWindowWrapper = new GlfwWindowWrapper(form);

            bridge1.BindWindowControl(glfwWindowWrapper);

            s_viewroot.InitRootGraphics(s_myRootGfx,
                                        s_myRootGfx.TopWinEventPortal,
                                        InnerViewportKind.GLES,
                                        glfwWindowWrapper,
                                        bridge1);



            //------------------------------------------------------------------------
            //optional:
            if (s_viewroot.GetGLPainter() is GLPainter glPainter)
            {
                glPainter.SmoothingMode = SmoothingMode.AntiAlias;
            }
        }
Exemplo n.º 14
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();
        }