I want to implement pixmap fonts in unity. The glyphs are specified in a png file and the file is loaded as a Texture2D.
I need some way to copy a small rectangle of the pixmap image containing a single character to a given position on the screen. For that sake, I thought I could use
Graphics.DrawTexture (screenRect : Rect, texture : Texture, sourceRect : Rect, leftBorder : int, rightBorder : int, topBorder : int, bottomBorder : int, mat : Material = null) : void
but the documentation does not explain what the different parameters are for, and I could not figure them out by testing. When calling (boo code follows):
Graphics.DrawTexture(Rect(0,0,40,40),texture,Rect(0,0,40,40),0,0,0,0,null)
I would expect the top-left 40x40 pixels of my image to be copied to the top-left 40x40 pixels of the screen. However, all I get is flat gray where the pixels should appear.
Does somebody know how Graphics.DrawTexture is intended to work? Is there another way to blit a rectangle from a texture onto the screen?
I know the texture image is well imported because it looks fine when using this other version of DrawTexture, which does not allow to specify a rectangle within the texture:
Graphics.DrawTexture (screenRect : Rect, texture : Texture, leftBorder : int, rightBorder : int, topBorder : int, bottomBorder : int, mat : Material = null) : void
I thought also of creating one texture for each glyph and drawing that instead. But I think that's a less natural solution.