Exemplo n.º 1
0
        void Window_RenderFrame(object sender, FrameEventArgs e)
        {
            //color picking
            GL.ClearColor(1f, 1f, 1f, 1f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            foreach (var c in parts)
            {
                c.drawToPickBuffer(pickShader, camera.Transfrom);
            }

            byte[] pixel = new byte[4];
            GL.ReadPixels(Window.Mouse.X, Window.Height - Window.Mouse.Y, 1, 1, PixelFormat.Rgba, PixelType.UnsignedByte, pixel);
            var m = gf.getModel(new Vector3(pixel[0], pixel[1], pixel[2]));

            if (m != null)
            {
                m.picked = true;
            }

            if (!drawToPickBuffer)
            {
                GL.ClearColor(.5f, .5f, .2f, 1f);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                foreach (var c in parts)
                {
                    c.draw(camera.Transfrom);
                }

                skybox.draw(camera);
            }

            Window.SwapBuffers();
        }
Exemplo n.º 2
0
        public void Draw(GameWindow gw, FrameEventArgs e)
        {
            //----------------------------setting up shaders-------------
            #region ShaderUniforms
            defaultShader.Bind();
            //defaultShader.SetUniform("bloom", false);
            defaultShader.SetUniform("proj", cam.Projection);
            defaultShader.SetUniform("view", cam.Transfrom);
            defaultShader.SetUniform("lightPos", cam.LightPos);

            earthShader.Bind();
            earthShader.SetUniform("view", cam.Transfrom);
            earthShader.SetUniform("proj", cam.Projection);
            earthShader.SetUniform("eyePos", cam.Position);
            earthShader.SetUniform("lightPos", cam.LightPos);

            sunShader.Bind();
            sunShader.SetUniform("view", cam.Transfrom);
            sunShader.SetUniform("proj", cam.Projection);

            lineShader.Bind();
            lineShader.SetUniform("view", cam.Transfrom);
            lineShader.SetUniform("proj", cam.Projection);
            #endregion

            //textured items
            buffer.Bind();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            skybox.draw(cam);

            foreach (Planet p in planets)
            {
                p.Draw(cam, defaultShader, lineShader);
            }

            sun.Draw(cam, sunShader);
            earth.Draw(cam, earthShader, lineShader);

            //transparent items
            //foreach (PlanetRing r in rings)
            //    r.draw(cam.Transfrom, defaultShader);

            int blurrPasses    = bloom ? 5 : 0;
            var blurredTexture = blur.Blur(buffer.Textures[1], blurrPasses);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.Viewport(0, 0, gw.Width, gw.Height);

            //frame.Draw(Area.TopLeft, buffer.Textures[0]);
            //frame.Draw(Area.TopRight, buffer.Textures[1]);

            if (showBloomBuffer)
            {
                frame.Draw(Area.BottomRight, blurredTexture);
            }

            finalShader.Bind();
            finalShader.SetUniform("useBloom", bloom);
            frame.Draw(Area.Full, buffer.Textures[0], blurredTexture, finalShader);

            guiManager.Draw(gw);
        }