Exemplo n.º 1
0
        /// <summary>
        /// Clear surface buffers.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used for clearing buffers.
        /// </param>
        /// <param name="bufferMask">
        /// A <see cref="ClearBufferMask"/> indicating which buffers to clear.
        /// </param>
        public void Clear(GraphicsContext ctx, ClearBufferMask bufferMask)
        {
            // Update clear values (only what is necessary)
            if ((bufferMask & ClearBufferMask.ColorBufferBit) != 0)
            {
                Gl.ClearColor(mClearColor.r, mClearColor.g, mClearColor.b, mClearColor.a);
            }
#if !MONODROID
            if ((bufferMask & ClearBufferMask.DepthBufferBit) != 0)
            {
                Gl.ClearDepth(mClearDepth);
            }
#else
            if ((bufferMask & ClearBufferMask.DepthBufferBit) != 0)
            {
                Gl.ClearDepth((float)mClearDepth);
            }
#endif
            if ((bufferMask & ClearBufferMask.StencilBufferBit) != 0)
            {
                Gl.ClearStencil(mClearStencil);
            }

            // Clear
            Gl.Clear(bufferMask);
        }
Exemplo n.º 2
0
        private void RenderFramebufferToScreen()
        {
            Gl.Viewport(0, 0, Constants.windowWidth, Constants.windowHeight);
            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            Gl.ClearDepth(1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            framebufferRenderShader.SetFloat("exposure", Constants.exposure);
            framebufferRenderPlane.Draw(framebufferRenderShader, mainFramebuffer.ColorTexture);
        }
Exemplo n.º 3
0
        public void ClearFrameBuffer(float r, float g, float b, float a)
        {
            FrameBuffer.Bind();

            Gl.ClearColor(r, g, b, a);
            Gl.ClearDepth(1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            FrameBuffer.Unbind();
        }
Exemplo n.º 4
0
        public void RenderFramebuffer()
        {
            var cameraComponent = MainCamera.GetComponent <CameraComponent>();

            Gl.Viewport(0, 0, GameSettings.GameResolutionX, GameSettings.GameResolutionY);
            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            Gl.ClearDepth(1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            framebufferRenderShader.SetFloat("exposure", RenderManager.Instance.exposure);
            framebufferRenderShader.SetInt("tonemapOperator", (int)RenderManager.Instance.tonemapOperator);
            framebufferRenderPlane.Draw(framebufferRenderShader, cameraComponent.Framebuffer.ColorTexture);
        }
Exemplo n.º 5
0
        private static void InitializeOpenGl()
        {
            Gl.ClearColor(0.05f, 0.1f, 0.15f, 1.0f);
            Gl.ClearDepth(1.0f);
            Gl.Enable(EnableCap.DepthTest);
            Gl.DepthFunc(DepthFunction.Lequal);
            Gl.ShadeModel(ShadingModel.Smooth);
            Gl.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            Gl.Enable(EnableCap.Normalize);

            Gl.Enable(EnableCap.CullFace);
            Gl.CullFace(CullFaceMode.Back);
            Gl.FrontFace(FrontFaceDirection.Ccw);
        }
Exemplo n.º 6
0
        private void RenderSceneToFramebuffer()
        {
            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, mainFramebuffer.Fbo);
            Gl.Viewport(0, 0, Constants.renderWidth, Constants.renderHeight);
            Gl.ClearDepth(0.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            Gl.ClipControl(ClipControlOrigin.LowerLeft, ClipControlDepth.ZeroToOne);
            Gl.DepthFunc(DepthFunction.Greater);

            camera.Render();
            DrawSkybox();
            testModel.Draw(camera, shader, light, (skybox, convolutedSkybox, prefilteredSkybox), brdfLut);

            Gl.DepthFunc(DepthFunction.Less);
            Gl.ClipControl(ClipControlOrigin.LowerLeft, ClipControlDepth.NegativeOneToOne);
        }
Exemplo n.º 7
0
        private void RenderControl_ContextCreated(object sender, GlControlEventArgs e)
        {
            GlControl glControl = (GlControl)sender;

            // Here you can allocate resources or initialize state
            Gl.MatrixMode(MatrixMode.Projection);
            Gl.LoadIdentity();
            Gl.Ortho(OrthoLeft, OrthoRight, OrthoBottom, OrthoTop, -0.1, 10.0);
            Gl.Enable(EnableCap.Texture2d);
            Gl.Enable(EnableCap.Blend);
            Gl.Enable(EnableCap.DepthTest);                     //Set up Z Depth tests for drawing pixels
            Gl.DepthFunc(DepthFunction.Lequal);                 //Only draw something new if its z value is closer to the 'camera'
            Gl.DepthMask(true);
            Gl.ClearDepth(10f);
            Gl.ClearColor(36 / 255f, 71 / 255f, 143 / 255f, 1f);
            Gl.Enable(EnableCap.AlphaTest);                     //Set up Alpha tests for drawing pixels
            Gl.AlphaFunc(AlphaFunction.Greater, .05f);          //Don't draw transparent pixels on polygons
            Gl.Enable(EnableCap.ScissorTest);
            Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            Gl.EnableClientState(EnableCap.VertexArray);
            Gl.EnableClientState(EnableCap.TextureCoordArray);
            contextCreated = true;
            Console.Console.ConsoleSetup();
            WorldData.WorldStartup();
            Screen.ScreenStartup();

            MaximizeBox = false;

            if (Save.SaveData.GameSettings.fullScreen)
            {
                FormBorderStyle = FormBorderStyle.None;
                WindowState     = FormWindowState.Maximized;
            }
            if (Save.SaveData.GameSettings.VSync)
            {
                Wgl.SwapIntervalEXT(-1);                 //Swap Interval (V-Sync Enabled at 1 or -1)
            }
            else
            {
                Wgl.SwapIntervalEXT(0);
            }
            ResizeWindow(Save.SaveData.GameSettings.windowx, Save.SaveData.GameSettings.windowy);
            ResizeE(sender, e);

            LogicUtils.Logic.LogicStart();
        }
Exemplo n.º 8
0
        private void RenderSceneToFramebuffer()
        {
            var cameraComponent = MainCamera.GetComponent <CameraComponent>();

            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, cameraComponent.Framebuffer.Fbo);
            Gl.Viewport(0, 0, (int)cameraComponent.Resolution.X, (int)cameraComponent.Resolution.Y);
            Gl.ClearDepth(0.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            Gl.ClipControl(ClipControlOrigin.LowerLeft, ClipControlDepth.ZeroToOne);
            Gl.DepthFunc(DepthFunction.Greater);

            MainCamera.Render();
            var skyboxComponent = skyboxEntity.GetComponent <SkyboxComponent>();

            skyboxComponent.DrawSkybox(MainCamera);

            var templateDrawInfo = new Mesh.DrawInfo()
            {
                Camera      = MainCamera,
                Light       = Lights[0],
                PbrCubemaps = (skyboxComponent.skybox, skyboxComponent.convolutedSkybox, skyboxComponent.prefilteredSkybox),
                BrdfLut     = brdfLut,
                HoloTexture = holoTexture,
                ProjMatrix  = MainCamera.GetComponent <CameraComponent>().ProjMatrix,
                ViewMatrix  = MainCamera.GetComponent <CameraComponent>().ViewMatrix
            };

            foreach (var entity in Entities)
            {
                if (!entity.HasComponent <ModelComponent>())
                {
                    continue;
                }

                var modelComponent = entity.GetComponent <ModelComponent>();
                var newDrawInfo    = new Mesh.DrawInfo(templateDrawInfo);
                newDrawInfo.Shader      = entity.GetComponent <ShaderComponent>();
                newDrawInfo.ModelMatrix = entity.GetComponent <TransformComponent>().Matrix;

                modelComponent.Draw(newDrawInfo);
            }

            Gl.DepthFunc(DepthFunction.Less);
            Gl.ClipControl(ClipControlOrigin.LowerLeft, ClipControlDepth.NegativeOneToOne);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Clear surface buffers.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used for clearing buffers.
        /// </param>
        /// <param name="bufferMask">
        /// A <see cref="ClearBufferMask"/> indicating which buffers to clear.
        /// </param>
        public void Clear(GraphicsContext ctx, ClearBufferMask bufferMask)
        {
            // Update clear values (only what is necessary)
            if ((bufferMask & ClearBufferMask.ColorBufferBit) != 0)
            {
                Gl.ClearColor(mClearColor.Red, mClearColor.Green, mClearColor.Blue, mClearColor.Alpha);
            }
            if ((bufferMask & ClearBufferMask.DepthBufferBit) != 0)
            {
                Gl.ClearDepth(mClearDepth);
            }
            if ((bufferMask & ClearBufferMask.StencilBufferBit) != 0)
            {
                Gl.ClearStencil(mClearStencil);
            }

            // Clear
            Gl.Clear(bufferMask);
        }
Exemplo n.º 10
0
 public void Clear(float r, float g, float b, float a)
 {
     Gl.ClearColor(r, g, b, a);
     Gl.ClearDepth(1.0f);
     Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
 }