Esempio n. 1
0
        /// <summary>
        /// Render a scene in the entire window from an arbirtrary vantage point.
        /// </summary>
        /// <param name="gameTime">Game time</param>
        /// <param name="scene">The scene manager</param>
        /// <param name="coords">The position to view the scene from</param>
        public void render(GameTime gameTime, Scene scene, Coords coords)
        {
            game.GraphicsDevice.Viewport = viewports[(int)Viewports.WholeWindow];
            game.GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.Black, 1.0f, 0);
            game.GraphicsDevice.RenderState.DepthBufferEnable = true;
            aspectRatio = game.GraphicsDevice.Viewport.AspectRatio;

            renderBloom = false;

            List<GameObject> gameObjects = scene.visible(coords, null);
            renderObjects(gameObjects, coords.camera(), null);

            // TODO: Render post-process shaders
            if (enableShaders)
            {
                renderBloom = true;
                bloomShader.Reset();

                renderObjects(gameObjects, coords.camera(), null);

                bloomShader.Render();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Render a frame of video containing the given Scene and Interface.
        /// The Scene manager includes the world, and all contained models.
        /// The interface is drawn last to show a Menu or HUD.
        /// </summary>
        /// <param name="gameTime">Game time</param>
        /// <param name="scene">The scene manager</param>
        /// <param name="drawHUD">Whether or not the HUD should be drawn.</param>
        public void render(GameTime gameTime, Scene scene, bool drawHUD)
        {
            renderBloom = false;

            // Render all players' viewports
            for (int playerIndex = 0; playerIndex < Player.players.Length; playerIndex++)
            {
                if (Player.players[playerIndex] != null)
                {
                    game.GraphicsDevice.Viewport = viewports[(int)Player.players[playerIndex].viewport];
                    game.GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.Black, 1.0f, 0);
                    game.GraphicsDevice.RenderState.DepthBufferEnable = true;
                    aspectRatio = game.GraphicsDevice.Viewport.AspectRatio;

                    List<GameObject> gameObjects = scene.visible(Player.players[playerIndex]);
                    renderObjects(gameObjects, Player.players[playerIndex]);
                }
                else
                {
                    if (MissingPlayerViewports[playerIndex] != Viewports.None)
                    {
                        game.GraphicsDevice.Viewport = viewports[(int)MissingPlayerViewports[playerIndex]];
                        game.GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.Black, 1.0f, 0);
                        Interface i = new Interface(game);
                        Text t = new Text(game);
                        t.SpriteFontName = "Resources/Fonts/Menu";
                        t.text = missingPlayerQuips[(gameTime.TotalRealTime.Seconds / secondsPerQuip) % missingPlayerQuips.Length];
                        t.center = true;
                        t.RelativePosition = new Vector2(game.GraphicsDevice.Viewport.Width / 2, game.GraphicsDevice.Viewport.Height / 2);
                        t.color = Color.WhiteSmoke;
                        i.AddComponent(t);
                        i.Draw(gameTime, Vector2.Zero, Vector2.One, 0);
                        // TODO: Draw something noteworthy in the empty slots?
                    }
                }
            }

            game.GraphicsDevice.Viewport = viewports[(int)Viewports.WholeWindow];

            // TODO: Render post-process shaders
            if (enableShaders)
            {
                renderBloom = true;
                bloomShader.Reset();

                // Render all players' viewports
                for (int playerIndex = 0; playerIndex < Player.players.Length; playerIndex++)
                {
                    if (Player.players[playerIndex] != null)
                    {
                        game.GraphicsDevice.Viewport = viewports[(int)Player.players[playerIndex].viewport];
                        game.GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.Black, 1.0f, 0);
                        game.GraphicsDevice.RenderState.DepthBufferEnable = true;
                        aspectRatio = game.GraphicsDevice.Viewport.AspectRatio;

                        List<GameObject> gameObjects = scene.visible(Player.players[playerIndex]);
                        renderObjects(gameObjects, Player.players[playerIndex]);
                    }
                    else
                    {
                        if (MissingPlayerViewports[playerIndex] != Viewports.None)
                        {
                            game.GraphicsDevice.Viewport = viewports[(int)MissingPlayerViewports[playerIndex]];
                            game.GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.Black, 1.0f, 0);
                            Interface i = new Interface(game);
                            Text t = new Text(game);
                            t.SpriteFontName = "Resources/Fonts/Menu";
                            t.text = missingPlayerQuips[(gameTime.TotalRealTime.Seconds / secondsPerQuip) % missingPlayerQuips.Length];
                            t.center = true;
                            t.RelativePosition = new Vector2(game.GraphicsDevice.Viewport.Width / 2, game.GraphicsDevice.Viewport.Height / 2);
                            t.color = Color.WhiteSmoke;
                            i.AddComponent(t);
                            i.Draw(gameTime, Vector2.Zero, Vector2.One, 0);
                            // TODO: Draw something noteworthy in the empty slots?
                        }
                    }
                }

                bloomShader.Render();
            }

            // Render players' HUDs
            if (drawHUD)
            {
                for (int playerIndex = 0; playerIndex < Player.players.Length; playerIndex++)
                {
                    if (Player.players[playerIndex] != null)
                    {
                        game.GraphicsDevice.Viewport = viewports[(int)Player.players[playerIndex].viewport];

                        Vector2 scale = new Vector2(game.GraphicsDevice.Viewport.Width / 1024.0f, game.GraphicsDevice.Viewport.Height / 768.0f);
                        Player.players[playerIndex].playerHUD.Draw(gameTime, Vector2.Zero, scale, 0);
                    }
                }
            }

            // Reset viewports
            game.GraphicsDevice.Viewport = viewports[(int)Viewports.WholeWindow];
        }