在纹理四边形中播放视频

时间:2012-11-21 18:26:17

标签: c#-4.0 3d xna-4.0

实际上我想播放四边形纹理的视频,但如果我用矩形绘制,显示的视频的颜色会有某种折旧。 以下是从mdsn加上abit修改的例子,有人可以帮我查一下吗?

提前致谢。


public Game1()
        {
            graphics = new GraphicsDeviceManager(this);

            graphics.PreferredBackBufferWidth = 1920;
            graphics.PreferredBackBufferHeight = 1080;
            graphics.PreferMultiSampling = false;
            graphics.IsFullScreen = false;

            // Set the back buffer format to color
            graphics.PreferredBackBufferFormat = SurfaceFormat.Color;

            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            PresentationParameters pp = GraphicsDevice.PresentationParameters;
            pp.MultiSampleCount = 20;

            quad = new Quad(Vector3.Zero, Vector3.Backward, Vector3.Up, 1,1);
            camera = new Camera(this, new Vector3(0, 0, 1.15f), Vector3.Zero, Vector3.Up);
            Components.Add(camera);

            base.Initialize();
        }

        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here

            video = Content.Load<Video>("1");
            player = new VideoPlayer();
            player.IsLooped = true;

            // Setup our BasicEffect for drawing the quad
            World = Matrix.Identity;

            quadEffect = new BasicEffect(graphics.GraphicsDevice);

            quadEffect.EnableDefaultLighting();

            quadEffect.View = camera.view;
            quadEffect.Projection = camera.projection;
            quadEffect.TextureEnabled = true;

            // Create a vertex declaration so we can call
            // DrawUserIndexedPrimitives later
            quadVertexDecl = new VertexDeclaration(VertexPositionTexture.VertexDeclaration.GetVertexElements());   

        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here

            // Play the video if it isn't already.
            if (player.State != MediaState.Playing)
                player.Play(video);

            KeyboardState state = Keyboard.GetState();
            .....

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            // TODO: Add your drawing code here
            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            GraphicsDevice.RasterizerState = rs;


            quadEffect.World = World;

            if (player.State == MediaState.Playing)
                quadEffect.Texture = player.GetTexture();

            foreach (EffectPass pass in quadEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;

                GraphicsDevice.DrawUserIndexedPrimitives(
                        PrimitiveType.TriangleList,
                        quad.Vertices, 0, 4,
                        quad.Indices, 0, 2);
            }
            base.Draw(gameTime);
        }

1 个答案:

答案 0 :(得分:1)

你正在使用quadEffect.EnableDefaultLighting();这将增加一个光源。您可以通过设置quadEffect.LightingEnabled = false;

来禁用它