Exemplo n.º 1
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            pointers = new List <PointerData>();
            // Get the Screen size
            var    bounds = Window.Current.Bounds;
            double height = bounds.Height;
            double width  = bounds.Width;

            Debug.WriteLine("Screen width:" + width + "  Screen height" + height);
            _Rect.Width  = width;
            _Rect.Height = height;

            int pixelWidth  = (int)(_Rect.Width * DisplayProperties.LogicalDpi / 96.0);
            int pixelHeight = (int)(_Rect.Height * DisplayProperties.LogicalDpi / 96.0);

            #region sharpDX Initialization

            // Use Rectangle that makes sharpDX to draw
            d2dBrush   = new ImageBrush();
            _Rect.Fill = d2dBrush;

            // Safely dispose any previous instance
            // Creates a new DeviceManager (Direct3D, Direct2D, DirectWrite, WIC)
            deviceManager = new DeviceManager();

            // New CubeRenderer
            shapeRenderer = new ShapeRenderer(pointers);
            fpsRenderer   = new FpsRenderer();

            d2dTarget            = new SurfaceImageSourceTarget(pixelWidth, pixelHeight);
            d2dBrush.ImageSource = d2dTarget.ImageSource;

            // Add Initializer to device manager
            deviceManager.OnInitialize += d2dTarget.Initialize;
            deviceManager.OnInitialize += shapeRenderer.Initialize;
            deviceManager.OnInitialize += fpsRenderer.Initialize;


            // Render the cube within the CoreWindow
            d2dTarget.OnRender += shapeRenderer.Render;
            d2dTarget.OnRender += fpsRenderer.Render;

            // Initialize the device manager and all registered deviceManager.OnInitialize
            deviceManager.Initialize(DisplayProperties.LogicalDpi);

            // Setup rendering callback
            CompositionTarget.Rendering += CompositionTarget_Rendering;

            // Callback on DpiChanged
            DisplayProperties.LogicalDpiChanged += DisplayProperties_LogicalDpiChanged;

            #endregion
        }
Exemplo n.º 2
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            pointers = new List<PointerData>();
            // Get the Screen size
            var bounds = Window.Current.Bounds;
            double height = bounds.Height;
            double width = bounds.Width;
            Debug.WriteLine("Screen width:" + width + "  Screen height" + height);
            _Rect.Width = width;
            _Rect.Height = height;

            int pixelWidth = (int)(_Rect.Width * DisplayProperties.LogicalDpi / 96.0);
            int pixelHeight = (int)(_Rect.Height * DisplayProperties.LogicalDpi / 96.0);

            #region sharpDX Initialization

            // Use Rectangle that makes sharpDX to draw
            d2dBrush = new ImageBrush();
            _Rect.Fill = d2dBrush;

            // Safely dispose any previous instance
            // Creates a new DeviceManager (Direct3D, Direct2D, DirectWrite, WIC)
            deviceManager = new DeviceManager();

            // New CubeRenderer
            shapeRenderer = new ShapeRenderer(pointers);
            fpsRenderer = new FpsRenderer();

            d2dTarget = new SurfaceImageSourceTarget(pixelWidth, pixelHeight);
            d2dBrush.ImageSource = d2dTarget.ImageSource;

            // Add Initializer to device manager
            deviceManager.OnInitialize += d2dTarget.Initialize;
            deviceManager.OnInitialize += shapeRenderer.Initialize;
            deviceManager.OnInitialize += fpsRenderer.Initialize;

            // Render the cube within the CoreWindow
            d2dTarget.OnRender += shapeRenderer.Render;
            d2dTarget.OnRender += fpsRenderer.Render;

            // Initialize the device manager and all registered deviceManager.OnInitialize
            deviceManager.Initialize(DisplayProperties.LogicalDpi);

            // Setup rendering callback
            CompositionTarget.Rendering += CompositionTarget_Rendering;

            // Callback on DpiChanged
            DisplayProperties.LogicalDpiChanged += DisplayProperties_LogicalDpiChanged;

            #endregion
        }