Ejemplo n.º 1
0
        public override void InitRender(RenderContext context, Camera camera)
        {
            GL.Viewport(0, 0, context.ScreenPixelSize.X, context.ScreenPixelSize.Y);
            FrameBuffer.Bind();

            var bgColor = context.BackgroundColor;

            GL.ClearColor(context.BackgroundColor.X, bgColor.Y, bgColor.Z, bgColor.W);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
        }
        // --------------------------------------------------------------------

        public void Render()
        {
            mFrameBuffer.Bind();
            Onyx3DEngine.Instance.Renderer.Render(SceneManagement.ActiveScene, mCamera, mFrameBuffer.Width, mFrameBuffer.Height);
            mFrameBuffer.Unbind();
            pictureBox1.Image = mFrameBuffer.Texture.AsBitmap();
        }
        /// <summary>
        /// Binds and initialises a <see cref="FrameBuffer"/> if required.
        /// </summary>
        /// <param name="frameBuffer">The <see cref="FrameBuffer"/> to bind.</param>
        /// <returns>A token that must be disposed upon finishing use of <paramref name="frameBuffer"/>.</returns>
        protected IDisposable BindFrameBuffer(FrameBuffer frameBuffer)
        {
            // This setter will also take care of allocating a texture of appropriate size within the frame buffer.
            frameBuffer.Size = frameBufferSize;

            frameBuffer.Bind();

            return(new ValueInvokeOnDisposal <FrameBuffer>(frameBuffer, b => b.Unbind()));
        }
Ejemplo n.º 4
0
        // --------------------------------------------------------------------

        public void Render()
        {
            mFrameBuffer.Bind();
            OnyxInstance.Renderer.RenderScene(Scene, Scene.ActiveCamera, mFrameBuffer.Width, mFrameBuffer.Height);
            if (DrawGrid)
            {
                OnyxInstance.Renderer.Render(mGridRenderer, Scene.ActiveCamera);
            }
            mFrameBuffer.Unbind();
        }
        protected override void PreDraw()
        {
            frameBuffer.Bind();

            // Set viewport to the texture size
            GLWrapper.PushViewport(new Rectangle(0, 0, frameBuffer.Texture.Width, frameBuffer.Texture.Height));
            // We need to draw children as if they were zero-based to the top-left of the texture
            // so we make the new zero be this container's position without affecting children in any negative ways
            GLWrapper.PushOrtho(new Rectangle((int)ScreenSpaceDrawQuad.TopLeft.X, (int)ScreenSpaceDrawQuad.TopLeft.Y, frameBuffer.Texture.Width, frameBuffer.Texture.Height));

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
        }
 protected override void PreDrawMask(FrameBuffer clippingMask)
 {
     clippingMask.Bind();
     GLWrapper.PushViewport(new RectangleI(0, 0, clippingMask.Texture.Width, clippingMask.Texture.Height));
     GLWrapper.Clear(new ClearInfo(Colour4.White));
     GLWrapper.SetBlend(new BlendingParameters
     {
         Source           = BlendingType.Zero,
         Destination      = BlendingType.OneMinusSrcColor,
         SourceAlpha      = BlendingType.Zero,
         DestinationAlpha = BlendingType.OneMinusSrcAlpha,
     });
 }
Ejemplo n.º 7
0
        private void RenderPass1(RenderContext context, Camera camera)
        {
            GL.Viewport(0, 0, context.ScreenPixelSize.X, context.ScreenPixelSize.Y);
            GBuffer.Bind();
            GL.Enable(EnableCap.DepthTest);

            // At least gPosition requires Color = 0, so the Positions is 0. Used to stencil the background.
            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            Pass = DeferredPass.Pass1;
            foreach (var obj in GetRenderObjects(context, camera))
            {
                Render(context, camera, obj);
            }
        }
Ejemplo n.º 8
0
        private void GLElement_GLRenderStarted(object sender, EventArgs e)
        {
            #region FBO start
            if (UseFrameBuffer)
            {
                FBO.Activate();
                FBO.FBOInitializeView(GLElement1.PerspectiveProjection, TransformOuter.Location.Z);
            }
            else
            {
                FBO.Deactivate();
            }
            #endregion

            RenderToBuffer();

            #region FBO finish
            if (UseFrameBuffer)
            {
                FBO.Deactivate();

                GLElement1.InitializeView();
                GL.ClearColor(0, .3f, .5f, 1);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                GL.LoadIdentity();

                // Now bind the texture to use it
                GL.ActiveTexture(TextureUnit.Texture0);
                FBO.Bind();
                GLHelpers.Color4(Colors.Black); // to prevent it from being transparent

                // Tranform
                TransformOuter.Apply();

                // Render with shader
                LightingShaderProgram.Texture1 = FBO.Texture;
                LightingShaderProgram.Activate();
                //GLHelpers.Plane(1.3, 1.3, 0); // put it on a plane
                GLHelpers.Cube2D(1.7); // put it on a cube

                // Do some cleanup
                TransformOuter.Remove();
                Texture2D.Disable2DTextures();
                ShaderProgram.DisableShaders();
            }
            #endregion
        }
        private InvokeOnDisposal bindFrameBuffer(FrameBuffer frameBuffer, Vector2 requestedSize)
        {
            if (!frameBuffer.IsInitialized)
            {
                frameBuffer.Initialize();
            }

            // These additional render buffers are only required if e.g. depth
            // or stencil information needs to also be stored somewhere.
            foreach (var f in Formats)
            {
                frameBuffer.Attach(f);
            }

            // This setter will also take care of allocating a texture of appropriate size within the framebuffer.
            frameBuffer.Size = requestedSize;

            frameBuffer.Bind();

            return(new InvokeOnDisposal(() => frameBuffer.Unbind()));
        }
