private void display(GLAutoDrawable drawable, Point p) { if (renderer == null) { renderer = new TextRenderer(new Font("SansSerif", Font.PLAIN, 10), true, true); } Neuron[] n = cells[p.x][p.y]; renderer.begin3DRendering(); renderer.setColor(0, 0, 1, 0.8f); float s1 = n[0].getState(), s2 = n[1].getState(); float avg = (s1 + s2) / 2; String s = String.format("%5.3f", avg); Rectangle2D rect = renderer.getBounds(s); renderer.draw3D(s, p.x, p.y, 0, .7f); // TODO fix string n lines renderer.end3DRendering(); GL gl = drawable.getGL(); gl.glRectf(p.x, p.y - 2, p.x + (float) rect.getWidth() * avg * .7f, p.y - 1); }
// Draw the scale label private void drawLabel(DrawContext dc, String text, Vec4 screenPoint) { TextRenderer textRenderer = OGLTextRenderer.getOrCreateTextRenderer(dc.getTextRendererCache(), this.defaultFont); Rectangle2D nameBound = textRenderer.getBounds(text); int x = (int) (screenPoint.x() - nameBound.getWidth() / 2d); int y = (int) screenPoint.y(); textRenderer.begin3DRendering(); textRenderer.setColor(this.getBackgroundColor(this.color)); textRenderer.draw(text, x + 1, y - 1); textRenderer.setColor(this.color); textRenderer.draw(text, x, y); textRenderer.end3DRendering(); }
public void drawText(String text, double x, double y) { if (textRenderer == null) throw new RuntimeException(); // gl.glDisable(GL.GL_DEPTH_TEST); // Uses 3D rendering so it can take advantage of the glTranslate // function textRenderer.begin3DRendering(); textRenderer.setColor(currentColor); textRenderer.draw3D( text, (float) (scaleX * (brushPos.getX() + x)), (float) (scaleY * (brushPos.getY() + y)), 0, 1); textRenderer.end3DRendering(); textRenderer.flush(); // gl.glEnable(GL.GL_DEPTH_TEST); }
/** * Draw the label's text. This method sets up the text renderer, and then calls {@link * #doDrawText(TextRenderer) doDrawText} to actually draw the text. * * @param dc Current draw context. * @param textRenderer Text renderer. */ protected void drawText(DrawContext dc, TextRenderer textRenderer) { GL gl = dc.getGL(); Angle heading = this.rotation; double headingDegrees; if (heading != null) headingDegrees = heading.degrees; else headingDegrees = 0; boolean matrixPushed = false; try { int x = this.screenPoint.x; int y = this.screenPoint.y; if (headingDegrees != 0) { gl.glPushMatrix(); matrixPushed = true; gl.glTranslated(x, y, 0); gl.glRotated(headingDegrees, 0, 0, 1); gl.glTranslated(-x, -y, 0); } if (this.isDrawInterior()) this.drawInterior(dc); textRenderer.begin3DRendering(); try { this.doDrawText(textRenderer); // Draw other labels that share the same text renderer configuration, if possible. if (this.isEnableBatchRendering()) this.drawBatchedText(dc, textRenderer); } finally { textRenderer.end3DRendering(); } } finally { if (matrixPushed) { gl.glPopMatrix(); } } }
public void beginRendering() { renderer.begin3DRendering(); }