Exemplo n.º 1
0
        //*/

        /// <summary>
        /// Test create render to texture
        /// </summary>
        public static void TestCreateRenderToTexture()
        {
            ColladaModel testModel = null;
            RenderToTexture renderToTexture = null;

            TestGame.Start(
                "TestCreateRenderToTexture",
                delegate
                {
                    testModel = new ColladaModel("Sword");
                    renderToTexture = new RenderToTexture(
                        //SizeType.QuarterScreen);
                        SizeType.HalfScreen);
                        //SizeType.FullScreen);
                        //SizeType.ShadowMap);
                },
                delegate
                {
                    bool renderToTextureWay =
                        Input.Keyboard.IsKeyUp(Keys.Space) &&
                        Input.GamePadAPressed == false;
                    BaseGame.Device.RenderState.DepthBufferEnable = true;

                    if (renderToTextureWay)
                    {
                        // Set render target to our texture
                        renderToTexture.SetRenderTarget();

                        // Clear background
                        renderToTexture.Clear(Color.Blue);

                        /*obs
                        // Draw background lines
                        BaseGame.DrawLine(new Point(0, 200), new Point(200, 0), Color.Blue);
                        BaseGame.DrawLine(new Point(0, 0), new Point(400, 400), Color.Red);
                        BaseGame.FlushLineManager2D();
                         */

                        // And draw object
                        testModel.Render(Matrix.CreateScale(1.5f));
                        //obs: BaseGame.MeshRenderManager.Render();

                        // Do we need to resolve?
                        renderToTexture.Resolve();
                        //BaseGame.Device.ResolveRenderTarget(0);

                        // Reset background buffer
                        BaseGame.ResetRenderTarget(true);
                    } // if (renderToTextureWay)
                    else
                    {
                        // Copy backbuffer way, render stuff normally first
                        // Clear background
                        BaseGame.Device.Clear(Color.Blue);

                        /*obs
                        // Draw background lines
                        BaseGame.DrawLine(new Point(0, 200), new Point(200, 0), Color.Blue);
                        BaseGame.DrawLine(new Point(0, 0), new Point(400, 400), Color.Red);
                        BaseGame.FlushLineManager2D();
                         */

                        // And draw object
                        testModel.Render(Matrix.CreateScale(1.5f));
                        //obs: BaseGame.MeshRenderManager.Render();
                    } // else

                    // Show render target in a rectangle on our screen
                    renderToTexture.RenderOnScreen(
                        //tst:
                        new Rectangle(100, 100, 256, 256));
                        //BaseGame.ResolutionRect);
                    //no need: BaseGame.UI.FlushUI();

                    TextureFont.WriteText(2, 0,
                        "               Press Space to toogle full screen rendering");
                    TextureFont.WriteText(2, 30,
                        "renderToTexture.Width=" + renderToTexture.Width);
                    TextureFont.WriteText(2, 60,
                        "renderToTexture.Height=" + renderToTexture.Height);
                    TextureFont.WriteText(2, 90,
                        "renderToTexture.Valid=" + renderToTexture.Valid);
                    TextureFont.WriteText(2, 120,
                        "renderToTexture.XnaTexture=" + renderToTexture.XnaTexture);
                    TextureFont.WriteText(2, 150,
                        "renderToTexture.ZBufferSurface=" + renderToTexture.ZBufferSurface);
                    TextureFont.WriteText(2, 180,
                        "renderToTexture.Filename=" + renderToTexture.Filename);
                });
        }
