Exemplo n.º 1
0
        /// <summary>
        /// Loads a Texture trying both TextureLoader and GDI as interim
        /// </summary>
        /// <param name="device">Direct3D Device to load the texture into</param>
        /// <param name="path">Path to load the texture from</param>
        /// <returns>A Direct3D Texture object. Null if failed</returns>
        public static OrbitTexture Load(Device device, string path)
        {
            Texture loadedTexture = null;

            // if file is an ICO file, use the FromIcon, otherwise proceed to the other ones
            if (System.IO.Path.GetExtension(path).Trim().ToLower() == ".ico")
            {
                loadedTexture = FromIcon(device, path);
            }
            // if not icon, try the other two possible methods
            if (loadedTexture == null)
            {
                // try TextureLoader
                loadedTexture = FromLoader(device, path);
                if (loadedTexture == null)
                {
                    // this means TextureLoader failed. try GDI
                    loadedTexture = FromGDI(device, path);
                }
            }

            // will return a texture of any of them succeeded. since both return null, will return null if failed.
            OrbitTexture orbitTexture = new OrbitTexture(loadedTexture, path);

            return(orbitTexture.GetReference());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a Texture from a GDI+ Bitmap
        /// </summary>
        /// <param name="device">Direct3D Device to load the texture into</param>
        /// <param name="sourceStream">Stream from which to create the texture</param>
        /// <returns>A OrbitTexture object. Null if failed</returns>
        public static OrbitTexture Load(Device device, System.IO.Stream sourceStream)
        {
            // try and load from the bitmap
            Texture texture = null;

            try
            {
                texture = new Texture(device, sourceStream, Usage.Dynamic, Pool.Default);
            }
            catch (Exception)
            {
                // return nothing if it fails
                return(null);
            }
            // create our OrbitTexture object which will house all the texture description parameters
            OrbitTexture orbitTexture = new OrbitTexture(texture);

            return(orbitTexture.GetReference());
        }