Example #1
0
        /// <summary>
        /// Handle the device reset event, recreate our
        /// environment maps
        /// </summary>
        private void OnDeviceReset(object sender, EventArgs e)
        {
            Device dev = (Device)sender;

            rte = new RenderToEnvironmentMap(dev, CubeMapSize, 1,
                                             Format.X8R8G8B8, true, DepthFormat.D16);

            environment = new CubeTexture(dev, CubeMapSize, 1,
                                          Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
        }
Example #2
0
        public void OnResetDevice()
        {
            int w = d3dDevice.PresentationParameters.BackBufferWidth;
            int h = d3dDevice.PresentationParameters.BackBufferHeight;

            fpsCamera.Aspect = ( float )w / ( float )h;

            SetupDeviceState();

            if (rts == null /*&& RtsEnabled*/)
            {
                rts        = new RenderToSurface(d3dDevice, surfWidth, surfHeight, Format.X8R8G8B8, true, DepthFormat.D24X8);
                rts.Reset += new EventHandler(rts_Reset);
                rts_Reset(this, null);
            }

            if (rte == null /*&& RteEnabled*/)
            {
                rte        = new RenderToEnvironmentMap(d3dDevice, envSize, 1, Format.X8R8G8B8, true, DepthFormat.D24X8);
                rte.Reset += new EventHandler(rte_Reset);
                rte_Reset(this, null);
            }
        }
Example #3
0
        /// <summary>
        /// The device exists, but may have just been Reset().  Resources in
        /// Pool.Default and any other device state that persists during
        /// rendering should be set here.  Render states, matrices, textures,
        /// etc., that don't change during rendering can be set once here to
        /// avoid redundant state setting during Render() or FrameMove().
        /// </summary>
        protected override void RestoreDeviceObjects(object sender, System.EventArgs e)
        {
            // InitializeDeviceObjects for file objects (build textures and vertex buffers)
            shinyTeapotMesh.RestoreDeviceObjects(device, null);
            skyBoxMesh.RestoreDeviceObjects(device, null);
            airplaneMesh.RestoreDeviceObjects(device, null);

            // Create RenderToEnvironmentMap object
            renderToEnvironmentMap = new RenderToEnvironmentMap(device, CubeMapResolution, 1,
                                                                device.PresentationParameters.BackBufferFormat, true, DepthFormat.D16);

            // Create the cubemap, with a format that matches the backbuffer
            if (Caps.TextureCaps.SupportsCubeMap)
            {
                try
                {
                    cubeMap = new CubeTexture(device, CubeMapResolution, 1,
                                              Usage.RenderTarget, device.PresentationParameters.BackBufferFormat, Pool.Default);
                }
                catch
                {
                    try
                    {
                        cubeMap = new CubeTexture(device, CubeMapResolution, 1,
                                                  0, device.PresentationParameters.BackBufferFormat, Pool.Default);
                    }
                    catch { cubeMap = null; }
                }
            }


            // Create the spheremap, with a format that matches the backbuffer
            if (cubeMap == null)
            {
                try
                {
                    sphereMap = new Texture(device, CubeMapResolution, CubeMapResolution,
                                            1, Usage.RenderTarget, device.PresentationParameters.BackBufferFormat, Pool.Default);
                }
                catch
                {
                    sphereMap = new Texture(device, CubeMapResolution, CubeMapResolution,
                                            1, 0, device.PresentationParameters.BackBufferFormat, Pool.Default);
                }
            }

            // Initialize effect
            effect.SetValue("texCubeMap", cubeMap);
            effect.SetValue("texSphereMap", sphereMap);

            if (cubeMap != null)
            {
                effect.Technique = "Cube";
                this.Text        = "CubeMap: Environment cube-mapping";
            }
            else
            {
                effect.Technique = "Sphere";
                this.Text        = "CubeMap: Environment cube-mapping (using dynamic spheremap)";
            }

            viewMatrixHandle       = effect.GetParameter(null, "matView");
            worldMatrixHandle      = effect.GetParameter(null, "matWorld");
            worldViewMatrixHandle  = effect.GetParameter(null, "matWorldView");
            projectionMatrixHandle = effect.GetParameter(null, "matProject");

            // Set the transform matrices
            float fAspect = (float)device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight;

            projectionMatrix = Matrix.PerspectiveFovLH((float)Math.PI * 0.4f, fAspect, 0.5f, 100.0f);
        }
 /// <summary>
 /// Predispone l'oggetto CubeMap ad essere generato dall'ambiente circostante (Rendering to target) (da utilizzare all'esterno del GameLoop)
 /// </summary>
 /// <param name="EdgeLength"></param>
 /// <returns></returns>
 public bool InitializeRenderToCube(int EdgeLength)
 {
     try
     {
         viewport = new Viewport();
         viewport.MaxZ = 1;
         viewport.Width = EdgeLength;
         viewport.Height = EdgeLength;
         LogiX_Engine.Device.RenderState.NormalizeNormals = true;
         cube = new CubeTexture(LogiX_Engine.Device, EdgeLength, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
         renderToEnvy = new RenderToEnvironmentMap(LogiX_Engine.Device, EdgeLength, 1, Format.X8R8G8B8, true, DepthFormat.D16);
         cam = new Camera(new VertexData(0, 0, 0), new VertexData(0, 0, 0));
         cam.FarPlane = 100000;
         cam.AspectRatio = 1;
         cam.FieldOfView = (float)Math.PI / 2;
         path = null;
         correct = true;
         return true;
     }
     catch
     {
         Error("OnInitializeRenderToCube");
         return false;
     }
 }