Exemplo n.º 2
0
        /// <summary>
        /// TestCaveColladaModelScene
        /// </summary>
        public static void TestCaveColladaModelScene()
        {
            ColladaModel caveModel = null;
            //ColladaModel playerModel = null;
            //PlaneRenderer groundPlane = null;

            TestGame.Start("TestCaveColladaModelScene",
                delegate
                {
                    // Load Cave
                    caveModel = new ColladaModel("Cave");
                    caveModel.material.ambientColor = Material.DefaultAmbientColor;

                    //TODO: playerModel = new ColladaModel("Hero");

                    // Play background music :)
                    //Sound.StartMusic();

                    /*not needed here
                    // Create ground plane
                    groundPlane = new PlaneRenderer(
                        new Vector3(0, 0, -0.001f),
                        new Plane(new Vector3(0, 0, 1), 0),
                        new Material(
                            "CaveDetailGround",
                            "CaveDetailGroundNormal"),
                        28);
                     */

                    // Set light direction (light is coming from the front right pos).
                    BaseGame.LightDirection = new Vector3(-18, -20, 16);
                },
                delegate
                {
                    if (Input.Keyboard.IsKeyDown(Keys.LeftAlt))
                    {
                        // Start glow shader
                        BaseGame.GlowShader.Start();

                        // Clear background with white color, looks much cooler for the
                        // post screen glow effect.
                        BaseGame.Device.Clear(Color.Black);
                    } // if (Input.Keyboard.IsKeyDown)

                    //BaseGame.Device.Clear(new Color(86, 86, 60));

                    // Render goblin always in center, but he is really big, bring him
                    // down to a more normal size that fits better in our test scene.
                    Matrix renderMatrix = Matrix.Identity;// Matrix.CreateScale(0.1f);

                    // Restore z buffer state
                    BaseGame.Device.RenderState.DepthBufferEnable = true;
                    BaseGame.Device.RenderState.DepthBufferWriteEnable = true;

                    /*TODO
                    // Make sure we use skinned tangent vertex format for shadow mapping
                    BaseGame.Device.VertexDeclaration =
                        TangentVertex.VertexDeclaration;

                    // Generate shadows
                    ShaderEffect.shadowMapping.GenerateShadows(
                        delegate
                        {
                            for (int x = 0; x < 2; x++)
                                for (int y = 0; y < 3; y++)
                                    goblinModel.GenerateShadow(renderMatrix *
                                        Matrix.CreateTranslation(-5 + 10 * x, -10 + 10 * y, 0));
                        });

                    // Render shadows
                    ShaderEffect.shadowMapping.RenderShadows(
                        delegate
                        {
                            for (int x = 0; x < 2; x++)
                                for (int y = 0; y < 3; y++)
                                    goblinModel.UseShadow(renderMatrix *
                                        Matrix.CreateTranslation(-5 + 10 * x, -10 + 10 * y, 0));
                            groundPlane.UseShadow();
                        });
                     */

                    // Show ground with DiffuseSpecular material and use parallax mapping!
                    //not needed: groundPlane.Render(ShaderEffect.normalMapping, "Specular30");
                    /*obs
                    // And show all goblins
                    for (int x = 0; x < 2; x++)
                        for (int y = 0; y < 3; y++)
                            goblinModel.Render(
                                renderMatrix *
                                Matrix.CreateTranslation(-5 + 10 * x, -10 + 10 * y, 0));
                     */
                    caveModel.Render(
                        Matrix.CreateTranslation(0, 0, +1));

                    LightManager.RenderAllCloseLightEffects();

                    // We have to render the effects ourselfs because
                    // it is usually done in DungeonQuestGame!
                    // Finally render all effects (before applying post screen effects)
                    BaseGame.effectManager.HandleAllEffects();

                    /*TODO
                    if (Input.Keyboard.IsKeyDown(Keys.LeftControl))
                        playerModel.Render(
                            Matrix.CreateTranslation(BaseGame.camera.PlayerPos));
                     */

                    // And show shadows on top of the scene (with shadow blur effect).
                    //TODO: ShaderEffect.shadowMapping.ShowShadows();

                    if (Input.Keyboard.IsKeyDown(Keys.LeftAlt))
                    {
                        // And finally show glow shader on top of everything
                        BaseGame.GlowShader.Show();
                    } // if (Input.Keyboard.IsKeyDown)

                    /*TODO
                    // If you press the right mouse button or B you can see all
                    // shadow map and post screen render targets (for testing/debugging)
                    if (Input.MouseRightButtonPressed ||
                        Input.GamePadBPressed)
                    {
                        BaseGame.AlphaBlending = false;
                        BaseGame.Device.RenderState.AlphaTestEnable = false;
                        // Line 1 (3 render targets, 2 shadow mapping, 1 post screen)
                        ShaderEffect.shadowMapping.shadowMapTexture.RenderOnScreen(
                            new Rectangle(10, 10, 256, 256));
                        ShaderEffect.shadowMapping.shadowMapBlur.SceneMapTexture.
                            RenderOnScreen(
                            new Rectangle(10 + 256 + 10, 10, 256, 256));
                        PostScreenMenu.sceneMapTexture.RenderOnScreenNoAlpha(
                            new Rectangle(10 + 256 + 10 + 256 + 10, 10, 256, 256));
                        // Line 2 (3 render targets, 2 post screen blurs, 1 final scene)
                        PostScreenMenu.downsampleMapTexture.RenderOnScreenNoAlpha(
                            new Rectangle(10, 10 + 256 + 10, 256, 256));
                        PostScreenMenu.blurMap1Texture.RenderOnScreenNoAlpha(
                            new Rectangle(10 + 256 + 10, 10 + 256 + 10, 256, 256));
                        PostScreenMenu.blurMap2Texture.RenderOnScreenNoAlpha(
                            new Rectangle(10 + 256 + 10 + 256 + 10, 10 + 256 + 10, 256, 256));
                    } // if (Input.MouseRightButtonPressed)
                     */
                });
        }
