开发者

Render Text onto a rectangle

I noticed that the TextRenderer dra开发者_JAVA技巧w3D class takes a scale factor but I'd like to be able to render a string into an arbitrary rectangle. I think could write a class to do this but I wondered if there is an easier way using the utilities in JOGL.


A very good and universal way to put anything (text, image,...) into an arbitrary rectangle is to create BufferedImage with the content you want. FYI: use Bufferedimage.createGraphics() to get the Graphics2D Object from the BufferedImage. With this Graphics2D object you can do then standard java 2D drawing. Also String writing with any Font and Size and Color you like:

Graphics2D.drawString(String str, int x, int y)

Once the BufferedImage looks like you want you can get a "standard" Texture Object from it:

texture = AWTTextureIO.newTexture(GLProfile glp, BufferedImage image, boolean mipmap)

this texture you can then apply to any arbitrary rectangle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