Example #1
0
        public override BitmapFontProcessorResult Process(BitmapFontFile bitmapFontFile,
                                                          ContentProcessorContext context)
        {
            try
            {
                context.Logger.LogMessage("Processing BMFont, Kerning pairs: {0}", bitmapFontFile.Kernings.Count);
                var result = new BitmapFontProcessorResult(bitmapFontFile);
                result.PackTexturesIntoXnb = PackTexturesIntoXnb;

                foreach (var fontPage in bitmapFontFile.Pages)
                {
                    // find our texture so we can embed it in the xnb asset
                    var imageFile = Path.Combine(Path.GetDirectoryName(bitmapFontFile.File), fontPage.File);
                    context.Logger.LogMessage("looking for image file: {0}", imageFile);

                    if (!File.Exists(imageFile))
                    {
                        throw new Exception(string.Format("Could not locate font atlas file {0} relative to folder {1}",
                                                          fontPage.File, Directory.GetCurrentDirectory()));
                    }

                    if (PackTexturesIntoXnb)
                    {
                        context.Logger.LogMessage("Found texture: {0}. Packing into xnb", imageFile);
                        var textureReference = new ExternalReference <TextureContent>(imageFile);
                        var texture          =
                            context.BuildAndLoadAsset <TextureContent, TextureContent>(textureReference,
                                                                                       "TextureProcessor");

                        var textureContent = new Texture2DContent();
                        textureContent.Mipmaps.Add(texture.Faces[0][0]);

                        if (CompressTextures)
                        {
                            textureContent.ConvertBitmapType(typeof(Dxt5BitmapContent));
                        }

                        result.Textures.Add(textureContent);
                    }
                    else
                    {
                        var textureFilename = PathHelper.MakeRelativePath(Directory.GetCurrentDirectory(), imageFile)
                                              .Replace("Content/", string.Empty);
                        textureFilename = Path.ChangeExtension(textureFilename, null);
                        context.Logger.LogMessage(
                            "Not writing texture but it is expected to exist and be processed: {0}", textureFilename);
                        result.TextureNames.Add(textureFilename);
                        result.TextureOrigins.Add(new Vector2(fontPage.X, fontPage.Y));
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                context.Logger.LogMessage("Error {0}", ex);
                throw;
            }
        }
Example #2
0
        public override SpriteFontContent Process(FontDescription input, ContentProcessorContext context)
        {
            // Fallback if we aren't buiding for iOS.
            var platform = ContentHelper.GetMonoGamePlatform();

            if (platform != MonoGamePlatform.iOS)
            {
                return(base.Process(input, context));
            }

            SpriteFontContent content      = base.Process(input, context);
            FieldInfo         TextureField = typeof(SpriteFontContent).GetField("texture", BindingFlags.Instance | BindingFlags.NonPublic);
            Texture2DContent  texture      = (Texture2DContent)TextureField.GetValue(content);

            // TODO: This is a very lame way of doing this as we're getting compression artifacts twice, but is the quickest way to get
            // Compressed fonts up and running. The SpriteFontContent/Processor contains a ton
            // of sealed/internal classes riddled with private fields, so overriding CompressFontTexture
            // or even Process is tricky. This works for now, but should be replaced when the content pipeline
            // moves a bit further

            var texWidth  = ContentHelper.NextPOT(texture.Faces[0][0].Width);
            var texHeight = ContentHelper.NextPOT(texture.Faces[0][0].Height);

            // Resize to square, power of two if necessary.
            if (texWidth != texHeight || texture.Faces[0][0].Width != texture.Faces[0][0].Height || texWidth != texture.Faces[0][0].Width || texHeight != texture.Faces[0][0].Height)
            {
                texHeight = texWidth = Math.Max(texHeight, texWidth);
                var resizedBitmap = (BitmapContent)Activator.CreateInstance(typeof(PixelBitmapContent <Color>), new object[] { texWidth, texHeight });
                var textureRegion = new Rectangle(0, 0, texture.Faces[0][0].Width, texture.Faces[0][0].Height);
                BitmapContent.Copy(texture.Faces[0][0], textureRegion, resizedBitmap, textureRegion);

                texture.Faces[0].Clear();
                texture.Faces[0].Add(resizedBitmap);

                context.Logger.LogImportantMessage(string.Format("Resized font texture {0} to {1}x{2}", input.Name, resizedBitmap.Width, resizedBitmap.Height));
            }
            else
            {
                texture.ConvertBitmapType(typeof(PixelBitmapContent <Color>));
            }

            MGTextureProcessor.ConvertToPVRTC(texture, 1, true, MGCompressionMode.PVRTCFourBitsPerPixel);

            return(content);
        }
Example #3
0
        public override BitmapFontProcessorResult Process(BitmapFontFile bitmapFontFile, ContentProcessorContext context)
        {
            try
            {
                context.Logger.LogMessage("Processing BMFont, Kerning pairs: {0}", bitmapFontFile.kernings.Count);
                var result = new BitmapFontProcessorResult(bitmapFontFile);

                foreach (var fontPage in bitmapFontFile.pages)
                {
                    var assetName = Path.GetFileNameWithoutExtension(fontPage.file);
                    context.Logger.LogMessage("Expecting texture asset: {0}", assetName);

                    // find our texture so we can embed it in the xnb asset
                    var imageFiles = Directory.GetFiles(".", fontPage.file, SearchOption.AllDirectories);
                    if (imageFiles.Length == 0)
                    {
                        throw new Exception(string.Format("Could not locate font atlas file {0} in any subdirectory of {1}", fontPage.file, Directory.GetCurrentDirectory()));
                    }

                    context.Logger.LogMessage("Found texture: {0}", imageFiles[0]);
                    var textureReference = new ExternalReference <TextureContent>(imageFiles[0]);
                    var texture          = context.BuildAndLoadAsset <TextureContent, TextureContent>(textureReference, "TextureProcessor");

                    var textureContent = new Texture2DContent();
                    textureContent.Mipmaps.Add(texture.Faces[0][0]);

                    if (_compress)
                    {
                        textureContent.ConvertBitmapType(typeof(Dxt5BitmapContent));
                    }

                    result.textures.Add(textureContent);
                }

                return(result);
            }
            catch (Exception ex)
            {
                context.Logger.LogMessage("Error {0}", ex);
                throw;
            }
        }
        public override SpriteFontContent Process(Texture2DContent input, ContentProcessorContext context)
        {
            // Fallback if we aren't buiding for iOS.
            var platform = ContentHelper.GetMonoGamePlatform();

            if (platform != MonoGamePlatform.iOS)
            {
                return(base.Process(input, context));
            }

            SpriteFontContent content = base.Process(input, context);

            // TODO: This is a very lame way of doing this as we're getting compression artifacts twice, but is the quickest way to get
            // Compressed fonts up and running. The SpriteFontContent/Processor contains a ton
            // of sealed/internal classes riddled with private fields, so overriding CompressFontTexture
            // or even Process is tricky. This works for now, but should be replaced when the content pipeline
            // moves a bit further

            var texWidth  = input.Faces[0][0].Width;
            var texHeight = input.Faces[0][0].Height;

            // Resize to square, power of two if necessary.
            if (texWidth != texHeight)
            {
                texHeight = texWidth = Math.Max(texHeight, texWidth);
                var resizedBitmap = (BitmapContent)Activator.CreateInstance(typeof(PixelBitmapContent <Color>), new object[] { texWidth, texHeight });
                var textureRegion = new Rectangle(0, 0, input.Faces[0][0].Width, input.Faces[0][0].Height);
                BitmapContent.Copy(input.Faces[0][0], textureRegion, resizedBitmap, textureRegion);

                input.Faces[0].Clear();
                input.Faces[0].Add(resizedBitmap);
            }
            else
            {
                input.ConvertBitmapType(typeof(PixelBitmapContent <Color>));
            }

            MGTextureProcessor.ConvertToPVRTC(input, 1, true, MGCompressionMode.PVRTCFourBitsPerPixel);

            return(content);
        }
Example #5
0
        public bool AddOutline(Texture2DContent tex)
        {
            SurfaceFormat fmt;

            if (!tex.Mipmaps[0].TryGetFormat(out fmt))
            {
                return(false);
            }
            if (fmt != SurfaceFormat.Color)
            {
                context_.Logger.LogImportantMessage("Converting from format {0} to Color.", fmt.ToString());
                tex.ConvertBitmapType(typeof(PixelBitmapContent <Color>));
            }
            byte[] data = tex.Mipmaps[0].GetPixelData();
            int    n    = AddOutline(data, tex.Mipmaps[0].Width, tex.Mipmaps[0].Height);

            tex.Mipmaps[0].SetPixelData(data);
            context_.Logger.LogMessage("Converting bitmap {0}x{1} touches {2} pixels.", tex.Mipmaps[0].Width, tex.Mipmaps[0].Height, n);
            tex.GenerateMipmaps(true);
            return(true);
        }