Package panamagl.renderers.text
Class OrientedTextRenderer
java.lang.Object
panamagl.renderers.text.OrientedTextRenderer
public class OrientedTextRenderer
extends Object
implements panamagl.renderers.text.TextRenderer<Font,Color>
Render text drawn with AWT in a texture mapped on a quad in screen coordinates, as JOGL's
TextRenderer does. Hence any AWT font can be used, text can be rotated, and text
partially out of the viewport is partially drawn (unlike BasicTextRenderer which draws
pixels at a raster position).
On HiDPI screens, set the pixel scale to draw glyphs with a font
scaled accordingly, as JOGL does with the surface scale. Text widths given by
getTextWidth(Font, String) remain in logical pixels.
This renderer only relies on AWT and OpenGL 1.x (no GLUT) and requires a context supporting the
fixed pipeline (e.g. a compatibility profile).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA text drawn in an image, with metrics in physical pixels. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateTextImage(Font font, String text, Color color) Draw a text with AWT in an image, with a font scaled by thepixel scale.voiddraw(panamagl.opengl.GL gl, Font font, String text, float x, float y, float z, Color color, float rotation) Draw a text with the left of its baseline at the given position, in pixels from the bottom left corner of the current viewport.voiddrawAtRasterPosition(panamagl.opengl.GL gl, Font font, String text, Color color) Draw a text at the current raster position, as GLUT bitmap strings : the raster position is the left of the text baseline and is moved to the end of the text once drawn.voiddrawImage(panamagl.opengl.GL gl, BufferedImage image, float x, float y) Draw an image, without scaling, with its bottom left corner at the given position in pixels from the bottom left corner of the current viewport.protected voiddrawTexture(panamagl.opengl.GL gl, BufferedImage image, float x, float y, float rotationD, float x0, float y0, int viewportWidth, int viewportHeight) Draw an image as a texture mapped on a quad in screen coordinates.floatintgetTextWidth(Font font, String text) Width of a text in logical pixels, i.e.protected int[]getViewport(panamagl.opengl.GL gl) booleanprotected FontMetricsprotected FontvoidsetAntialiasing(boolean antialiasing) voidsetPixelScale(float pixelScale) Scale applied to fonts to draw glyphs, e.g.protected static MemorySegmenttoRGBA(Arena arena, BufferedImage image) Convert an AWT image to RGBA pixels, bottom row first as expected by OpenGL.
-
Field Details
-
pixelScale
protected float pixelScale -
antialiasing
protected boolean antialiasing
-
-
Constructor Details
-
OrientedTextRenderer
public OrientedTextRenderer()
-
-
Method Details
-
draw
-
drawAtRasterPosition
-
drawImage
Draw an image, without scaling, with its bottom left corner at the given position in pixels from the bottom left corner of the current viewport. The image is drawn as a textured quad, so that it can be partially out of the viewport. -
drawTexture
protected void drawTexture(panamagl.opengl.GL gl, BufferedImage image, float x, float y, float rotationD, float x0, float y0, int viewportWidth, int viewportHeight) Draw an image as a texture mapped on a quad in screen coordinates.- Parameters:
x- , y the position where the quad origin is translated, in pixels.rotationD- a counter-clockwise rotation around the quad origin, in degrees.x0- , y0 the position of the bottom left corner of the quad, relative to its origin.
-
createTextImage
Draw a text with AWT in an image, with a font scaled by thepixel scale. The dimensions of the returned image are hence in physical pixels. -
getTextWidth
Width of a text in logical pixels, i.e. not scaled by thegetPixelScale(). -
scale
-
metrics
-
getViewport
protected int[] getViewport(panamagl.opengl.GL gl) -
toRGBA
Convert an AWT image to RGBA pixels, bottom row first as expected by OpenGL. -
setPixelScale
public void setPixelScale(float pixelScale) Scale applied to fonts to draw glyphs, e.g. 2 on a HiDPI screen. Non positive or undefined values are replaced by 1. -
getPixelScale
public float getPixelScale() -
isAntialiasing
public boolean isAntialiasing() -
setAntialiasing
public void setAntialiasing(boolean antialiasing)
-