/** Changes the current color of this TextRenderer to the supplied one, where each component ranges from 0.0f - 1.0f. The alpha component, if used, does not need to be premultiplied into the color channels as described in the documentation for {@link Texture Texture}, although premultiplied colors are used internally. The default color is opaque white. @param r the red component of the new color @param g the green component of the new color @param b the blue component of the new color @param a the alpha component of the new color, 0.0f = completely transparent, 1.0f = completely opaque @throws GLException If an OpenGL context is not current when this method is called */ public void setColor(float r, float g, float b, float a) throws GLException { renderer.setColor(r, g, b, a); }
/** Creates a new Overlay with the given font and rendering attributes. An OpenGL context must be current at the time the constructor is called. @param drawable the drawable to render the text to @param font the font to use @param antialiased whether to use antialiased fonts @param useFractionalMetrics whether to use fractional font @throws GLException if an OpenGL context is not current when the constructor is called */ public Overlay(GLDrawable drawable, Font font, boolean antialiased, boolean useFractionalMetrics) throws GLException { this(drawable, new TextRenderer(font, antialiased, useFractionalMetrics)); }
@Override public void drawString(float x, float y, String s, Color3f color) { text.beginRendering(panel.getWidth(), panel.getHeight()); text.setColor(color.x, color.y, color.z, 1); text.draw(s, (int) x, panel.getHeight() - (int) y); text.endRendering(); } }
text = text.trim(); renderer.beginRendering(drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); Rectangle2D bounds = renderer.getBounds(text); int width = (int) bounds.getWidth(); int height = (int) bounds.getHeight(); renderer.draw(text, x, y); renderer.endRendering();
renderer.beginRendering(drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); renderer.draw(fpsText, x, y); renderer.endRendering();
private void recomputeFPSSize(float fps) { String fpsText; int magnitude; if (fps >= 10000) { fpsText = "10000.00"; magnitude = 5; } else if (fps >= 1000) { fpsText = "1000.00"; magnitude = 4; } else if (fps >= 100) { fpsText = "100.00"; magnitude = 3; } else if (fps >= 10) { fpsText = "10.00"; magnitude = 2; } else { fpsText = "9.00"; magnitude = 1; } if (magnitude > this.fpsMagnitude) { Rectangle2D bounds = renderer.getBounds("FPS: " + fpsText); fpsWidth = (int) bounds.getWidth(); fpsHeight = (int) bounds.getHeight(); fpsOffset = (int) (fpsHeight * 0.5f); this.fpsMagnitude = magnitude; } } }
/** Draws the supplied String at the desired location using the renderer's current color. See {@link #draw(CharSequence, int, int) draw(CharSequence, int, int)}. */ public void draw(final String str, final int x, final int y) throws GLException { draw3D(str, x, y, 0, 1); }
@Override public void endRendering() { renderer.end3DRendering(); nodeRefresh = false; edgeRefresh = false; }
/** Creates a {@link java.awt.Graphics2D Graphics2D} instance for rendering into the overlay. The returned object should be disposed of using the normal {@link java.awt.Graphics#dispose() Graphics.dispose()} method once it is no longer being used. @return a new {@link java.awt.Graphics2D Graphics2D} object for rendering into the backing store of this renderer */ public Graphics2D createGraphics() { // Validate the size of the renderer against the current size of // the drawable validateRenderer(); return renderer.createGraphics(); }
/** * Sets whether smoothing (i.e., GL_LINEAR filtering) is enabled * in the backing TextureRenderer of this TextRenderer. A few * graphics cards do not behave well when this is enabled, * resulting in fuzzy text. Defaults to true. */ public void setSmoothing(final boolean smoothing) { this.smoothing = smoothing; getBackingStore().setSmoothing(smoothing); }
/** Returns the size of the backing store of this renderer in a newly-allocated {@link java.awt.Dimension Dimension} object. @return the size of the backing store of this renderer */ public Dimension getSize() { return getSize(null); }
/** Sets the size of the backing store of this renderer. This may cause the OpenGL texture object associated with this renderer to be invalidated; it is not recommended to cache this texture object outside this class but to instead call {@link #getTexture getTexture} when it is needed. @param width the new width of the backing store of this renderer @param height the new height of the backing store of this renderer @throws GLException If an OpenGL context is not current when this method is called */ public void setSize(final int width, final int height) throws GLException { init(width, height); }
/** Causes the TextRenderer to flush any internal caches it may be maintaining and draw its rendering results to the screen. This should be called after each call to draw() if you are setting OpenGL state such as the modelview matrix between calls to draw(). */ public void flush() { flushGlyphPipeline(); }
@Override public Object clone() { final CharSequenceIterator iter = new CharSequenceIterator(mSequence); iter.mCurrentIndex = mCurrentIndex; return iter; }
/** Ends the OpenGL rendering process for the overlay. This is separated out so advanced applications can render independent pieces of the overlay to different portions of the drawable. @throws GLException If an OpenGL context is not current when this method is called */ public void endRendering() throws GLException { renderer.endOrthoRendering(); }
/** Draws the supplied String at the desired 3D location using the renderer's current color. See {@link #draw3D(CharSequence, float, float, float, float) draw3D(CharSequence, float, float, float, float)}. */ public void draw3D(final String str, final float x, final float y, final float z, final float scaleFactor) { internal_draw3D(str, x, y, z, scaleFactor); }
/** Creates a new FPSCounter with the given font and rendering attributes. An OpenGL context must be current at the time the constructor is called. @param drawable the drawable to render the text to @param font the font to use @param antialiased whether to use antialiased fonts @param useFractionalMetrics whether to use fractional font @throws GLException if an OpenGL context is not current when the constructor is called */ public FPSCounter(GLDrawable drawable, Font font, boolean antialiased, boolean useFractionalMetrics) throws GLException { this.drawable = drawable; renderer = new TextRenderer(font, antialiased, useFractionalMetrics); }
/** Changes the current color of this TextRenderer to the supplied one, where each component ranges from 0.0f - 1.0f. The alpha component, if used, does not need to be premultiplied into the color channels as described in the documentation for {@link Texture Texture}, although premultiplied colors are used internally. The default color is opaque white. @param r the red component of the new color @param g the green component of the new color @param b the blue component of the new color @param a the alpha component of the new color, 0.0f = completely transparent, 1.0f = completely opaque @throws GLException If an OpenGL context is not current when this method is called */ public void setColor(float r, float g, float b, float a) throws GLException { renderer.setColor(r, g, b, a); }
public JoglDebugDraw(JoglPanel panel) { this.panel = panel; text = new TextRenderer(new Font("Courier New", Font.PLAIN, 12)); mat[8] = 0; mat[9] = 0; mat[2] = 0; mat[6] = 0; mat[10] = 1; mat[14] = 0; mat[3] = 0; mat[7] = 0; mat[11] = 0; mat[15] = 1; }