/** 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)); }
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();
/** 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); }
@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(); } }
renderer.beginRendering(drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); renderer.draw(fpsText, x, y); renderer.endRendering();
/** * Draw txt at (x,y,z), with the text centered in the x-direction, facing * along the +z axis. * * @param gl * @param txt * @param x * @param y * @param z */ private void drawAxisText(GL2 gl, String txt, float x, float y, float z) { Rectangle2D dim = this.axisLabelRenderer.getBounds(txt); float width = (float) dim.getWidth() * SCALE_FACTOR; this.axisLabelRenderer.begin3DRendering(); this.axisLabelRenderer.draw3D(txt, x - width / 2, y, z, SCALE_FACTOR); this.axisLabelRenderer.end3DRendering(); } }
gl.glLoadIdentity(); gl.glOrtho(0,RSurfWidth,RSurfHeight,0,-1.0,1.0); tr.begin3DRendering(); tr.setColor(new java.awt.Color(argb, true)); gl.glEnable(gl.GL_SCISSOR_TEST); gl.glScissor(clipX, clipY, clipW, clipH); tr.draw3D(text.toString(), x, RSurfHeight-y, 0, 1); gl.glDisable(gl.GL_SCISSOR_TEST); tr.end3DRendering(); gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glPopMatrix(); fontMap.put(new Integer(fonthandle), new com.jogamp.opengl.util.awt.TextRenderer(fonty, true, false)); hasret[0] = 1; return fonthandle; ((com.jogamp.opengl.util.awt.TextRenderer)fontMap.remove(new Integer(handle))).dispose();
@Override public void drawSimpleText(GL gl, GLU glu, Camera cam, String s, Coord3d position, Color color) { renderer.begin3DRendering(); renderer.draw3D(s, position.x, position.y, position.z, 0.01f); renderer.flush(); renderer.end3DRendering(); }
@Override public void drawTextNode(NodeModel objectModel) { Node node = objectModel.getNode(); TextProperties textData = (TextProperties) node.getTextProperties(); if (textData != null) { String txt = textData.getText(); float width, height, posX, posY; if (txt == null || txt.isEmpty()) { return; } float sizeFactor = drawable.getGlobalScale() * textData.getSize() * model.sizeMode.getSizeFactor3d(model.nodeSizeFactor, objectModel); if (nodeRefresh || (objectModel.getTextWidth() == 0f && objectModel.getTextHeight() == 0f)) { Rectangle2D r = renderer.getBounds(txt); width = (float) (sizeFactor * r.getWidth()); height = (float) (sizeFactor * r.getHeight()); posX = node.x() + (float) width / -2f; posY = node.y() + (float) height / -2f; textData.setDimensions(width, height); } else { width = textData.getWidth(); height = textData.getHeight(); posX = node.x() + (float) width / -2f; posY = node.y() + (float) height / -2f; } model.colorMode.textNodeColor(this, objectModel); renderer.draw3D(txt, posX, posY, (float) node.z(), sizeFactor); } }
/** 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 draw(OTFOGLDrawer drawer) { if (textRenderer == null) { textRenderer = new TextRenderer(new Font("SansSerif", Font.PLAIN, 32), true, false); textRenderer.setColor(new Color(50, 50, 128, 255)); } GL2 gl = OTFGLAbstractDrawable.getGl(); if (vert != null) { drawPlanPolyLine(gl); } drawActivityTexts(); Point2D.Double agentCoords = drawer.getCurrentSceneGraph().getAgentPointLayer().getAgentCoords(this.agentId.toCharArray()); if (agentCoords != null) { // We know where the agent is, so we draw stuff around them. drawArrowFromAgentToTextLabel(agentCoords, gl); drawCircleAroundAgent(agentCoords, gl); drawLabelText(drawer, agentCoords); } }
private void displayLinkIds(Map<Coord, String> linkIds, GLAutoDrawable glAutoDrawable, Rect rect) { TextRenderer textRenderer = new TextRenderer(new Font("SansSerif", Font.PLAIN, 32), true, false); String testText = "0000000"; Rectangle2D test = textRenderer.getBounds(testText); Map<Coord, Boolean> xymap = new HashMap<>(); // Why is here a Map used, and not a Set? double xRaster = test.getWidth(), yRaster = test.getHeight();
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; } } }
@Override public void endRendering() { renderer.end3DRendering(); nodeRefresh = false; edgeRefresh = false; }
@Override public void beginRendering() { renderer.begin3DRendering(); float cameraLocation = drawable.getCameraLocation()[2]; if (cachedCameraLocationZ != cameraLocation && model.sizeMode == sizeModes[0]) { //Force refresh if camera location changed in fixed mode nodeRefresh = true; edgeRefresh = true; } cachedCameraLocationZ = cameraLocation; }
public void init() { this.font = new Font("SansSerif", Font.BOLD, 24); this.axisLabelRenderer = new TextRenderer(this.font); // FIXME don't work ?! this.axisLabelRenderer.setUseVertexArrays(false); }
@Override public void reinitRenderer() { renderer = new TextRenderer(renderer.getFont(), antialised, fractionalMetrics, null, shouldUseMipmapGeneration()); }
/** Begins rendering of 2D text in 3D with this {@link TextRenderer TextRenderer} into the current OpenGL drawable. Assumes the end user is responsible for setting up the modelview and projection matrices, and will render text using the {@link #draw3D draw3D} method. This method pushes some OpenGL state bits, binds and enables the internal OpenGL texture object, sets the texture environment mode to GL_MODULATE, and changes the current color to the last color set with this TextRenderer via {@link #setColor setColor}. @throws GLException If an OpenGL context is not current when this method is called */ public void begin3DRendering() throws GLException { beginRendering(false, 0, 0, false); }
/** Ends a render cycle with this {@link TextRenderer TextRenderer}. Restores the projection and modelview matrices as well as several OpenGL state bits. Should be paired with {@link #beginRendering beginRendering}. @throws GLException If an OpenGL context is not current when this method is called */ public void endRendering() throws GLException { endRendering(true); }
/** * Draw txt at (x,y,z), with the text centered in the x-direction, facing * along the +z axis. * * @param gl * @param txt * @param x * @param y * @param z */ private void drawAxisText(GL2 gl, String txt, double x, double y, double z) { Rectangle2D dim = this.axisLabelRenderer.getBounds(txt); float width = (float) dim.getWidth() * SCALE_FACTOR; this.axisLabelRenderer.begin3DRendering(); this.axisLabelRenderer.draw3D(txt, (float) x - width / 2, (float) y, (float) z, SCALE_FACTOR); this.axisLabelRenderer.end3DRendering(); } }