示例#1
0
        /// <summary>
        /// Loads pngs to 2d textures. Create 1 2dtexture for one msdf folder.
        /// </summary>
        public void LoadFontTexturesAsPng(string fontname)
        {
            FileSystem.IReadOnlyPackage pack;
            string temp;

            string p1, p2;

            if (Game.ModData.Manifest.FontsMSDFBaseFolders == null)
            {
                return;
            }
            p1 = Game.ModData.Manifest.FontsMSDFBaseFolders[fontname].First;
            p2 = Game.ModData.Manifest.FontsMSDFBaseFolders[fontname].Second;

            Texture             = Game.Renderer.Context.CreateTexture2DArray();
            Texture.scaleFilter = TextureScaleFilter.Linear;
            Texture.SetEmpty(Size, Size, 127);             // просто заготовка gjl 127 слойный массив, каждый слой 96 на 96 пикселей.



            if (Game.ModData.DefaultFileSystem.TryGetPackageContaining(p2, out pack, out temp))
            {
                foreach (string f in pack.Contents)
                {
                    using (var stream = pack.GetStream(f))
                    {
                        Png pic;
                        try
                        {
                            pic = new Png(stream);
                            Texture.SetData(pic.Data, Size, Size, Convert.ToInt32(f.Split('.')[0]));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error loading char: {0} x {1}", f, Convert.ToInt32(f.Split('.')[0]));
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("MSDF fonts not loaded. Create font folder and write it to mod.yaml Packages for mod=" + Game.ModData.Manifest.Id + " path=");
            }
        }
示例#2
0
        /// <summary>
        /// Создает текстуру в OPenGL для данного Sheet
        /// </summary>
        /// <returns></returns>
        public ITexture AssignOrGetOrSetDataGLTexture()
        {
            if (texture == null)
            {
                texture             = Game.Renderer.Context.CreateTexture2DArray();
                texture.scaleFilter = TextureScaleFilter.Nearest;
                texture.SetEmpty(Size.Width, Size.Width, 10);
                dirty = true;
            }

            if (data != null && dirty)
            {
                //Flush CPU data to GPU data(OpenGL Texture)
                texture.SetData(data, Size.Width, Size.Width, textureArrayIndex);
                dirty = false;
                if (releaseBufferOnCommit)
                {
                    data = null;
                }
            }

            return(texture);
        }