Ejemplo n.º 1
0
        /// <summary>Creates a image from given URL.</summary>
        /// <param name="preferredName">Name of the preferred.</param>
        /// <param name="imageLocation">The image location on disk.</param>
        /// <returns>The location of the created resource.</returns>
        /// <exception cref="ArgumentNullException">PreferredName or imageLocation. </exception>
        public string CreateFromUrl(string preferredName, string imageLocation)
        {
#if DEBUG
            if (string.IsNullOrEmpty(preferredName))
            {
                throw new ArgumentNullException("preferredName");
            }

            if (imageLocation == null)
            {
                throw new ArgumentNullException("imageLocation");
            }

            if (string.IsNullOrEmpty(imageLocation.ToString()))
            {
                throw new ArgumentNullException("imageLocation");
            }
#endif

            var texture      = this.contentManager.Load <Texture2D>(imageLocation.ToString());
            var resourceName = UniqueNameCreator.GetUniqueName(preferredName);
            Resources.Add(resourceName, texture);

            return(resourceName);
        }
Ejemplo n.º 2
0
        public string CreateRenderTarget(string preferredName, int width, int height, bool mipMap)
        {
            var renderTarget = new RenderTarget2D(
                this.device,
                width,
                height,
                mipMap,
                SurfaceFormat.Color,
                DepthFormat.Depth24);

            var resourceName = UniqueNameCreator.GetUniqueName(preferredName);

            Resources.Add(resourceName, renderTarget);

            return(resourceName);
        }
Ejemplo n.º 3
0
        /// <summary>Creates the texture.</summary>
        /// <param name="name">The name of the texture.</param>
        /// <param name="width">The width of the texture.</param>
        /// <param name="height">The height of the texture.</param>
        /// <param name="color">The color of texture.</param>
        /// <returns>The created texture.</returns>
        /// <exception cref="ArgumentNullException">Name is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">width can not be smaller then 1 and height can not be smaller then 1. </exception>
        public string Create(string name, int width, int height, GUIColor color)
        {
#if DEBUG
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (width < 1)
            {
                throw new ArgumentOutOfRangeException("width", "width can not be smaller then 1");
            }

            if (height < 1)
            {
                throw new ArgumentOutOfRangeException("height", "height can not be smaller then 1");
            }
#endif

            var texture = new Texture2D(this.device, width, height, false, SurfaceFormat.Color);
            var count   = width * height;
            var array   = new GUIColor[count];

            for (var i = 0; i < array.Length; i++)
            {
                array[i] = color;
            }

            texture.SetData(array);

            var resourceName = UniqueNameCreator.GetUniqueName(name);
            texture.Name = resourceName;

            Resources.Add(resourceName, texture);

            return(resourceName);
        }