Exemplo n.º 1
0
        public static Texture2D FromFile(GraphicsDevice graphicsDevice, string filename)
        {
            Bitmap image = BitmapFactory.DecodeFile(filename);

            if (image == null)
            {
                throw new ContentLoadException("Error loading file: " + filename);
            }

            ESImage   theTexture = new ESImage(image, graphicsDevice.PreferedFilter);
            Texture2D result     = new Texture2D(theTexture);

            result.Name = Path.GetFileNameWithoutExtension(filename);
            return(result);
        }
Exemplo n.º 2
0
        public ESImage GetSubImageAtPoint(Vector2 point, int subImageWidth, int subImageHeight, float subImageScale)
        {
            //Create a new Image instance using the texture which has been assigned to the current instance
            ESImage subImage = new ESImage(texture, subImageScale);

            // Define the offset of the subimage we want using the point provided
            subImage.TextureOffsetX = (int)point.X;
            subImage.TextureOffsetY = (int)point.Y;

            // Set the width and the height of the subimage
            subImage.ImageWidth  = subImageWidth;
            subImage.ImageHeight = subImageHeight;

            return(subImage);
        }
Exemplo n.º 3
0
        public static Texture2D FromFile(GraphicsDevice graphicsDevice, Stream textureStream)
        {
            MonoTouch.Foundation.NSData nsData = MonoTouch.Foundation.NSData.FromStream(textureStream);

            UIImage image = UIImage.LoadFromData(nsData);

            if (image == null)
            {
                throw new ContentLoadException("Error loading Texture2D Stream");
            }

            ESImage   theTexture = new ESImage(image, graphicsDevice.PreferedFilter);
            Texture2D result     = new Texture2D(theTexture);

            return(result);
        }
Exemplo n.º 4
0
        public static Texture2D FromFile(GraphicsDevice graphicsDevice, string filename, int width, int height)
        {
            Bitmap image = (Bitmap)Bitmap.FromFile(filename);

            if (image == null)
            {
                throw new ContentLoadException("Error loading file: " + filename);
            }

            // TODO resize
            ESImage   theTexture = new ESImage(image, graphicsDevice.PreferedFilter);
            Texture2D result     = new Texture2D(theTexture);

            result.Name = Path.GetFileNameWithoutExtension(filename);
            return(result);
        }
Exemplo n.º 5
0
        public static Texture2D FromFile(GraphicsDevice graphicsDevice, Stream textureStream)
        {
            Bitmap image = (Bitmap)Bitmap.FromStream(textureStream);

            if (image == null)
            {
                throw new ContentLoadException("Error loading Texture2D Stream");
            }

            ESImage   theTexture = new ESImage(image, graphicsDevice.PreferedFilter);
            Texture2D result     = new Texture2D(theTexture);



            return(result);
        }
Exemplo n.º 6
0
        public static Texture2D FromStream(GraphicsDevice graphicsDevice, Stream stream)
        {
            var image = (Bitmap)Bitmap.FromStream(stream);

            if (image == null)
            {
                throw new ContentLoadException("Error loading Texture2D Stream");
            }

            // Fix up the Image to match the expected format
            image.RGBToBGR();

            var theTexture = new ESImage(image, graphicsDevice.PreferedFilter);
            var result     = new Texture2D(theTexture);

            return(result);
        }
Exemplo n.º 7
0
        public static Texture2D FromFile(GraphicsDevice graphicsDevice, string filename, int width, int height)
        {
            UIImage image;

            if (filename.Contains(".pdf"))
            {
                image = Extender.FromPdf(filename, width, height);
            }
            else
            {
                // If we are loading graphics from the Content folder then we can take advantage of the FromBundle methods ability
                // to automatically cope with @2x graphics for high resolution devices.  If we are loading from somewhere else (e.g.
                // the documents folder for our app) then FromBundle will not work and so we must call FromFile.
                if (filename.StartsWith("Content/", StringComparison.OrdinalIgnoreCase) == true)
                {
                    image = UIImage.FromBundle(filename);
                }
                else
                {
                    image = UIImage.FromFile(filename);
                }
            }

            if (image == null)
            {
                throw new ContentLoadException("Error loading file: " + filename);
            }

            ESImage theTexture;

            if (width == 0 && height == 0)
            {
                theTexture = new ESImage(image, graphicsDevice.PreferedFilter);
            }
            else
            {
                var small = image.Scale(new SizeF(width, height));
                theTexture = new ESImage(small, graphicsDevice.PreferedFilter);
            }

            Texture2D result = new Texture2D(theTexture);

            // result.Name = Path.GetFileNameWithoutExtension(filename);
            result.Name = filename;
            return(result);
        }
Exemplo n.º 8
0
        public Texture2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat format)
        {
            throw new Exception();

            this.graphicsDevice = graphicsDevice;

            this._format = format;
            this._mipmap = mipMap;


            if (GraphicsDevice.OpenGLESVersion == OpenGLES.EAGLRenderingAPI.OpenGLES2)
            {
                this._width  = width;
                this._height = height;
                texture      = new ESImage(width, height);
            }
            else
            {
                // This is needed in OpenGL ES 1.1 as it only supports power of 2 textures
                int xTexSize = 1;
                int yTexSize = 1;
                while (width > xTexSize && height > yTexSize)
                {
                    if (width > xTexSize)
                    {
                        xTexSize *= 2;
                    }
                    if (height > yTexSize)
                    {
                        yTexSize *= 2;
                    }
                }

                this._width  = xTexSize;
                this._height = yTexSize;

                generateOpenGLTexture();
            }
        }
Exemplo n.º 9
0
        public static Texture2D FromFile(GraphicsDevice graphicsDevice, Stream textureStream)
        {
            Bitmap image = BitmapFactory.DecodeStream(textureStream);

            if (image == null)
            {
                throw new ContentLoadException("Error loading Texture2D Stream");
            }
            ESImage theTexture;

            if (GraphicsDevice.openGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0)
            {
                theTexture = new ESImage(image, graphicsDevice.PreferedFilterGL20);
            }
            else
            {
                theTexture = new ESImage(image, graphicsDevice.PreferedFilterGL11);
            }

            Texture2D result = new Texture2D(theTexture);

            return(result);
        }
Exemplo n.º 10
0
        public ESImage GetSubImageAtPoint(Vector2 point, int subImageWidth, int subImageHeight, float subImageScale)
        {
            //Create a new Image instance using the texture which has been assigned to the current instance
            ESImage subImage = new ESImage(texture, subImageScale);
            // Define the offset of the subimage we want using the point provided
            subImage.TextureOffsetX = (int)point.X;
            subImage.TextureOffsetY = (int)point.Y;

            // Set the width and the height of the subimage
            subImage.ImageWidth = subImageWidth;
            subImage.ImageHeight = subImageHeight;

            return subImage;
        }
Exemplo n.º 11
0
 internal Texture2D(ESImage theImage)
 {
     texture = theImage;
 }