示例#1
0
        /// <summary>Creates a new solid color screen mask</summary>
        /// <param name="graphicsDevice">
        ///   Graphics device the screen mask will be draw with
        /// </param>
        /// <param name="createDelegate">
        ///   Factory method that will be used to instantiate the mask
        /// </param>
        /// <returns>The newly created solid color screen mask</returns>
        internal static ColorScreenMask Create(
            GraphicsDevice graphicsDevice, CreateDelegate createDelegate
            )
        {
            // Fake up a service provider with a graphics device service so we can
            // create a content manager without the huge rat-tail of references
            IServiceProvider serviceProvider;

            serviceProvider = GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
                GraphicsDeviceServiceHelper.MakeDummyGraphicsDeviceService(graphicsDevice)
                );

            // Create a resource content manager to load the default effect and hand
            // everything to the new screen mask instance, which will then be responsible
            // for freeing those resources again.
            ResourceContentManager contentManager = new ResourceContentManager(
                serviceProvider, Resources.ScreenMaskResources.ResourceManager
                );

            try {
                Effect effect = contentManager.Load <Effect>("ScreenMaskEffect");
                try {
                    return(createDelegate(graphicsDevice, contentManager, effect));
                }
                catch (Exception) {
                    effect.Dispose();
                    throw;
                }
            }
            catch (Exception) {
                contentManager.Dispose();
                throw;
            }
        }
示例#2
0
        /// <summary>Initializes a new text batch for rendering</summary>
        /// <param name="graphicsDevice">Graphics device to render to</param>
        public TextBatch(GraphicsDevice graphicsDevice)
        {
            this.dummyService = GraphicsDeviceServiceHelper.MakeDummyGraphicsDeviceService(
                graphicsDevice
                );
#if WINDOWS_PHONE
            // Windows Phone doesn't expose programmable shaders to XNA
            this.solidColorEffect = new BasicEffect(graphicsDevice);
#else
            this.contentManager = new ResourceContentManager(
                GraphicsDeviceServiceHelper.MakePrivateServiceProvider(this.dummyService),
                Resources.TextBatchResources.ResourceManager
                );

            // Create the default effect we're going to use for rendering
            this.solidColorEffect = this.contentManager.Load <Effect>("DefaultTextEffect");
#endif
#if XNA_3
            // Create a new vertex declaration for the internally used primitive batch
            this.vertexDeclaration = new VertexDeclaration(
                graphicsDevice, VertexPositionNormalTexture.VertexElements
                );
#endif

            // Set up our internal primitive batch. We delegate the vertex batching
            // methods to this class and just make it our responsibility to present
            // a clean interface to the user.
            this.primitiveBatch = new PrimitiveBatch <VertexPositionNormalTexture>(
                graphicsDevice
#if XNA_3
                , this.vertexDeclaration, VertexPositionNormalTexture.SizeInBytes
#endif
                );

            // Set up a view matrix that provides a 1:1 transformation of pixels to
            // world units. Unless the user sets his own ViewProjection matrix, this will
            // allow us to expose similar behavior to the XNA SpriteBatch class.
            this.viewProjection = new Matrix(
                2.0f / (float)graphicsDevice.Viewport.Width, 0.0f, 0.0f, 0.0f,
                0.0f, 2.0f / (float)graphicsDevice.Viewport.Height, 0.0f, 0.0f,
                0.0f, 0.0f, 1.0f, 0.0f,
                -1.0f, -1.0f, 0.0f, 1.0f
                );
        }