Example #1
0
        protected override Task LoadContent()
#endif
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            var assembly = GetType().Assembly;

            _font = StaticSpriteFont.FromBMFont(assembly.ReadResourceAsString("FontStashSharp.Samples.StaticSpriteFont.Fonts.Arial.fnt"),
                                                fileName => assembly.OpenResourceStream("FontStashSharp.Samples.StaticSpriteFont.Fonts." + fileName),
                                                GraphicsDevice);

#if MONOGAME || FNA
            _white = new Texture2D(GraphicsDevice, 1, 1);
            _white.SetData(new[] { Color.White });
#elif STRIDE
            _white = Texture2D.New2D(GraphicsDevice, 1, 1, false, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.ShaderResource);
            _white.SetData(GraphicsContext.CommandList, new[] { Color.White });
#endif

            GC.Collect();

#if STRIDE
            return(base.LoadContent());
#endif
        }
Example #2
0
        public SpriteFont NewStatic(float size, IList<Glyph> glyphs, IList<Image> images, float baseOffset, float defaultLineSpacing, IList<Kerning> kernings = null, float extraSpacing = 0, float extraLineSpacing = 0, char defaultCharacter = ' ')
        {
            var font = new StaticSpriteFont(size, glyphs, null, baseOffset, defaultLineSpacing, kernings, extraSpacing, extraLineSpacing, defaultCharacter) { FontSystem = this };

            // affects the textures from the images.
            foreach (var image in images)
                font.StaticTextures.Add(Texture.New(GraphicsDevice, image).DisposeBy(font));

            return font;
        }
        public void Load()
        {
            var assembly = TestsEnvironment.Assembly;
            var data     = assembly.ReadResourceAsString("Resources.arial64.fnt");

            var font = StaticSpriteFont.FromBMFont(data, fileName => assembly.OpenResourceStream("Resources." + fileName), TestsEnvironment.GraphicsDevice);

            Assert.AreEqual(font.FontSize, 63);
            Assert.AreEqual(font.Glyphs.Count, 191);

            var texture = font.Glyphs.First().Value.Texture;

            Assert.NotNull(texture);
            Assert.AreEqual(texture.Width, 512);
            Assert.AreEqual(texture.Height, 512);
        }
        public override void ConvertFromData(ConverterContext converterContext, StaticSpriteFontData data, ref SpriteFont obj)
        {
            var services   = converterContext.Tags.Get(ServiceRegistry.ServiceRegistryKey);
            var fontSystem = services.GetSafeServiceAs <GameFontSystem>().FontSystem;

            var staticSpriteFont = new StaticSpriteFont(fontSystem, data);

            for (int index = 0; index < data.Bitmaps.Length; index++)
            {
                var bitmap = data.Bitmaps[index];

                // Convert to texture ref so that Converter system doesn't get lost
                // TODO: Support that directly in converter?
                var textureRef = new ContentReference <Texture2D> {
                    Location = bitmap.Location
                };
                Texture2D texture = null;
                converterContext.ConvertFromData(textureRef, ref texture);
                staticSpriteFont.StaticTextures[index] = texture;
            }

            obj = staticSpriteFont;
        }