private static DisplayObject GetCutUpTexturesFromBoundImage(int sectionSize, string fileName = "") { bool success = IL.ConvertImage(DevIL.DataFormat.RGBA, DevIL.DataType.UnsignedByte); if (!success) { return(null); } DisplayObject image = new DisplayObject(); Vector2i size = new Vector2i(IL.GetImageInfo().Width, IL.GetImageInfo().Height); Vector2u amount = new Vector2u((uint)Math.Ceiling(size.X / (float)sectionSize), (uint)Math.Ceiling(size.Y / (float)sectionSize)); Vector2i currentSize = new Vector2i(size.X, size.Y); Vector2i pos = new Vector2i(); for (int iy = 0; iy < amount.Y; iy++) { int h = Math.Min(currentSize.Y, sectionSize); currentSize.Y -= h; currentSize.X = size.X; for (int ix = 0; ix < amount.X; ix++) { int w = Math.Min(currentSize.X, sectionSize); currentSize.X -= w; Texture texture = new Texture((uint)w, (uint)h); IntPtr partPtr = Marshal.AllocHGlobal((w * h) * 4); IL.CopyPixels(pos.X, pos.Y, 0, w, h, 1, DevIL.DataFormat.RGBA, DevIL.DataType.UnsignedByte, partPtr); Texture.Bind(texture); { Gl.glTexImage2D( Gl.GL_TEXTURE_2D, 0, IL.GetInteger(ILIntegerMode.ImageBytesPerPixel), w, h, 0, IL.GetInteger(ILIntegerMode.ImageFormat), ILDefines.IL_UNSIGNED_BYTE, partPtr); } Texture.Bind(null); Marshal.FreeHGlobal(partPtr); Sprite sprite = new Sprite(texture); sprite.Position = new Vector2f(pos.X, pos.Y); image.AddChild(sprite); if (fileName != "") { Textures.Add(texture); TextureFileNames.Add(fileName + "_" + ix.ToString("00") + "_" + iy.ToString("00") + "^"); } pos.X += w; } pos.Y += h; pos.X = 0; } image.Texture.Size = new Vector2u((uint)size.X, (uint)size.Y); SplitTextures.Add(image); SplitTextureFileNames.Add(fileName); return(image); }
private static DisplayObject GetCutUpTexturesFromBoundImage(int sectionSize, string fileName = "") { bool success = IL.ConvertImage(DevIL.DataFormat.RGBA, DevIL.DataType.UnsignedByte); if (!success) return null; DisplayObject image = new DisplayObject(); Vector2i size = new Vector2i(IL.GetImageInfo().Width, IL.GetImageInfo().Height); Vector2u amount = new Vector2u((uint)Math.Ceiling(size.X / (float)sectionSize), (uint)Math.Ceiling(size.Y / (float)sectionSize)); Vector2i currentSize = new Vector2i(size.X, size.Y); Vector2i pos = new Vector2i(); for (int iy = 0; iy < amount.Y; iy++) { int h = Math.Min(currentSize.Y, sectionSize); currentSize.Y -= h; currentSize.X = size.X; for (int ix = 0; ix < amount.X; ix++) { int w = Math.Min(currentSize.X, sectionSize); currentSize.X -= w; Texture texture = new Texture((uint)w, (uint)h); IntPtr partPtr = Marshal.AllocHGlobal((w * h) * 4); IL.CopyPixels(pos.X, pos.Y, 0, w, h, 1, DevIL.DataFormat.RGBA, DevIL.DataType.UnsignedByte, partPtr); Texture.Bind(texture); { Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR); Gl.glTexImage2D( Gl.GL_TEXTURE_2D, 0, IL.GetInteger(ILIntegerMode.ImageBytesPerPixel), w, h, 0, IL.GetInteger(ILIntegerMode.ImageFormat), ILDefines.IL_UNSIGNED_BYTE, partPtr); } Texture.Bind(null); Marshal.FreeHGlobal(partPtr); Sprite sprite = new Sprite(texture); sprite.Position = new Vector2f(pos.X, pos.Y); image.AddChild(sprite); if (fileName != "") { Textures.Add(texture); TextureFileNames.Add(fileName + "_" + ix.ToString("00") + "_" + iy.ToString("00") + "^"); } pos.X += w; } pos.Y += h; pos.X = 0; } image.Texture.Size = new Vector2u((uint)size.X, (uint)size.Y); SplitTextures.Add(image); SplitTextureFileNames.Add(fileName); return image; }