private void CloseCurrentApp() { if (currentApp != null) { currentApp.DeInit(); } // Clean up currentApp = null; if (currentControl != null) { currentControl.HandleCreated -= renderControl_HandleCreated; currentControl.Dispose(); renderPanel.Controls.Remove(currentControl); currentControl = null; } if (currentHost != null) { currentHost.Dispose(); currentHost = null; } // Just in case... GC.Collect(); GC.WaitForPendingFinalizers(); }
private void renderControl_HandleCreated(object sender, EventArgs e) { // STEP TWO - Now the underlying Windows Window was created - we can hook OpenGL on it. // // Take this as an example how to hook up any FUSEE application with a given Winforms form: // Then instantiate your app (could be as well _currentApp = new MyOwnRenderCanvasDerivedClass(); ) // Inject Fusee.Engine.Base InjectMe dependencies // FrameRateLogger _fRL = new FrameRateLogger(); // start logging frame rate on console // connect UDPReceiver with PointCloudReader PointCloudReader.StartStreamingUDPCallback += new UDPReceiver().StreamFrom; // Inject Fusee.Engine.Base InjectMe dependencies IO.IOImp = new Fusee.Base.Imp.Desktop.IOImp(); var fap = new Fusee.Base.Imp.Desktop.FileAssetProvider("Assets"); fap.RegisterTypeHandler( new AssetHandler { ReturnedType = typeof(Font), Decoder = delegate(string id, object storage) { if (!Path.GetExtension(id).ToLower().Contains("ttf")) { return(null); } return(new Font { _fontImp = new FontImp((Stream)storage) }); }, Checker = id => Path.GetExtension(id).ToLower().Contains("ttf") }); fap.RegisterTypeHandler( new AssetHandler { ReturnedType = typeof(SceneContainer), Decoder = delegate(string id, object storage) { if (!Path.GetExtension(id).ToLower().Contains("fus")) { return(null); } var ser = new Serializer(); return(ser.Deserialize((Stream)storage, null, typeof(SceneContainer)) as SceneContainer); }, Checker = id => Path.GetExtension(id).ToLower().Contains("fus") }); AssetStorage.RegisterProvider(fap); // First create a WinformsHost around the control currentHost = new WinformsHost(currentControl, canvaspanel); currentApp = new Core.PointVisualizationBase(); currentApp.UDPReceiver = new UDPReceiver(); // Now use the host as the canvas AND the input implementation of your App // Inject Fusee.Engine InjectMe dependencies (hard coded) currentApp.CanvasImplementor = currentHost; currentApp.ContextImplementor = new Fusee.Engine.Imp.Graphics.Desktop.RenderContextImp(currentApp.CanvasImplementor); Input.AddDriverImp(currentHost); Input.AddDriverImp(new Fusee.Engine.Imp.Graphics.Desktop.WindowsTouchInputDriverImp(currentHost.canvas)); //// If not already done, show the window. currentControl.Show(); //// Then you can run the app currentApp.Run(); }