Source:
private void render(Iterable<EntityRef> floatingTextEntities) { glDisable(GL_DEPTH_TEST); Vector3f cameraPosition = camera.getPosition(); for (EntityRef entity : floatingTextEntities) { LocationComponent location = entity.getComponent(LocationComponent.class); if (location == null) { continue; } Vector3f worldPos = location.getWorldPosition(); if (!worldProvider.isBlockRelevant(worldPos)) { continue; } FloatingTextComponent floatingText = entity.getComponent(FloatingTextComponent.class); List<String> text = Arrays.asList(floatingText.text.split("\n")); Color baseColor = floatingText.textColor; Color shadowColor = floatingText.textShadowColor; boolean underline = false; String longest = ""; for (String s : text) { if (s.length() > longest.length()) longest = s; } int textWidth = font.getWidth(longest); FontMeshBuilder meshBuilder = new FontMeshBuilder(underlineMaterial); Map<Material, Mesh> meshMap = entityMeshCache.get(entity); if (meshMap == null) { meshMap = meshBuilder .createTextMesh(font, text, textWidth, HorizontalAlign.CENTER, baseColor, shadowColor, underline); entityMeshCache.put(entity, meshMap); } glPushMatrix(); float scale = METER_PER_PIXEL * floatingText.scale; glTranslated(worldPos.x - cameraPosition.x, worldPos.y - cameraPosition.y, worldPos.z - cameraPosition.z); OpenGLUtils.applyBillboardOrientation(); glScaled(scale, -scale, scale); glTranslated(-textWidth / 2.0, 0.0, 0.0); for (Map.Entry<Material, Mesh> meshMapEntry : meshMap.entrySet()) { Mesh mesh = meshMapEntry.getValue(); Material material = meshMapEntry.getKey(); material.enable(); material.bindTextures(); material.setFloat4("croppingBoundaries", Float.MIN_VALUE, Float.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE); material.setFloat2("offset", 0.0f, 0.0f); material.setFloat("alpha", 1.0f); mesh.render(); } glPopMatrix(); } glEnable(GL_DEPTH_TEST); }

Target:
private void render(Iterable<EntityRef> floatingTextEntities) { glDisable(GL_DEPTH_TEST); Vector3f cameraPosition = camera.getPosition(); for (EntityRef entity : floatingTextEntities) { LocationComponent location = entity.getComponent(LocationComponent.class); if (location == null) { continue; } Vector3f worldPos = location.getWorldPosition(); if (!worldProvider.isBlockRelevant(worldPos)) { continue; } FloatingTextComponent floatingText = entity.getComponent(FloatingTextComponent.class); String[] linesOfText = floatingText.text.split("\n"); Color baseColor = floatingText.textColor; Color shadowColor = floatingText.textShadowColor; boolean underline = false; int textWidth = 0; for (String singleLine : linesOfText) { if (font.getWidth(singleLine) > textWidth) textWidth = font.getWidth(singleLine); } FontMeshBuilder meshBuilder = new FontMeshBuilder(underlineMaterial); Map<Material, Mesh> meshMap = entityMeshCache.get(entity); if (meshMap == null) { meshMap = meshBuilder .createTextMesh(font, Arrays.asList(linesOfText), textWidth, HorizontalAlign.CENTER, baseColor, shadowColor, underline); entityMeshCache.put(entity, meshMap); } glPushMatrix(); float scale = METER_PER_PIXEL * floatingText.scale; glTranslated(worldPos.x - cameraPosition.x, worldPos.y - cameraPosition.y, worldPos.z - cameraPosition.z); OpenGLUtils.applyBillboardOrientation(); glScaled(scale, -scale, scale); glTranslated(-textWidth / 2.0, 0.0, 0.0); for (Map.Entry<Material, Mesh> meshMapEntry : meshMap.entrySet()) { Mesh mesh = meshMapEntry.getValue(); Material material = meshMapEntry.getKey(); material.enable(); material.bindTextures(); material.setFloat4("croppingBoundaries", Float.MIN_VALUE, Float.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE); material.setFloat2("offset", 0.0f, 0.0f); material.setFloat("alpha", 1.0f); mesh.render(); } glPopMatrix(); } glEnable(GL_DEPTH_TEST); }