Hi buddy,
I don't know if this is the best way, and I haven't done it before... but here's how I'd do it:
- Create a
Paint
object that will describe the appearance of the text.
- Set the required parameters for font (
Paint.setTypeFace()
), size (Paint.setTextSize()
), color, etc.
- Measure the size of the required bitmap using
Paint.getTextBounds()
and the string you want to draw.
- Create a new bitmap of that size using
Bitmap.createBitmap()
, make sure it has an alpha component.
- Create a canvas using the bitmap you created to draw into using
new Canvas(bitmap)
.
- Draw the text into the bitmap:
Canvas.drawText()
, using the paint object you created and the string you want.
- Scale the bitmap using
Bitmap.createScaledBitmap()
to be the next larger size as a power of 2 in x and y. I have a handy function (round up to power of 2) for that if you need it.
- Bind, set texture parameters and load the bitmap to gl using
GLUtils.texImage2D()
- Draw a quad/sprite using the texture; scale appropriately using the measured text dimensions.
Of course, if you want to do the button background/button text compositing beforehand, you can use the canvas to draw into the background instead.
I presume that whatever fonts android supports, Canvas.drawText() will support using the appropriate Paint settings, the same should go for string characters (Kanji or other) that are input to it. It will be easy to find out by experimenting once you get the method above up and running.
Hope this was somewhat helpful. Cheers, Aert.