public static Texture2d Load(string filename, ResourceManager resourceManager = null, TextureOptions textureOptions = null)
        {
            try
            {
                textureOptions = textureOptions ?? TextureOptions.Load(TextureOptions.GetOptionsFilename(filename), resourceManager);
            }
            catch (FileNotFoundException)
            {
                Trace.WriteLine($"No texture options for {filename}");
            }

            if (File.Exists(filename))
            {
                using (var stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                    return(Load(stream, filename, textureOptions));
            }

            if (resourceManager == null)
            {
                return(null);
            }
            var resourceName = filename.Substring(0, filename.LastIndexOf(".")).Replace('-', '_');

            using (var bitmap = resourceManager.GetObject(resourceName) as Bitmap)
                if (bitmap != null)
                {
                    return(Load(bitmap, $"file:{filename}", textureOptions));
                }
                else
                {
                    Trace.WriteLine($"Texture not found: {filename} / {resourceName}");
                    return(null);
                }
        }
        private static TextureOptions load(JObject data)
        {
            var options = new TextureOptions();

            parseFields(options, data);
            return(options);
        }
Exemple #3
0
 public TextureMultiAtlas2d(int width, int height, string description, TextureOptions textureOptions = null)
 {
     this.width = width;
     this.height = height;
     this.description = description;
     this.textureOptions = textureOptions;
     pushAtlas();
 }
 public TextureContainerAtlas(ResourceContainer resourceContainer = null, TextureOptions textureOptions = null, int width = 512, int height = 512, int padding = 0, string description = nameof(TextureContainerAtlas))
 {
     this.resourceContainer = resourceContainer;
     this.textureOptions    = textureOptions;
     this.width             = width;
     this.height            = height;
     this.padding           = padding;
     this.description       = description;
 }
Exemple #5
0
        public static Texture2d Load(Bitmap bitmap, string description, TextureOptions textureOptions = null)
        {
            if (bitmap == null)
            {
                throw new ArgumentNullException(nameof(bitmap));
            }

            textureOptions = textureOptions ?? TextureOptions.Default;
            var sRgb = textureOptions.Srgb && DrawState.ColorCorrected;

            var textureId = GL.GenTexture();

            try
            {
                DrawState.BindTexture(textureId);

                var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                GL.TexImage2D(TextureTarget.Texture2D, 0, sRgb ? PixelInternalFormat.SrgbAlpha : PixelInternalFormat.Rgba, bitmapData.Width, bitmapData.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bitmapData.Scan0);
                if (textureOptions.GenerateMipmaps)
                {
                    GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                }
                GL.Finish();
                bitmap.UnlockBits(bitmapData);
                DrawState.CheckError("specifying texture");

                textureOptions.ApplyParameters(TextureTarget.Texture2D);
            }
            catch (Exception)
            {
                GL.DeleteTexture(textureId);
                DrawState.UnbindTexture(textureId);
                throw;
            }

            return(new Texture2d(textureId, bitmap.Width, bitmap.Height, description));
        }
 public TextureContainerSeparate(ResourceContainer resourceContainer = null, TextureOptions textureOptions = null)
 {
     this.resourceContainer = resourceContainer;
     this.textureOptions    = textureOptions;
 }
 public TextureAtlas2d(int width, int height, string description, TextureOptions textureOptions = null)
     : this(Texture2d.Create(new Color4(0, 0, 0, 0), description, width, height, textureOptions))
 {
 }
Exemple #8
0
        public static Texture2d Create(Color4 color, string description, int width = 1, int height = 1, TextureOptions textureOptions = null)
        {
            if (width < 1 || height < 1)
            {
                throw new InvalidOperationException($"Invalid texture size: {width}x{height}");
            }

            textureOptions = textureOptions ?? TextureOptions.Default;

            var textureId = GL.GenTexture();

            try
            {
                var data = new int[width * height];
                for (int i = 0; i < width * height; i++)
                {
                    data[i] = color.ToRgba();
                }

                DrawState.BindTexture(textureId);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, data);
                if (textureOptions.GenerateMipmaps)
                {
                    GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                    GL.Finish();
                }
                DrawState.CheckError("specifying texture");

                textureOptions.ApplyParameters(TextureTarget.Texture2D);
            }
            catch (Exception)
            {
                GL.DeleteTexture(textureId);
                DrawState.UnbindTexture(textureId);
                throw;
            }

            return(new Texture2d(textureId, width, height, description));
        }
Exemple #9
0
 public static Texture2d Load(string filename, ResourceContainer resourceContainer = null, TextureOptions textureOptions = null)
 {
     using (var bitmap = LoadBitmap(filename, resourceContainer))
         return(bitmap != null?Load(bitmap, $"file:{filename}", textureOptions ?? LoadTextureOptions(filename, resourceContainer)) : null);
 }
Exemple #10
0
 public static TextureOptions LoadTextureOptions(string forBitmapFilename, ResourceContainer resourceContainer = null)
 => TextureOptions.Load(TextureOptions.GetOptionsFilename(forBitmapFilename), resourceContainer);
Exemple #11
0
 public static Texture2d Load(Stream stream, string filename, TextureOptions textureOptions = null)
 {
     using (var bitmap = (Bitmap)Image.FromStream(stream, false, false))
         return(Load(bitmap, $"file:{filename}", textureOptions));
 }