//NEW CODE protected override void Initialise() { //draw targets usually need a camera. Camera3D camera = new Camera3D(); //look at the sphere, which will be at 0,0,0 camera.LookAt(Vector3.Zero, new Vector3(0, 0, 4), Vector3.UnitY); //create the draw target texture in the same way the DrawSphere sample created the draw target screen //creates a 128x128 texture (the pixelation should be visible) drawToTexture = new DrawTargetTexture2D(camera, 128, 128, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); //make the texture clear colour different from the screen, so it's more obvious drawToTexture.ClearBuffer.ClearColour = Color.WhiteSmoke; //create the sphere (reused from Tutorial_03) Tutorial_03.SphereDrawer sphere = new Tutorial_03.SphereDrawer(Vector3.Zero); //Note, the sphere is added to the drawToTexture, not the drawToScreen drawToTexture.Add(sphere); //now, create the drawToScreen object.. //The same camera is being used, although it doesn't have to be. //The 2D element helper class that will be used will automatically push it's own 2D Camera when //drawing, to keep itself consistent. drawToScreen = new DrawTargetScreen(this, camera); drawToScreen.ClearBuffer.ClearColour = Color.CornflowerBlue; Vector2 sizeInPixels = new Vector2(512, 512); //Now create a 2D helper element that will display the texture on screen Xen.Ex.Graphics2D.TexturedElement displayTexture = null; //this helper class can directly take a DrawTargetTexture2D as a texture parameter. //This saves some effort here. //drawToTexture's Texture2D can be accessed with drawToTexture.GetTexture(), //in a similar way to XNA render targets. //However, at this point, drawToTexture.GetTexture() will be null - as the draw //target has yet to be drawn to. //drawToTexture.Warm() can be called, which will create the resources now. //However calling Warm() doesn't totally solve the problem because the texture //will change when content needs reloading (this happens after a device reset, etc) //The 2D helper element takes care of this itself. //Content loading/reloading and dealing with GetTexture() will be covered in the next example. //for now, the helper class will handle things. displayTexture = new TexturedElement(drawToTexture, sizeInPixels); //add it to the screen drawToScreen.Add(displayTexture); }
//NEW CODE protected override void Initialise() { //draw targets usually need a camera. var camera = new Camera3D(); //look at the sphere, which will be at 0,0,0 camera.LookAt(Vector3.Zero, new Vector3(0, 0, 4), Vector3.UnitY); //create the draw target texture in the same way the DrawSphere sample created the draw target screen //creates a 128x128 texture (the pixelation should be visible) drawToTexture = new DrawTargetTexture2D(camera, 128, 128, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); //make the texture clear colour different from the screen, so it's more obvious drawToTexture.ClearBuffer.ClearColour = Color.WhiteSmoke; //create the sphere (reused from Tutorial_03) var sphere = new Tutorial_03.SphereDrawer(Vector3.Zero); //Note, the sphere is added to the texture, not the screen drawToTexture.Add(sphere); //now, create the drawToScreen object.. //The same camera is being used, although it doesn't have to be. drawToScreen = new DrawTargetScreen(camera); drawToScreen.ClearBuffer.ClearColour = Color.CornflowerBlue; var sizeInPixels = new Vector2(512,512); //Now create a 2D helper element that will display the texture on screen Xen.Ex.Graphics2D.TexturedElement displayTexture = null; //this helper class can directly take a DrawTargetTexture2D as a constructor parameter. //drawToTexture's Texture2D can be accessed with drawToTexture.GetTexture(), //However, at this point, drawToTexture.GetTexture() will be null - as the draw //target has yet to be drawn to. //drawToTexture.Warm() can be called, which will create the resources now. //However calling Warm() doesn't totally solve the problem because the texture //will change when content needs reloading (this happens after a device reset, etc) //The 2D helper element takes care of this itself. //Content loading/reloading and dealing with GetTexture() will be covered in the next example. //for now, the helper class will handle things. //create the 2D helper element, which will display the texture on the screen. displayTexture = new TexturedElement(drawToTexture, sizeInPixels); //add it to the screen drawToScreen.Add(displayTexture); }