Ejemplo n.º 1
0
        void TextureChangedCore(object sender, TextureEventArgs e)
        {
            byte[] data = e.Data;
            if (e.Name == "terrain.png")
            {
                MemoryStream stream = new MemoryStream(data);
                Bitmap       atlas  = Platform.ReadBmp(stream);
                if (ChangeTerrainAtlas(atlas, null))
                {
                    return;
                }
                atlas.Dispose();
            }
            else if (e.Name == "cloud.png" || e.Name == "clouds.png")
            {
                UpdateTexture(ref CloudsTex, e.Name, data, false);
            }
            else if (e.Name == "default.png")
            {
                MemoryStream stream = new MemoryStream(data);
                Bitmap       bmp    = Platform.ReadBmp(stream);
                if (!Platform.Is32Bpp(bmp))
                {
                    Drawer2D.ConvertTo32Bpp(ref bmp);
                }

                Drawer2D.SetFontBitmap(bmp);
                Events.RaiseChatFontChanged();
            }
        }
Ejemplo n.º 2
0
        /// <summary> Reads a bitmap from the stream (converting it to 32 bits per pixel if necessary),
        /// and updates the native texture for it. </summary>
        public void UpdateTexture(ref int texId, byte[] data, bool setSkinType)
        {
            MemoryStream stream = new MemoryStream(data);

            Graphics.DeleteTexture(ref texId);

            using (Bitmap bmp = Platform.ReadBmp(stream)) {
                if (setSkinType)
                {
                    DefaultPlayerSkinType = Utils.GetSkinType(bmp);
                }

                if (!FastBitmap.CheckFormat(bmp.PixelFormat))
                {
                    using (Bitmap bmp32 = Drawer2D.ConvertTo32Bpp(bmp))
                        texId = Graphics.CreateTexture(bmp32);
                }
                else
                {
                    texId = Graphics.CreateTexture(bmp);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary> Reads a bitmap from the stream (converting it to 32 bits per pixel if necessary),
        /// and updates the native texture for it. </summary>
        public bool UpdateTexture(ref int texId, string file, byte[] data, bool setSkinType)
        {
            MemoryStream stream  = new MemoryStream(data);
            int          maxSize = Graphics.MaxTextureDimensions;

            using (Bitmap bmp = Platform.ReadBmp(stream)) {
                if (bmp.Width > maxSize || bmp.Height > maxSize)
                {
                    Chat.Add("&cUnable to use " + file + " from the texture pack.");
                    Chat.Add("&c Its size is (" + bmp.Width + "," + bmp.Height
                             + "), your GPU supports (" + maxSize + "," + maxSize + ") at most.");
                    return(false);
                }

                Graphics.DeleteTexture(ref texId);
                if (setSkinType)
                {
                    DefaultPlayerSkinType = Utils.GetSkinType(bmp);
                    if (DefaultPlayerSkinType == SkinType.Invalid)
                    {
                        throw new NotSupportedException("char.png has invalid dimensions");
                    }
                }

                if (!Platform.Is32Bpp(bmp))
                {
                    using (Bitmap bmp32 = Drawer2D.ConvertTo32Bpp(bmp))
                        texId = Graphics.CreateTexture(bmp32, true);
                }
                else
                {
                    texId = Graphics.CreateTexture(bmp, true);
                }
                return(true);
            }
        }