Is there a way to load a SpriteFont without the use of content pipeline, similarly to loading Texture2D files? I do not really want to use the content pipeline at all, but I have not found any solution for SpriteFonts, and coding a custom text handler seems to be a big headache and tons of unnecessary work.
So something similar to this Texture2D loader:
public Texture2D TextureFromStreamForWP8(GraphicsDevice graphicsDevice, Stream stream)
{
Texture2D result = null;
var image = new BitmapImage();
image.SetSource(stream);
var bitmap = new WriteableBitmap(image);
var pixels = SetColorsFromPixelData(bitmap.Pixels);
Texture2D texture2D = new Texture2D(graphicsDevice,
bitmap.PixelWidth, bitmap.PixelHeight);
texture2D.SetData(pixels);
result = texture2D;
return result;
}
private Color[] SetColorsFromPixelData(int[] pixelData)
{
var Colors = new Color[pixelData.Length];
for (var i = 0; i < pixelData.Length; i++)
{
var packedColor = pixelData[i];
Color unpackedColor = new Color();
unpackedColor.B = (byte)(packedColor);
unpackedColor.G = (byte)(packedColor >> 8);
unpackedColor.R = (byte)(packedColor >> 16);
unpackedColor.A = (byte)(packedColor >> 24);
Colors[i] = unpackedColor;
}
return Colors;
}
}
Yesterday I spent another long hours to find an answer and I found how the drawtext method works, why do I need an xml and the likes… Well, it wont be a big headache to create a class that can handle text rendering from an image, so I think I will choose that. There are tools that can create an image from fonts, I will only need a container that will hold information about the x/y/width/height parameter of each character and a method that will accept a string and will draw the required portion of the image to the screen for each character in the string.
I still do not know how I will achieve the simulation of a keyboard (to give the user the ability of writing texts into controls), but that is another issue I need to solve.
Back in my XNA development days, I have used the FromFile method. There is a reason why I had to use this one, though I do not really know what it is, so I will re-check that FromStream method! Thanks for pointing on it!
I tried it now. I got an exception “method not implemented”. It seems in 3.2.2 for windows phone it is not implemented, so that was the reason I had to use a different approach.
I have installed Monogame through NuGet, if it matters, as the 3.2.2 installer has wrong dlls in the templates and there are issues with the orientation and with who knows what else.