Exemplo n.º 1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // Default initializations
            SeeingSharpApplication.InitializeAsync(
                Assembly.GetExecutingAssembly(),
                new Assembly[] {
                typeof(GraphicsCore).Assembly
            },
                new string[0]).Wait();
            SeeingSharpApplication.Current.InitializeUIEnvironment();
            GraphicsCore.Initialize();
        }
Exemplo n.º 2
0
        public async Task MemoryRenderTarget_2DFallbackRendering()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            using (GraphicsCore.AutomatedTest_NewTestEnviornment())
            {
                GraphicsCore.Initialize(
                    enableDebug: false,
                    force2DFallback: true);
                Assert.True(GraphicsCore.IsInitialized);

                Polygon2D polygon = new Polygon2D(new Vector2[]
                {
                    new Vector2(10, 10),
                    new Vector2(900, 100),
                    new Vector2(800, 924),
                    new Vector2(50, 1014),
                    new Vector2(10, 10)
                });
                using (SolidBrushResource solidBrush = new SolidBrushResource(Color4.LightGray))
                    using (SolidBrushResource solidBrushBorder = new SolidBrushResource(Color4.Gray))
                        using (PolygonGeometryResource polygonGeometry = new PolygonGeometryResource(polygon))
                            using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024))
                            {
                                // Perform rendering
                                memRenderTarget.ClearColor = Color4.CornflowerBlue;
                                await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync((graphics) =>
                                {
                                    // 2D rendering is made here
                                    graphics.DrawGeometry(polygonGeometry, solidBrushBorder, 3f);
                                    graphics.FillGeometry(polygonGeometry, solidBrush);
                                });

                                await memRenderTarget.AwaitRenderAsync();

                                // Take screenshot
                                GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                                //screenshot.DumpToDesktop("Blub.png");

                                // Calculate and check difference
                                float diff = BitmapComparison.CalculatePercentageDifference(
                                    screenshot, Properties.Resources.ReferenceImage_SimpleGeometry2D);
                                Assert.True(diff < 0.2, "Difference to reference image is to big!");
                            }
            }
        }
Exemplo n.º 3
0
        public void Initialize(CoreApplicationView applicationView)
        {
            SeeingSharpApplication.InitializeAsync(
                this.GetType().GetTypeInfo().Assembly,
                new Assembly[]
            {
                typeof(SeeingSharpApplication).GetTypeInfo().Assembly,
                typeof(GraphicsCore).GetTypeInfo().Assembly
            },
                new string[] { }).Wait();
            GraphicsCore.Initialize(enableDebug: true);

            applicationView.Activated += this.OnViewActivated;

            // Register event handlers for app lifecycle.
            CoreApplication.Suspending += this.OnSuspending;
            CoreApplication.Resuming   += this.OnResuming;
        }
Exemplo n.º 4
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Default initializations
            SeeingSharpApplication.InitializeAsync(
                Assembly.GetExecutingAssembly(),
                new Assembly[] {
                typeof(GraphicsCore).Assembly
            },
                new string[0]).Wait();
            GraphicsCore.Initialize();

            // Run the application
            MainWindow mainWindow = new MainWindow();

            SeeingSharpApplication.Current.InitializeUIEnvironment();
            Application.Run(mainWindow);
        }
Exemplo n.º 5
0
        public static async Task InitializeWithGrahicsAsync()
        {
            // Initialize main application singleton
            if (!SeeingSharpApplication.IsInitialized)
            {
                await SeeingSharpApplication.InitializeAsync(
                    Assembly.GetExecutingAssembly(),
                    new Assembly[] { typeof(GraphicsCore).Assembly },
                    new string[0]);
            }

            // Initialize the graphics engine
            if (!GraphicsCore.IsInitialized)
            {
                GraphicsCore.Initialize();
                GraphicsCore.Current.SetDefaultDeviceToSoftware();
                GraphicsCore.Current.DefaultDevice.ForceDetailLevel(DetailLevel.High);
            }

            Assert.True(GraphicsCore.IsInitialized, "GraphicsCore could not be initialized!");
        }
