Reputation: 19344
Having little experience in Opengl es (or opengl) I was hoping somebody could help me out with this.
I'm creating an opengl es application and I would like to be able to dynamically create the text of my buttons etc.
The 2 obvious reasons for that are:
-to be modular (changing the text quickly without using photoshop)
-to be able to add languages later down the line
can anybody point me to a tutorial or at least give me the basic steps/functions to:
create textures form text
load custom fonts to display text textures with the chosen custom font
indicate if I can use this for loading Kanji ?
Best regards
Jason Rogers
Upvotes: 2
Views: 2296
Reputation: 2905
In our app we've decided to draw HUD (buttons, icons, text) using android XML layout instead of OpenGL ES.
There were severals reasons for that:
To do it you just need to add GlSurfaceView
as a child view to your main view.
Upvotes: 2
Reputation: 2049
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:
Paint
object that will describe the appearance of the text.Paint.setTypeFace()
), size (Paint.setTextSize()
), color, etc.Paint.getTextBounds()
and the string you want to draw.Bitmap.createBitmap()
, make sure it has an alpha component.new Canvas(bitmap)
.Canvas.drawText()
, using the paint object you created and the string you want.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.GLUtils.texImage2D()
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.
Upvotes: 3