Esempio n. 1
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            try
            {
                bmpSource = new OpenGLD3DImageUpdater();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                bmpSource = new OpenGLWriteableBitmapUpdater();
            }
            asyncResult = null;
            renderer    = new Renderer();
            CompositionTarget.Rendering += (o, args) =>
            {
                if (DateTime.Now.Subtract(this.lastMeasureTime) > TimeSpan.FromSeconds(1))
                {
                    this.Title           = this.frames + "fps";
                    this.frames          = 0;
                    this.lastMeasureTime = DateTime.Now;
                }
                if (this.asyncResult == null || this.asyncResult.IsCompleted)
                {
                    image.Source = bmpSource.EndRender(asyncResult);
                    var actualWidth  = this.ActualWidth;
                    var actualHeight = this.ActualHeight;
                    bmpSource.Size = new Size((int)actualWidth, (int)actualHeight);
                    if (this.bmpSource is OpenGLWriteableBitmapUpdater)
                    {
                        // call GC.collect every second(frames == 0)
                        if (this.frames == 0)
                        {
                            GC.Collect();
                        }
                        this.backbuffer = null;
                    }
                    this.asyncResult = bmpSource.BeginRender(
                        () =>
                    {
                        GL.MatrixMode(MatrixMode.Projection);
                        GL.LoadIdentity();
                        float halfWidth  = (float)(actualWidth / 2);
                        float halfHeight = (float)(actualHeight / 2);
                        GL.Ortho(-halfWidth, halfWidth, halfHeight, -halfHeight, 1000, -1000);
                        GL.Viewport(0, 0, (int)actualWidth, (int)actualHeight);

                        this.renderer.Render();
                    },
                        ref backbuffer);
                    this.frames++;
                }
            };
        }
Esempio n. 2
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            try
            {
                bmpSource = new OpenGLD3DImageUpdater();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                bmpSource = new OpenGLWriteableBitmapUpdater();
            }
            asyncResult = null;
            renderer = new Renderer();
            CompositionTarget.Rendering += (o, args) =>
            {
                if (DateTime.Now.Subtract(this.lastMeasureTime) > TimeSpan.FromSeconds(1))
                {
                    this.Title = this.frames + "fps";
                    this.frames = 0;
                    this.lastMeasureTime = DateTime.Now;
                }
                if (this.asyncResult == null || this.asyncResult.IsCompleted)
                {
                    image.Source = bmpSource.EndRender(asyncResult);
                    var actualWidth = this.ActualWidth;
                    var actualHeight = this.ActualHeight;
                    bmpSource.Size = new Size((int)actualWidth, (int)actualHeight);
                    if (this.bmpSource is OpenGLWriteableBitmapUpdater)
                    {
                        // call GC.collect every second(frames == 0)
                        if (this.frames == 0)
                        {
                            GC.Collect();
                        }
                        this.backbuffer = null;
                    }
                    this.asyncResult = bmpSource.BeginRender(
                        () =>
                        {
                            GL.MatrixMode(MatrixMode.Projection);
                            GL.LoadIdentity();
                            float halfWidth = (float)(actualWidth / 2);
                            float halfHeight = (float)(actualHeight / 2);
                            GL.Ortho(-halfWidth, halfWidth, halfHeight, -halfHeight, 1000, -1000);
                            GL.Viewport(0, 0, (int)actualWidth, (int)actualHeight);

                            this.renderer.Render();
                        },
                        ref backbuffer);
                    this.frames++;
                }
            };
        }