Exemplo n.º 6
0
        protected async override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // Default initializations
            await SeeingSharpApplication.InitializeAsync(
                Assembly.GetExecutingAssembly(),
                new Assembly[] {
                typeof(GraphicsCore).Assembly
            },
                new string[0]);

            // Initialize UI and Graphics
            SeeingSharpApplication.Current.InitializeUIEnvironment();
            GraphicsCore.Initialize();

            // Load the main window
            MainWindow mainWindow = new SeeingSharpModelViewer.MainWindow();

            SeeingSharpApplication.Current.InitializeAutoErrorReporting_Wpf(this, mainWindow);
            mainWindow.Show();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Wird aufgerufen, wenn die Anwendung durch den Endbenutzer normal gestartet wird.  Weitere Einstiegspunkte
        /// werden z. B. verwendet, wenn die Anwendung gestartet wird, um eine bestimmte Datei zu öffnen.
        /// </summary>
        /// <param name="e">Details über Startanforderung und -prozess.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
            // Initialize application and graphics
            if (!SeeingSharpApplication.IsInitialized)
            {
                await SeeingSharpApplication.InitializeAsync(
                    this.GetType().GetTypeInfo().Assembly,
                    new Assembly[]
                {
                    typeof(SeeingSharpApplication).GetTypeInfo().Assembly,
                    typeof(GraphicsCore).GetTypeInfo().Assembly
                },
                    new string[] { e.Arguments });

                GraphicsCore.Initialize();

                // Force high texture quality on tablet devices
                foreach (EngineDevice actDevice in GraphicsCore.Current.LoadedDevices)
                {
                    if (actDevice.IsSoftware)
                    {
                        continue;
                    }
                    actDevice.Configuration.TextureQuality = TextureQuality.Hight;
                }

                // Initialize the UI environment
                SeeingSharpApplication.Current.InitializeUIEnvironment();
            }

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }

            // Ensure the current window is active
            Window.Current.Activate();
        }
Exemplo n.º 8
0
        public async Task MemoryRenderTarget_2DInitError()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            GDI.Bitmap screenshot = null;
            using (UnitTestHelper.FailTestOnInternalExceptions())
                using (GraphicsCore.AutomatedTest_NewTestEnviornment())
                    using (GraphicsCore.AutomatedTest_ForceD2DInitError())
                    {
                        GraphicsCore.Initialize();
                        Assert.True(GraphicsCore.IsInitialized);
                        Assert.False(GraphicsCore.Current.DefaultDevice.Supports2D);

                        using (SolidBrushResource solidBrush = new SolidBrushResource(Color4.Gray))
                            using (TextFormatResource textFormat = new TextFormatResource("Arial", 36))
                                using (SolidBrushResource textBrush = new SolidBrushResource(Color4.RedColor))
                                    using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024))
                                    {
                                        memRenderTarget.ClearColor = Color4.CornflowerBlue;

                                        // Get and configure the camera
                                        PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D;
                                        camera.Position = new Vector3(0f, 5f, -7f);
                                        camera.Target   = new Vector3(0f, 0f, 0f);
                                        camera.UpdateCamera();

                                        // 2D rendering is made here
                                        Custom2DDrawingLayer d2dDrawingLayer = new Custom2DDrawingLayer((graphics) =>
                                        {
                                            RectangleF d2dRectangle = new RectangleF(10, 10, 236, 236);
                                            graphics.Clear(Color4.LightBlue);
                                            graphics.FillRoundedRectangle(
                                                d2dRectangle, 30, 30,
                                                solidBrush);

                                            d2dRectangle.Inflate(-10, -10);
                                            graphics.DrawText("Hello Direct2D!", textFormat, d2dRectangle, textBrush);
                                        });

                                        // Define scene
                                        await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) =>
                                        {
                                            var resD2DTexture = manipulator.AddResource <Direct2DTextureResource>(
                                                () => new Direct2DTextureResource(d2dDrawingLayer, 256, 256));
                                            var resD2DMaterial = manipulator.AddSimpleColoredMaterial(resD2DTexture);
                                            var geoResource    = manipulator.AddResource <GeometryResource>(
                                                () => new GeometryResource(new PalletType(
                                                                               palletMaterial: NamedOrGenericKey.Empty,
                                                                               contentMaterial: resD2DMaterial)));

                                            GenericObject newObject = manipulator.AddGeneric(geoResource);
                                            newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                                            newObject.Scaling       = new Vector3(2f, 2f, 2f);
                                        });

                                        // Take screenshot
                                        await memRenderTarget.AwaitRenderAsync();

                                        screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                                        //screenshot.DumpToDesktop("Blub.png");
                                    }
                    }

            // Calculate and check difference
            Assert.NotNull(screenshot);
            bool isNearEqual = BitmapComparison.IsNearEqual(
                screenshot, Properties.Resources.ReferenceImage_SimpleObject);

            Assert.True(isNearEqual, "Difference to reference image is to big!");
        }