Пример #1
0
        public static byte[] GrabScreenshot(MainWindow game, int frontbuffer, bool yflip = false)
        {
            if (GraphicsContext.CurrentContext == null)
            {
                throw new GraphicsContextMissingException();
            }
            var backbuffer = game.MSAABuffer.Framebuffer;

            SafeFrameBuffer.BindFramebuffer(FramebufferTarget.ReadFramebuffer, backbuffer);
            SafeFrameBuffer.BindFramebuffer(FramebufferTarget.DrawFramebuffer, frontbuffer);
            if (yflip) //Screenshots are captured upside-down for some reason but this is corrected during video encoding, so flip here for a correctly oriented screenshot
            {
                SafeFrameBuffer.BlitFramebuffer(0, 0, game.RenderSize.Width, game.RenderSize.Height,
                                                0, game.RenderSize.Height, game.RenderSize.Width, 0,
                                                ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest);
            }
            else
            {
                SafeFrameBuffer.BlitFramebuffer(0, 0, game.RenderSize.Width, game.RenderSize.Height,
                                                0, 0, game.RenderSize.Width, game.RenderSize.Height,
                                                ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest);
            }
            SafeFrameBuffer.BindFramebuffer(FramebufferTarget.ReadFramebuffer, frontbuffer);

            GL.ReadPixels(0, 0, game.RenderSize.Width, game.RenderSize.Height,
                          OpenTK.Graphics.OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, _screenshotbuffer);
            SafeFrameBuffer.BindFramebuffer(FramebufferTarget.Framebuffer, backbuffer);
            return(_screenshotbuffer);
        }
Пример #2
0
        public static byte[] GrabScreenshot(MainWindow game, int frontbuffer)
        {
            if (GraphicsContext.CurrentContext == null)
            {
                throw new GraphicsContextMissingException();
            }
            var backbuffer = game.MSAABuffer.Framebuffer;

            SafeFrameBuffer.BindFramebuffer(FramebufferTarget.ReadFramebuffer, backbuffer);
            SafeFrameBuffer.BindFramebuffer(FramebufferTarget.DrawFramebuffer, frontbuffer);
            SafeFrameBuffer.BlitFramebuffer(0, 0, game.RenderSize.Width, game.RenderSize.Height,
                                            0, 0, game.RenderSize.Width, game.RenderSize.Height,
                                            ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest);
            SafeFrameBuffer.BindFramebuffer(FramebufferTarget.ReadFramebuffer, frontbuffer);

            GL.ReadPixels(0, 0, game.RenderSize.Width, game.RenderSize.Height,
                          OpenTK.Graphics.OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, _screenshotbuffer);
            SafeFrameBuffer.BindFramebuffer(FramebufferTarget.Framebuffer, backbuffer);
            return(_screenshotbuffer);
        }