Beispiel #1
0
 public SpriteRenderer(MasterRenderer master)
     : base(master)
 {
     SpriteBatch = new SpriteBatch(master.ScreenWidth, master.ScreenHeight);
     GUISystem   = new GUISystem(SpriteBatch);
     shader      = new SpriteShader();
 }
        public ForwardPipeline(MasterRenderer renderer)
            : base(renderer)
        {
            GLError.Begin();

            forwardShader        = new WorldShader();
            shadowShader         = new ShadowShader();
            shadowMap            = new ShadowMap(GFXSettings.ShadowResolution, GFXSettings.ShadowResolution);
            shadowCamera         = new ShadowCamera();
            ppBuffer             = new PostProcessBuffer(ScreenWidth, ScreenHeight);
            ppShader             = new PostProcessShader();
            skyRenderTarg        = new TexRenderTarget(ScreenWidth, ScreenHeight);
            screenshotRenderTarg = new TexRenderTarget(1, 1);

            screenshotRenderTarg.Bind();
            GL.ReadBuffer(ReadBufferMode.ColorAttachment0);
            screenshotRenderTarg.Unbind();

            ErrorCode err = GLError.End();

            if (err != ErrorCode.NoError)
            {
                throw new Exception(string.Format("Failed to initialize forward pipeline. OpenGL Error: {0}", err));
            }
        }
        /*  For graph of f(x)=sin(x) and f(x)=cos(x)
         *  where time = [0, 24]
         *
         *  22-2: No sun
         *  2-7, 16-22: sun-rise, sun-set
         *  7-17: day
         *  -- -- --
         *  where time = [0, 2pi] (y-axis)
         *
         *  sun-rise: [0, pi/4]
         *  day: [pi/4, 1.32]
         *  sun-set: [1.32, pi]
         *  night: [pi, 2pi]
         */

        public SkyboxRenderer(MasterRenderer master)
            : base(master)
        {
            cube   = new SimpleMesh(BufferUsageHint.StaticDraw, 3, VERTICES);
            skyMap = GLoader.LoadTexture("Textures/skyMap.png", TextureMinFilter.Nearest, TextureMagFilter.Nearest);
            shader = new SkyboxShader();
        }
        public Camera(MasterRenderer renderer)
        {
            AspectRatio   = (float)renderer.ScreenWidth / renderer.ScreenHeight;
            this.renderer = renderer;

            Speeds[0] = 2f;
            Speeds[1] = 5f;

            MouseRay      = new Ray(Vector3.Zero, Vector3.UnitZ);
            Position      = new Vector3(0, 400, 0);
            ViewFrustum   = new Frustum();
            AudioListener = new AudioListener(Position);
            UpdateMatrices();
        }
        public GuiRenderer(MasterRenderer master)
            : base(master)
        {
            float[] positions = new float[]
            {
                -1, 1,  // top left
                -1, -1, // bottom left
                1, 1,   // top right
                1, -1   // bottom right
            };

            Quad             = new SimpleMesh(BufferUsageHint.StaticDraw, 2, positions);
            shader           = new GuiShader();
            depthDebugShader = new DepthDebugShader();
        }
Beispiel #6
0
 public Renderer(MasterRenderer master)
 {
     Master = master;
 }
        public void Run(float targetFPS)
        {
            TargetFrameRate = targetFPS;

            if (!Glfw.Init())
            {
                throw new Exception("Failed to initialize glfw!");
            }

            try
            {
                // Setup the error callback
                Glfw.SetErrorCallback(OnError);

                // Configure the window settings
                Glfw.WindowHint(WindowHint.Resizeable, startResizable ? 1 : 0);
                Glfw.WindowHint(WindowHint.Samples, 0);

                // Create the window
                handle = Glfw.CreateWindow(startWidth, startHeight, title,
                                           GlfwMonitorPtr.Null, GlfwWindowPtr.Null);
                HasFocus = true;

                // TODO: check if window was initialized correctly

                // Set the gl context
                Glfw.MakeContextCurrent(handle);

                // Get the primary monitor
                primaryMonitor          = Glfw.GetMonitors()[0];
                primaryMonitorVideoMode = Glfw.GetVideoMode(primaryMonitor);

                Glfw.GetWindowSize(handle, out width, out height);
                Center();

                // Setup window events
                Glfw.SetScrollCallback(handle, OnInputScroll);
                Glfw.SetCursorPosCallback(handle, OnMouseMove);
                Glfw.SetWindowSizeCallback(handle, OnSizeChanged);
                Glfw.SetWindowFocusCallback(handle, OnWindowFocusChanged);
                Glfw.SetKeyCallback(handle, OnInputKeyChanged);
                Input.Initialize(this);

                // Set defaults and load
                SetVSync(false);

                Renderer = new MasterRenderer(width, height, startOptions);
                InitOpenAL();

                GLError.Begin();
                Load();
                ErrorCode initError = GLError.End();
                if (initError != ErrorCode.NoError)
                {
                    throw new Exception(string.Format("Uncaught opengl initialization error! {0}", initError));
                }

                // Begin game loop
                double lastTime = Glfw.GetTime();

                while (!Glfw.WindowShouldClose(handle))
                {
                    double now = Glfw.GetTime();
                    float  dt  = (float)(now - lastTime);
                    lastTime = now;

                    // Process current deltatime
                    HandleFPS(dt);

                    // Check for input events before we call Input.Begin
                    Glfw.PollEvents();

                    // Check for window size change.
                    // We only call the OnResized event here so that
                    // when a user is custom resizing it doesn't get invoked
                    // a thousand times.
                    if (lastDrawnWidth != width || lastDrawnHeight != height)
                    {
                        lastDrawnWidth  = width;
                        lastDrawnHeight = height;
                        OnSafeResized();
                    }

                    // Update
                    Input.Begin();
                    Renderer.Update(dt);
                    Update(dt);
                    Input.End();

                    // Draw
                    Renderer.Prepare(dt);
                    Draw(dt);
                    Renderer.Render(dt);

                    // Check for any uncaught opengl exceptions
                    ErrorCode glError = GL.GetError();
                    if (glError != ErrorCode.NoError)
                    {
                        throw new Exception(string.Format("Uncaught OpenGL Error: {0}", glError));
                    }

                    // Draw the buffers
                    Glfw.SwapBuffers(handle);

                    if (!vsyncEnabled)
                    {
                        // Sleep to avoid cpu cycle burning
                        double startSleepNow = Glfw.GetTime();
                        double timeToWait    = targetDeltaTime - (startSleepNow - now);

                        while (timeToWait > 0)
                        {
                            Thread.Sleep(0);
                            double sleepNow = Glfw.GetTime();
                            timeToWait   -= (sleepNow - startSleepNow);
                            startSleepNow = sleepNow;
                        }
                    }
                }

                Unload();
            }
            finally
            {
                Glfw.DestroyWindow(handle);
            }
        }
 public RenderPipeline(MasterRenderer renderer)
 {
     Renderer = renderer;
 }
 public Camera2D(MasterRenderer renderer)
 {
     this.renderer   = renderer;
     this.ZoomLevels = new List <float>();
 }