Ejemplo n.º 10
0
        private void getImageGL(Action <Image <Rgba32> > callback)
        {
            host.DrawThread.Scheduler.Add(() =>
            {
                var image = new Image <Rgba32>((int)DrawWidth, (int)DrawHeight);

                var sharedData = (BufferedDrawNodeSharedData)typeof(BufferedContainer <Drawable>).GetField("sharedData", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this);

                var fbo = new FrameBuffer();
                fbo.Bind();
                GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget2d.Texture2D, sharedData.MainBuffer.Texture.TextureId, 0);

                bool success = image.TryGetSinglePixelSpan(out var span);
                Debug.Assert(success);
                GL.ReadPixels(0, 0, (int)DrawWidth, (int)DrawHeight, PixelFormat.Rgba, PixelType.UnsignedByte, ref MemoryMarshal.GetReference(span));
                fbo.Dispose();
                GLWrapper.BindFrameBuffer(GLWrapper.DefaultFrameBuffer);

                callback(image);
            });
        }
        protected override void OnOpenGLDraw(object sender, RenderEventArgs args)
        {
            fbo.Bind();

            GL.Clear(0, 1, 1, 1);
            GL.Viewport(0, 0, 500, 500);
            GL.OrthoProj(500, 500);

            //using (SpriteBatch.BeginScope())
            //{
            //SpriteBatch.Rect(0, 0, 200, 200, Color.Red);

            // SpriteBatch.Fan(points.Reverse().ToArray(), color);
            //}

            //byte[] pixels = new byte[4];
            //GL.ReadPixels(1, 1, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, pixels);

            GL.Disable(GL_CULL_FACE);
            GL.Enable(GL_DEPTH_TEST);
            GL.Enable(GL_BLEND);
            GL.BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
            GL.BlendEquation(GL_FUNC_ADD_EXT);

            GL.DrawText(0, 0, 1, 1, 1, "Segoe UI Light", 80, "Hello Doods");

            FrameBuffer.Unbind(GL);
            GL.Clear(0, 0.6f, 1, 1);
            GL.Viewport(0, 0, Control.Width, Control.Height);
            GL.OrthoProj(Control.Width, Control.Height);

            using (SpriteBatch.BeginScope())
            {
                SpriteBatch.Rect(200, 100, 300, 300, fbo.Texture, Color.White);

                SpriteBatch.Rect(10, 10, 50, 50, Color.Green);

                //SpriteBatch.Fan(points.Reverse().ToArray(), color);
            }
        }
Ejemplo n.º 12
0
        protected override void OnRenderFrame(FrameEventArgs args)
        {
            frameBuffer.Bind();

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

            GL.Enable(EnableCap.DepthTest);
            GL.CullFace(CullFaceMode.Back);

            //skybox.Use(camera);

            SceneManager.currentScene?.Render();

            FrameBuffer.Unbind();

            // EditorWindow();

            _controller.GenerateDockspace(EditorWindow);
            _controller.Render();

            GL.Flush();
            SwapBuffers();
            base.OnRenderFrame(args);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Binds and initialises a <see cref="FrameBuffer"/> if required.
        /// </summary>
        /// <param name="frameBuffer">The <see cref="FrameBuffer"/> to bind.</param>
        /// <returns>A token that must be disposed upon finishing use of <paramref name="frameBuffer"/>.</returns>
        protected ValueInvokeOnDisposal BindFrameBuffer(FrameBuffer frameBuffer)
        {
            if (!frameBuffer.IsInitialized)
            {
                frameBuffer.Initialize(true, filteringMode);
            }

            if (formats != null)
            {
                // These additional render buffers are only required if e.g. depth
                // or stencil information needs to also be stored somewhere.
                foreach (var f in formats)
                {
                    frameBuffer.Attach(f);
                }
            }

            // This setter will also take care of allocating a texture of appropriate size within the frame buffer.
            frameBuffer.Size = frameBufferSize;

            frameBuffer.Bind();

            return(new ValueInvokeOnDisposal(frameBuffer.Unbind));
        }
Ejemplo n.º 14
0
 public void BindTarget( )
 {
     FrameBuffer.Bind( );
 }