示例#1
0
        protected override void OnDraw(FrameArgs e)
        {
            base.OnDraw(e);

            // the first stage draws the sprite to the frame buffer with
            // a horizontal blur
            using (_fbcam.Begin()) {             // using the camera...
                using (_fb.Begin()) {            // ...and drawing to buffer...
                    using (_matHblur.Begin()) {  // ...and blur mat...
                        // since a material was put in scope, it overrides
                        // the sprite's built-in material
                        _sprites["star"].Draw(Matrix4.Identity);
                    }
                }
            }

            // the second stage draws the sprite with a vertical blur
            // to the screen. normal sprites are drawn last to create
            // a glow effect on the rightmost sprite.
            using (_cam.Begin()) {
                using (_matVblur.Begin()) {
                    // draw blurred sprite in middle
                    _quad.Draw(Matrix4.Identity);
                    // draw blurred sprighte on right
                    _quad.Draw(Matrix4.CreateTranslation(128, 0, 0));
                }
                // draw sprite on left
                _sprites["star"].Draw(Matrix4.CreateTranslation(-128, 0, 1));
                // draw sprite on right on top of blurred sprite
                _sprites["star"].Draw(Matrix4.CreateTranslation(128, 0, 1));
            }
        }
示例#2
0
        void FadeTo(Scene nextScene, Start startArgs, FrameArgs frameArgs)
        {
            if (_scene == null)
            {
                throw new InvalidOperationException("No current scene to crossfade from!");
            }

            var prevScene = _scene;

            _scene = nextScene;
            _t     = 0;

            _fading = true;

            if (_duration <= 0)
            {
                Skip();
            }
            else
            {
                if (_prevTexture == null)
                {
                    _prevTexture = new Texture(new System.Drawing.Size((int)startArgs.Size.X, (int)startArgs.Size.Y));
                }
                if (_nextTexture == null)
                {
                    _nextTexture = new Texture(new System.Drawing.Size((int)startArgs.Size.X, (int)startArgs.Size.Y));
                }
                if (_prevFBO == null)
                {
                    _prevFBO = new FrameBuffer(_prevTexture);
                }
                if (_nextFBO == null)
                {
                    _nextFBO = new FrameBuffer(_nextTexture);
                }

                using (_prevFBO.Begin()) {
                    if (prevScene != null)
                    {
                        prevScene.DrawNow(frameArgs);
                    }
                    else
                    {
                        base.OnDraw(frameArgs);
                    }
                }

                View.RenderNow();
            }

            if (prevScene != null && _disposeCurrent)
            {
                prevScene.Dispose();
            }

            View.LoadFrame();
        }
示例#3
0
        public static CubeMapTexture Generate(int seed, int resolution, int samples)
        {
            var rand = seed == 0 ? new Random() : new Random(seed);

            var stars = Star.Generate(rand, rand.Next(16384, 32768));
            var dusts = DustCloud.Generate(rand, rand.Next(4096, 8192));

            int renderResolution = resolution * samples;

            var camera = new Camera(renderResolution, renderResolution, MathHelper.PiOver2, 4f, 64f);

            var starShader = new StarShader {
                Camera = camera
            };
            var dustShader = new DustCloudShader {
                Camera = camera
            };

            var target = new FrameBuffer(new BitmapTexture2D(new Bitmap(renderResolution, renderResolution)), 16);

            var angles = new[] {
                Tuple.Create(0f, MathHelper.PiOver2),
                Tuple.Create(0f, -MathHelper.PiOver2),
                Tuple.Create(MathHelper.PiOver2, 0f),
                Tuple.Create(-MathHelper.PiOver2, 0f),
                Tuple.Create(0f, 0f),
                Tuple.Create(0f, MathHelper.Pi)
            };

            var bmps = new Bitmap[6];

            target.Begin();

            GL.ClearColor(Color.Black);

            var bmp = new Bitmap(renderResolution, renderResolution);

            for (int i = 0; i < 6; ++i)
            {
                camera.Pitch = angles[i].Item1;
                camera.Yaw   = angles[i].Item2;

                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                dustShader.BeginBatch();
                foreach (var dust in dusts)
                {
                    dustShader.Render(dust);
                }
                dustShader.EndBatch();

                starShader.BeginBatch();
                foreach (var star in stars)
                {
                    starShader.Render(star);
                }
                starShader.EndBatch();

                var data = bmp.LockBits(new Rectangle(0, 0, renderResolution, renderResolution), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                GL.ReadPixels(0, 0, renderResolution, renderResolution, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
                bmp.UnlockBits(data);

                bmps[i] = new Bitmap(bmp, new Size(resolution, resolution));
            }

            bmp.Dispose();
            target.End();
            target.Dispose();

            return(new CubeMapTexture(bmps[0], bmps[1], bmps[2], bmps[3], bmps[4], bmps[5]));
        }