Ejemplo n.º 1
0
        /// <summary>
        /// Application constructor
        /// </summary>
        public BillboardForm()
        {
            // Set the window text
            this.Text = "Billboard: D3D Billboarding Example";

            this.MinimizeBox = false;

            skyBoxMesh  = new GraphicsMesh();
            terrainMesh = new GraphicsMesh();

            OnetimeSceneInitialization();
            // Now let's setup our D3D parameters
            PresentParameters presentParams = new PresentParameters();

            presentParams.Windowed               = true;
            presentParams.SwapEffect             = SwapEffect.Discard;
            presentParams.AutoDepthStencilFormat = DepthFormat.D16;
            presentParams.EnableAutoDepthStencil = true;

            // create the device
            device = new Device(0, DeviceType.Default, this,
                                CreateFlags.None, presentParams);
            // store the render state
            renderState = device.RenderState;
            // initialize any device resources that aren't lost on reset
            InitializeDeviceObjects();
            // attach the reset callback
            device.DeviceReset += new EventHandler(RestoreDeviceObjects);
            // initialize any device resources that are lost on reset
            RestoreDeviceObjects(device, EventArgs.Empty);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The device has been created.  Resources that are not lost on
        /// Reset() can be created here
        /// </summary>
        public void InitializeDeviceObjects()
        {
            Pool vertexBufferPool;
            Caps caps;

            // Initialize the font's internal textures
            font = new Font(device, new System.Drawing.Font("Arial",
                                                            12.0f, System.Drawing.FontStyle.Bold));

            // Load the main file object
            if (airplane == null)
            {
                airplane = new GraphicsMesh();
            }

            airplane.Create(device,
                            "StencilBufferShadowVolume.Content.", "air2.md3dm",
                            System.Reflection.Assembly.GetExecutingAssembly());

            // Load the terrain
            if (terrainObject == null)
            {
                terrainObject = new GraphicsMesh();
            }

            terrainObject.Create(device,
                                 "StencilBufferShadowVolume.Content.", "seafloor.md3dm",
                                 System.Reflection.Assembly.GetExecutingAssembly());

            // Set a reasonable vertex type
            terrainObject.SetVertexFormat(MeshVertex.Format);
            airplane.SetVertexFormat(MeshVertex.Format);

            // Get the device capabilities

            caps = device.DeviceCaps;

            if (caps.SurfaceCaps.SupportsVidVertexBuffer)
            {
                vertexBufferPool = Pool.VideoMemory;
            }
            else
            {
                vertexBufferPool = Pool.SystemMemory;
            }

            // Create a big square for rendering the mirror, we don't
            // need to recreate this every time, if the VertexBuffer
            // is destroyed (by a call to Reset for example), it will
            // automatically be recreated and the 'Created' event fired.
            squareVertexBuffer = new VertexBuffer(typeof(ShadowVertex), 4,
                                                  device, Usage.WriteOnly, ShadowVertex.Format,
                                                  vertexBufferPool);
            squareVertexBuffer.Created += new System.EventHandler(
                this.ShadowCreated);

            // Manually fire the created event the first time
            this.ShadowCreated(squareVertexBuffer, null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The device has been created.  Resources that are not lost on
        /// Reset() can be created here.
        /// </summary>
        public void InitializeDeviceObjects()
        {
            // Load the main file object
            for (int i = 0; i < 2; i++)
            {
                if (fileObject[i] == null)
                {
                    fileObject[i] = new GraphicsMesh();
                }
            }

            // Load a .md3dm file
            fileObject[0].Create(device,
                                 "StencilBufferStencilDepth.Content.", "heli.md3dm",
                                 System.Reflection.Assembly.GetExecutingAssembly());
            fileObject[1].Create(device,
                                 "StencilBufferStencilDepth.Content.", "air2.md3dm",
                                 System.Reflection.Assembly.GetExecutingAssembly());
            if ((squareVertexBuffer == null) || (squareVertexBuffer.Disposed))
            {
                Pool vertexBufferPool;
                Caps caps;

                // Get the device capabilities

                caps = device.DeviceCaps;

                if (caps.SurfaceCaps.SupportsVidVertexBuffer)
                {
                    vertexBufferPool = Pool.VideoMemory;
                }
                else
                {
                    vertexBufferPool = Pool.SystemMemory;
                }

                // Create a big square for rendering the stencilbuffer
                // contents
                squareVertexBuffer = new VertexBuffer(typeof(Vector4), 4,
                                                      device, Usage.WriteOnly, VertexFormats.Transformed,
                                                      vertexBufferPool);
                squareVertexBuffer.Created += new System.EventHandler(
                    this.SquareVBCreated);
                this.SquareVBCreated(squareVertexBuffer, null);
            }
        }