Пример #1
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// reset, which will happen after a lost device scenario. This is the best location to
        /// create Pool.Default resources since these resources need to be reloaded whenever
        /// the device is lost. Resources created here should be released in the OnLostDevice
        /// event.
        /// </summary>
        public void OnResetDevice(object sender, DeviceEventArgs e)
        {
            // Now Create the VB
            vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 100,
                                            e.Device, Usage.WriteOnly, CustomVertex.PositionNormalTextured.Format, Pool.Default);
            OnCreateVertexBuffer();

            // Set up our view matrix. A view matrix can be defined given an eye point,
            // a point to lookat, and a direction for which way is up. Here, we set the
            // eye five units back along the z-axis and up three units, look at the
            // origin, and define "up" to be in the y-direction.
            e.Device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 3.0f, -5.0f),
                                                      new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));

            // For the projection matrix, we set up a perspective transform (which
            // transforms geometry from 3D view space to 2D viewport space, with
            // a perspective divide making objects smaller in the distance). To build
            // a perpsective transform, we need the field of view (1/4 pi is common),
            // the aspect ratio, and the near and far clipping planes (which define at
            // what distances geometry should be no longer be rendered).
            e.Device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, 1.0f, 1.0f, 100.0f);

            // Setup the ambient color
            e.Device.RenderState.AmbientColor = unchecked ((int)0xffffffff);
            // Turn off culling, so we see the front and back of the triangle
            e.Device.RenderState.CullMode = Cull.None;
            // Turn off D3D lighting
            e.Device.RenderState.Lighting = false;
            // Turn on the ZBuffer
            e.Device.RenderState.ZBufferEnable = true;

            e.Device.SamplerState[0].AddressU = TextureAddress.Clamp;
            e.Device.SamplerState[0].AddressV = TextureAddress.Clamp;

            string path = Utility.FindMediaFile("video\\skiing.avi");

            try
            {
                videoTexture         = Video.FromFile(path);
                videoTexture.Ending += new System.EventHandler(this.MovieOver);
                videoTexture.TextureReadyToRender += new TextureRenderEventHandler(this.RenderIt);

                // Now start rendering to our texture
                videoTexture.RenderToTexture(e.Device);

                canRender = true;
            }
            catch (Exception err)
            {
                MessageBox.Show(string.Format("An error has occurred that will not allow this sample to continue.\r\nException={0}", err.ToString()), "This sample must exit.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                sampleFramework.CloseWindow();
                throw err;
            }
        }