Has anyone here used jME-TTF to render blurred text?
I’m trying to write a test case for blurred text. I started with the code fragment at https://1337atr.weebly.com/jttf_blurtext.html, but so far all I get out of bt.render()
is a solid blue texture.
Here’s my code so far:
import com.atr.jme.font.TrueTypeFont;
import com.atr.jme.font.asset.TrueTypeKey;
import com.atr.jme.font.asset.TrueTypeKeyMesh;
import com.atr.jme.font.asset.TrueTypeLoader;
import com.atr.jme.font.util.BlurText;
import com.atr.jme.font.util.StringContainer;
import com.atr.jme.font.util.Style;
import com.jme3.app.SimpleApplication;
import com.jme3.font.Rectangle;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.shape.Quad;
import com.jme3.texture.Texture;
public class TestMeshBlur extends SimpleApplication {
public static void main(String[] args) {
TestMeshBlur app = new TestMeshBlur();
app.start();
}
@Override
public void simpleInitApp() {
assetManager.registerLoader(TrueTypeLoader.class, "ttf");
int pointSize = 48;
int dpi = 72;
boolean useWeakCache = true;
TrueTypeKey key = new TrueTypeKeyMesh(Constants.FONT, Style.Plain,
pointSize, dpi, useWeakCache);
TrueTypeFont font = assetManager.loadAsset(key);
int kerning = 0;
Rectangle textBox = new Rectangle(0f, 0f, 256f, 256f);
StringContainer container = new StringContainer(font,
Constants.HELLO_WORLD, kerning, textBox);
int numPasses = 5;
float passOffset = 1f;
float intensity = 2.5f;
ColorRGBA blurColor = new ColorRGBA(0.02f, 0.4f, 1f, 0f); // light blue
BlurText bt = new BlurText(assetManager, renderManager, container,
numPasses, passOffset, intensity, blurColor);
Texture blurredTexture = bt.render();
Material unshadedMaterial = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
unshadedMaterial.setTexture("ColorMap", blurredTexture);
float quadWidth = 256f;
float quadHeight = 256f;
Mesh quadMesh = new Quad(quadWidth, quadHeight);
Geometry quad = new Geometry("quad", quadMesh);
quad.setMaterial(unshadedMaterial);
float leftX = (cam.getWidth() - quadWidth) / 2;
float bottomY = (cam.getHeight() - quadHeight) / 2;
quad.move(leftX, bottomY, 0f);
guiNode.attachChild(quad);
}
}