Пример #1
0
        /// <summary>
        /// Creates a texture from a bitmap.
        /// </summary>
        /// <param name="bitmap">The bitmap to create the texture from.</param>
        /// <returns>The created texture.</returns>
        public static pTexture FromBitmap(Bitmap bitmap, TextureAtlas atlas = null)
        {
            if (bitmap == null)
            {
                return(null);
            }

            int usableWidth  = Math.Min(OsuGlControl.MaxTextureSize, bitmap.Width);
            int usableHeight = Math.Min(OsuGlControl.MaxTextureSize, bitmap.Height);

            pTexture tex = atlas == null ? new pTexture(usableWidth, usableHeight) : atlas.Add(usableWidth, usableHeight);

            tex.SetData(bitmap);

            return(tex);
        }
Пример #2
0
        /// <summary>
        /// Read a pTexture from the ResourceStore (ouenresources project).
        /// </summary>
        public static pTexture FromResourceStore(string filename, TextureAtlas atlas = null)
        {
            pTexture tex = null;

#if DEBUG
            tex = fromDebugLocations(filename);
            if (tex != null)
            {
                return(tex);
            }
#endif

            //load using newer resources where available.
            if (GameBase.NewGraphicsAvailable)
            {
                tex = FromNewResourceStore(filename, atlas);
                if (tex != null)
                {
                    tex.Filename = filename;
                    return(tex);
                }
            }

            byte[] bytes = ResourcesStore.ResourceManager.GetObject(filename) as byte[];

            if (bytes == null)
            {
                return(null);
            }

            using (Stream stream = new MemoryStream(bytes))
            {
                using (HaxBinaryReader br = new HaxBinaryReader(stream))
                {
                    //XNA pipeline header crap.  F**k it all.
                    br.ReadBytes(10);
                    int typeCount = br.Read7BitEncodedInt();
                    for (int i = 0; i < typeCount; i++)
                    {
                        br.ReadString();
                        br.ReadInt32();
                    }
                    br.Read7BitEncodedInt();
                    br.Read7BitEncodedInt();
                    //And that's the header dealt with.

                    br.ReadInt32();

                    int width  = br.ReadInt32();
                    int height = br.ReadInt32();

                    tex          = atlas == null ? new pTexture(width, height) : atlas.Add(width, height);
                    tex.Filename = filename;

                    int numberLevels = br.ReadInt32();

                    for (int i = 0; i < numberLevels; i++)
                    {
                        int    count = br.ReadInt32();
                        byte[] data  = br.ReadBytes(count);

                        bgraToRgba(data, data.Length);
                        tex.SetData(data, i, 0);
                    }
                }
            }

            return(tex);
        }