Exemplo n.º 3
0
        /// <summary>
        /// TestCaveColladaModelScene
        /// </summary>
        public static void TestCaveColladaModelSceneSplitScreen()
        {
            ColladaModel caveModel = null;
            Viewport originalViewport = new Viewport(),
                viewport1 = new Viewport(),
                viewport2 = new Viewport();

            TestGame.Start("TestCaveColladaModelScene",
                delegate
                {
                    // Load Cave
                    caveModel = new ColladaModel("Cave");
                    caveModel.material.ambientColor = Material.DefaultAmbientColor;

                    // Set light direction (light is coming from the front right pos).
                    BaseGame.LightDirection = new Vector3(-18, -20, 16);

                    // Create both viewports
                    originalViewport = BaseGame.Device.Viewport;

                    viewport1 = new Viewport();
                    viewport1.Width = BaseGame.Width / 2;
                    viewport1.Height = BaseGame.Height;
                    viewport1.X = 0;
                    viewport1.Y = 0;

                    viewport2 = new Viewport();
                    viewport2.Width = BaseGame.Width / 2;
                    viewport2.Height = BaseGame.Height;
                    viewport2.X = BaseGame.Width / 2;
                    viewport2.Y = 0;

                    // Fix projection matrix for 2 views
                    BaseGame.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                        BaseGame.FieldOfView, BaseGame.aspectRatio / 2.0f,
                        BaseGame.NearPlane, BaseGame.FarPlane);
                },
                delegate
                {
                    // Render goblin always in center, but he is really big, bring him
                    // down to a more normal size that fits better in our test scene.
                    Matrix renderMatrix = Matrix.Identity;// Matrix.CreateScale(0.1f);

                    // Restore z buffer state
                    BaseGame.Device.RenderState.DepthBufferEnable = true;
                    BaseGame.Device.RenderState.DepthBufferWriteEnable = true;

                    // Render viewport 1
                    BaseGame.Device.Viewport = viewport1;
                    BaseGame.Device.Clear(BaseGame.BackgroundColor);
                    caveModel.Render(
                        Matrix.CreateTranslation(0, 0, +1));
                    LightManager.RenderAllCloseLightEffects();
                    BaseGame.effectManager.HandleAllEffects();

                    // Render viewport 2
                    BaseGame.Device.Viewport = viewport2;
                    BaseGame.ViewMatrix = BaseGame.ViewMatrix *
                        Matrix.CreateRotationY(1.4f);
                    BaseGame.Device.Clear(BaseGame.BackgroundColor);

                    caveModel.Render(
                        Matrix.CreateTranslation(0, 0, +1));
                    LightManager.RenderAllCloseLightEffects();
                    BaseGame.effectManager.HandleAllEffects();

                    // Restore
                    BaseGame.Device.Viewport = originalViewport;

                    // Draw seperation line
                    //BaseGame.Device.RenderState.DepthBufferEnable = true;
                    //BaseGame.Device.RenderState.DepthBufferWriteEnable = true;
                    //TODO
                    UIManager.DrawUI();
                });
        }
Exemplo n.º 4
0
        /// <summary>
        /// Test load static model
        /// </summary>
        public static void TestLoadStaticModel()
        {
            ColladaModel someModel = null;

            TestGame.Start("TestLoadStaticModel",
                delegate
                {
                    // Load the cave for all the lights (else everything will be dark)
                    someModel = new ColladaModel("Cave");
                    someModel = new ColladaModel(
                        //"Cave");
                        //"Flare");
                        //"Club");
                        "Sword");
                        //"Door");
                },
                delegate
                {
                    someModel.Render(
                        //Matrix.CreateTranslation(
                        //BaseGame.camera.PlayerPos+new Vector3(0, 0, 1)));
                        //Matrix.CreateScale(100));
                        Matrix.Identity);
                        //Matrix.CreateTranslation(new Vector3(2, 0, 0)));
                });
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create game manager
        /// </summary>
        public GameManager()
        {
            // Load the cave and fill in all static game items (will be done
            // there in the loading process).
            caveModel = new ColladaModel("Cave");
            caveModel.material.ambientColor = Material.DefaultAmbientColor;

            // Load all animated models (player and monsters)
            for (int i = 0; i <= (int)AnimatedTypes.BigOgre; i++)
                animatedModels.Add(new AnimatedColladaModel(
                    //tst: "GoblinWizard"));
                    ((AnimatedTypes)i).ToString()));

            // Also load all static models
            for (int i = 0; i <= (int)StaticTypes.BigSword; i++)
                staticModels.Add(new ColladaModel(
                    ((StaticTypes)i).ToString()));

            screenBorder = new Texture("ScreenBorder");
        }