com.jme3.font.BitmapFont Java Examples

The following examples show how to use com.jme3.font.BitmapFont. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JmeBitmapText.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected Sheet createSheet() {
    //TODO: multithreading..
    Sheet sheet = super.createSheet();
    Sheet.Set set = Sheet.createPropertiesSet();
    set.setDisplayName("BitmapText");
    set.setName(BitmapText.class.getName());
    BitmapText obj = geom;//getLookup().lookup(Spatial.class);
    if (obj == null) {
        return sheet;
    }

    set.put(makeProperty(obj, String.class, "getText", "setText", "Text"));
    set.put(makeProperty(obj, ColorRGBA.class, "getColor", "setColor", "Color"));
    set.put(makeProperty(obj, BitmapFont.class, "getFont", "Font"));

    sheet.put(set);
    return sheet;

}
 
Example #2
Source File: StatsView.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public StatsView(String name, AssetManager manager, Statistics stats){
    super(name);

    setQueueBucket(Bucket.Gui);
    setCullHint(CullHint.Never);

    statistics = stats;

    statLabels = statistics.getLabels();
    statData = new int[statLabels.length];
    labels = new BitmapText[statLabels.length];

    BitmapFont font = manager.loadFont("Interface/Fonts/Console.fnt");
    for (int i = 0; i < labels.length; i++){
        labels[i] = new BitmapText(font);
        labels[i].setLocalTranslation(0, labels[i].getLineHeight() * (i+1), 0);
        attachChild(labels[i]);
    }

    addControl(this);
}
 
Example #3
Source File: TestBitmapFont.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    inputManager.addMapping("WordWrap", new KeyTrigger(KeyInput.KEY_TAB));
    inputManager.addListener(keyListener, "WordWrap");
    inputManager.addRawInputListener(textListener);
    
    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    txt = new BitmapText(fnt, false);
    txt.setBox(new Rectangle(0, 0, settings.getWidth(), settings.getHeight()));
    txt.setSize(fnt.getPreferredSize() * 2f);
    txt.setText(txtB);
    txt.setLocalTranslation(0, txt.getHeight(), 0);
    guiNode.attachChild(txt);

    txt2 = new BitmapText(fnt, false);
    txt2.setSize(fnt.getPreferredSize() * 1.2f);
    txt2.setText("Text without restriction. \nText without restriction. Text without restriction. Text without restriction");
    txt2.setLocalTranslation(0, txt2.getHeight(), 0);
    guiNode.attachChild(txt2);
    
    txt3 = new BitmapText(fnt, false);
    txt3.setBox(new Rectangle(0, 0, settings.getWidth(), 0));
    txt3.setText("Press Tab to toggle word-wrap. type text and enter to input text");
    txt3.setLocalTranslation(0, settings.getHeight()/2, 0);
    guiNode.attachChild(txt3);
}
 
Example #4
Source File: TestBitmapText3D.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Quad q = new Quad(6, 3);
    Geometry g = new Geometry("quad", q);
    g.setLocalTranslation(0, -3, -0.0001f);
    g.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    rootNode.attachChild(g);

    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText txt = new BitmapText(fnt, false);
    txt.setBox(new Rectangle(0, 0, 6, 3));
    txt.setQueueBucket(Bucket.Transparent);
    txt.setSize( 0.5f );
    txt.setText(txtB);
    rootNode.attachChild(txt);
}
 
Example #5
Source File: StatsView.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public StatsView(String name, AssetManager manager, Statistics stats){
    super(name);

    setQueueBucket(Bucket.Gui);
    setCullHint(CullHint.Never);

    statistics = stats;
    statistics.setEnabled(enabled);

    statLabels = statistics.getLabels();
    statData = new int[statLabels.length];

    BitmapFont font = manager.loadFont("Interface/Fonts/Console.fnt");
    statText = new BitmapText(font);
    statText.setLocalTranslation(0, statText.getLineHeight() * statLabels.length, 0);
    attachChild(statText);

    addControl(this);
}
 
Example #6
Source File: TestImageRaster.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void convertAndPutImage(Image image, float posX, float posY) {
    Texture tex = new Texture2D(image);
    tex.setMagFilter(MagFilter.Nearest);
    tex.setMinFilter(MinFilter.NearestNoMipMaps);
    tex.setAnisotropicFilter(16);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", tex);

    Quad q = new Quad(5, 5);
    Geometry g = new Geometry("quad", q);
    g.setLocalTranslation(posX, posY - 5, -0.0001f);
    g.setMaterial(mat);
    rootNode.attachChild(g);

    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText txt = new BitmapText(fnt);
    txt.setBox(new Rectangle(0, 0, 5, 5));
    txt.setQueueBucket(RenderQueue.Bucket.Transparent);
    txt.setSize(0.5f);
    txt.setText(image.getFormat().name());
    txt.setLocalTranslation(posX, posY, 0);
    rootNode.attachChild(txt);
}
 
Example #7
Source File: TestBitmapFont.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    inputManager.addMapping("WordWrap", new KeyTrigger(KeyInput.KEY_TAB));
    inputManager.addListener(keyListener, "WordWrap");
    inputManager.addRawInputListener(textListener);

    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    txt = new BitmapText(fnt, false);
    txt.setBox(new Rectangle(0, 0, settings.getWidth(), settings.getHeight()));
    txt.setSize(fnt.getPreferredSize() * 2f);
    txt.setText(txtB);
    txt.setLocalTranslation(0, txt.getHeight(), 0);
    guiNode.attachChild(txt);

    txt2 = new BitmapText(fnt, false);
    txt2.setSize(fnt.getPreferredSize() * 1.2f);
    txt2.setText("Text without restriction. \nText without restriction. Text without restriction. Text without restriction");
    txt2.setLocalTranslation(0, txt2.getHeight(), 0);
    guiNode.attachChild(txt2);

    txt3 = new BitmapText(fnt, false);
    txt3.setBox(new Rectangle(0, 0, settings.getWidth(), 0));
    txt3.setText("Press Tab to toggle word-wrap. type text and enter to input text");
    txt3.setLocalTranslation(0, settings.getHeight()/2, 0);
    guiNode.attachChild(txt3);
}
 
Example #8
Source File: TestBitmapText3D.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Quad q = new Quad(6, 3);
    Geometry g = new Geometry("quad", q);
    g.setLocalTranslation(0, -3, -0.0001f);
    g.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    rootNode.attachChild(g);

    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText txt = new BitmapText(fnt, false);
    txt.setBox(new Rectangle(0, 0, 6, 3));
    txt.setQueueBucket(Bucket.Transparent);
    txt.setSize( 0.5f );
    txt.setText(txtB);
    rootNode.attachChild(txt);
}
 
Example #9
Source File: TestObjGroupsLoading.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {

    // load scene with following structure:
    // Chair 1 (just mesh without name) and named groups: Chair 2, Pillow 2, Podium
    Spatial scene = assetManager.loadModel(new ModelKey("OBJLoaderTest/TwoChairs.obj"));
    // add light to make it visible
    scene.addLight(new AmbientLight(ColorRGBA.White));
    // attach scene to the root
    rootNode.attachChild(scene);
    
    // configure camera for best scene viewing
    cam.setLocation(new Vector3f(-3, 4, 3));
    cam.lookAtDirection(new Vector3f(0, -0.5f, -1), Vector3f.UNIT_Y);
    flyCam.setMoveSpeed(10);
    
    // create display to indicate pointed geometry name
    pointerDisplay = new BitmapText(guiFont);
    pointerDisplay.setBox(new Rectangle(0, settings.getHeight(), settings.getWidth(), settings.getHeight()/2));
    pointerDisplay.setAlignment(BitmapFont.Align.Center);
    pointerDisplay.setVerticalAlignment(BitmapFont.VAlign.Center);
    guiNode.attachChild(pointerDisplay);
    
    initCrossHairs();
}
 
Example #10
Source File: GuiGlobals.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  Goes through all of the font page materials and sets
 *  alpha test and alpha fall-off.
 */
public void fixFont( BitmapFont font ) {
    for( int i = 0; i < font.getPageSize(); i++ ) {
        Material m = font.getPage(i);
        // AlphaTest and AlphaFalloff are deprecated in favor of the material
        // parameter... in fact in current JME there are no-ops.
        //m.getAdditionalRenderState().setAlphaTest(true);
        //m.getAdditionalRenderState().setAlphaFallOff(0.1f);
        m.setFloat("AlphaDiscardThreshold", 0.1f);
    }
}
 
Example #11
Source File: SceneApplication.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void loadFPSText() {
    BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.fnt");

    fpsText = new BitmapText(font, false);
    fpsText.setSize(font.getCharSet().getRenderedSize());
    fpsText.setLocalTranslation(0, fpsText.getLineHeight(), 0);
    fpsText.setText("Frames per second");
    statsGuiNode.attachChild(fpsText);
}
 
Example #12
Source File: OpenRTSApplication.java    From OpenRTS with MIT License 5 votes vote down vote up
private void initTexts() {
	BitmapFont guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
	fpsText = new BitmapText(guiFont, false);
	fpsText.setLocalTranslation(0, fpsText.getLineHeight(), 0);
	fpsText.setText("Frames per second");
	guiNode.attachChild(fpsText);

	debugger = new MyDebugger(0, settings.getHeight(), assetManager.loadFont("Interface/Fonts/Console.fnt"));
	guiNode.attachChild(debugger.getNode());
}
 
Example #13
Source File: BitmapFontLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Object load(AssetInfo info) throws IOException {
    InputStream in = null;
    try {
        in = info.openStream();
        BitmapFont font = load(info.getManager(), info.getKey().getFolder(), in);
        return font;
    } finally {
        if (in != null){
            in.close();
        }
    }
}
 
Example #14
Source File: TestRtlBitmapText.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    // A right to left BitmapText
    BitmapText txt = new BitmapText(fnt, true);
    txt.setBox(new Rectangle(0, 0, 150, 0));
    txt.setLineWrapMode(LineWrapMode.Word);
    txt.setAlignment(BitmapFont.Align.Right);
    txt.setText(text);
    txt.setLocalTranslation(cam.getWidth() / 2, cam.getHeight() / 2, 0);
    guiNode.attachChild(txt);
}
 
Example #15
Source File: TestOpenCLLibraries.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    Context clContext = context.getOpenCLContext();
    if (clContext == null) {
        BitmapText txt = new BitmapText(fnt);
        txt.setText("No OpenCL Context created!\nSee output log for details.");
        txt.setLocalTranslation(5, settings.getHeight() - 5, 0);
        guiNode.attachChild(txt);
        return;
    }
    CommandQueue clQueue = clContext.createQueue(clContext.getDevices().get(0));
    
    StringBuilder str = new StringBuilder();
    str.append("OpenCL Context created:\n  Platform: ")
            .append(clContext.getDevices().get(0).getPlatform().getName())
            .append("\n  Devices: ").append(clContext.getDevices());
    str.append("\nTests:");
    str.append("\n  Random numbers: ").append(testRandom(clContext, clQueue));
    str.append("\n  Matrix3f: ").append(testMatrix3f(clContext, clQueue));
    str.append("\n  Matrix4f: ").append(testMatrix4f(clContext, clQueue));
    
    clQueue.release();
    
    BitmapText txt1 = new BitmapText(fnt);
    txt1.setText(str.toString());
    txt1.setLocalTranslation(5, settings.getHeight() - 5, 0);
    guiNode.attachChild(txt1);
    
    flyCam.setEnabled(false);
    inputManager.setCursorVisible(true);
}
 
Example #16
Source File: HelloOpenCL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    Context clContext = context.getOpenCLContext();
    if (clContext == null) {
        BitmapText txt = new BitmapText(fnt);
        txt.setText("No OpenCL Context created!\nSee output log for details.");
        txt.setLocalTranslation(5, settings.getHeight() - 5, 0);
        guiNode.attachChild(txt);
        return;
    }
    CommandQueue clQueue = clContext.createQueue();
    
    StringBuilder str = new StringBuilder();
    str.append("OpenCL Context created:\n  Platform: ")
            .append(clContext.getDevices().get(0).getPlatform().getName())
            .append("\n  Devices: ").append(clContext.getDevices());
    str.append("\nTests:");
    str.append("\n  Buffers: ").append(testBuffer(clContext, clQueue));
    str.append("\n  Kernel: ").append(testKernel(clContext, clQueue));
    str.append("\n  Images: ").append(testImages(clContext, clQueue));
    
    clQueue.release();
    
    BitmapText txt1 = new BitmapText(fnt);
    txt1.setText(str.toString());
    txt1.setLocalTranslation(5, settings.getHeight() - 5, 0);
    guiNode.attachChild(txt1);
    
    flyCam.setEnabled(false);
    inputManager.setCursorVisible(true);
}
 
Example #17
Source File: GuiGlobals.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void lightFont( BitmapFont font ) {
    Material[] pages = new Material[font.getPageSize()];
    for( int i = 0; i < pages.length; i++ ) {
        Material original = font.getPage(i);
        Material m = new Material(assets, "Common/MatDefs/Light/Lighting.j3md");
        m.setTexture("DiffuseMap", getTexture(original, "ColorMap"));
        pages[i] = m;
    }
    font.setPages(pages);
}
 
Example #18
Source File: ShadowTestUIManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ShadowTestUIManager(AssetManager assetManager,AbstractShadowRenderer plsr, AbstractShadowFilter plsf, 
        Node guiNode, InputManager inputManager, ViewPort viewPort) {
    this.plsr = plsr;
    this.plsf = plsf;
    this.viewPort = viewPort;
    BitmapFont guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    shadowTypeText = createText(guiFont);
    shadowCompareText = createText(guiFont);
    shadowFilterText = createText(guiFont);
    shadowIntensityText = createText(guiFont);

    shadowTypeText.setText(TYPE_TEXT + "Processor");
    shadowCompareText.setText(COMPARE_TEXT + (hardwareShadows ? "Hardware" : "Software"));
    shadowFilterText.setText(FILTERING_TEXT + plsr.getEdgeFilteringMode().toString());
    shadowIntensityText.setText(INTENSITY_TEXT + plsr.getShadowIntensity());

    shadowTypeText.setLocalTranslation(10, viewPort.getCamera().getHeight() - 20, 0);
    shadowCompareText.setLocalTranslation(10, viewPort.getCamera().getHeight() - 40, 0);
    shadowFilterText.setLocalTranslation(10, viewPort.getCamera().getHeight() - 60, 0);
    shadowIntensityText.setLocalTranslation(10, viewPort.getCamera().getHeight() - 80, 0);

    guiNode.attachChild(shadowTypeText);
    guiNode.attachChild(shadowCompareText);
    guiNode.attachChild(shadowFilterText);
    guiNode.attachChild(shadowIntensityText);

    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("changeFiltering", new KeyTrigger(KeyInput.KEY_F));
    inputManager.addMapping("ShadowUp", new KeyTrigger(KeyInput.KEY_T));
    inputManager.addMapping("ShadowDown", new KeyTrigger(KeyInput.KEY_G));
    inputManager.addMapping("ThicknessUp", new KeyTrigger(KeyInput.KEY_Y));
    inputManager.addMapping("ThicknessDown", new KeyTrigger(KeyInput.KEY_H));
    inputManager.addMapping("toggleHW", new KeyTrigger(KeyInput.KEY_RETURN));


    inputManager.addListener(this, "toggleHW", "toggle", "ShadowUp", "ShadowDown", "ThicknessUp", "ThicknessDown", "changeFiltering");

}
 
Example #19
Source File: Label.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Label( String s, boolean applyStyles, ElementId elementId, String style ) {
    super(false, elementId, style);

    // Set our layers
    getControl(GuiControl.class).setLayerOrder(LAYER_INSETS, 
                                               LAYER_BORDER, 
                                               LAYER_BACKGROUND,
                                               LAYER_ICON,
                                               LAYER_SHADOW_TEXT,
                                               LAYER_TEXT);

    // Retrieve the font before creation so that if the font is
    // customized by the style then we don't end up creating a
    // BitmapText object just to throw it away when a new font
    // is set right after.  It's a limitation of BitmapText that
    // can't have it's font changed post-creation.
    Styles styles = GuiGlobals.getInstance().getStyles();
    BitmapFont font = styles.getAttributes(elementId.getId(), style).get("font", BitmapFont.class);
    this.text = new TextComponent(s, font);
    text.setLayer(3);

    getControl(GuiControl.class).setComponent(LAYER_TEXT, text);

    if( applyStyles ) {
        styles.applyStyles(this, elementId, style);
    }
}
 
Example #20
Source File: TestMultipleApplications.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    clContext = context.getOpenCLContext();
    if (clContext == null) {
        LOG.severe("No OpenCL context found");
        stop();
        return;
    }
    Device device = clContext.getDevices().get(0);
    clQueue = clContext.createQueue(device);
    clQueue.register();
    
    String source = ""
            + "__kernel void Fill(__global float* vb, float v)\n"
            + "{\n"
            + "  int idx = get_global_id(0);\n"
            + "  vb[idx] = v;\n"
            + "}\n";
    Program program = clContext.createProgramFromSourceCode(source);
    program.build();
    program.register();
    kernel = program.createKernel("Fill");
    kernel.register();
    
    buffer = clContext.createBuffer(4);
    buffer.register();
    
    flyCam.setEnabled(false);
    inputManager.setCursorVisible(true);
    
    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    infoText = new BitmapText(fnt, false);
    //infoText.setBox(new Rectangle(0, 0, settings.getWidth(), settings.getHeight()));
    infoText.setText("Device: "+clContext.getDevices());
    infoText.setLocalTranslation(0, settings.getHeight(), 0);
    guiNode.attachChild(infoText);
    statusText = new BitmapText(fnt, false);
    //statusText.setBox(new Rectangle(0, 0, settings.getWidth(), settings.getHeight()));
    statusText.setText("Running");
    statusText.setLocalTranslation(0, settings.getHeight() - infoText.getHeight() - 2, 0);
    guiNode.attachChild(statusText);
}
 
Example #21
Source File: GuiGlobals.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public BitmapFont loadFont( String path ) {
    BitmapFont result = assets.loadFont(path);
    fixFont(result);
    return result;
}
 
Example #22
Source File: TextField.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected TextEntryComponent createTextEntryComponent( DocumentModel model ) {
    Styles styles = GuiGlobals.getInstance().getStyles();
    BitmapFont font = styles.getAttributes(getElementId().getId(), getStyle()).get("font", BitmapFont.class);
    return new TextEntryComponent(model, font);
}
 
Example #23
Source File: TextField.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@StyleAttribute("font")
public void setFont( BitmapFont f ) {
    text.setFont(f);
}
 
Example #24
Source File: TextField.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public BitmapFont getFont() {
    return text.getFont();
}
 
Example #25
Source File: MyDebugger.java    From OpenRTS with MIT License 4 votes vote down vote up
public MyDebugger(int x, int y, BitmapFont font) {
	bitmap = new BitmapText(font, false);
	bitmap.setLocalTranslation(x, y, 0);
	bitmap.setText("");
}
 
Example #26
Source File: DesktopAssetManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public BitmapFont loadFont(String name){
    return loadAsset(new AssetKey<BitmapFont>(name));
}
 
Example #27
Source File: Label.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setFont( BitmapFont font ) {
    text.setFont(font);
    if( shadow != null ) {
        shadow.setFont(font);
    }
}
 
Example #28
Source File: StatsAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public StatsAppState( Node guiNode, BitmapFont guiFont ) {
    this.guiNode = guiNode;
    this.guiFont = guiFont;
}
 
Example #29
Source File: Label.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public BitmapFont getFont() {
    return text.getFont();
}
 
Example #30
Source File: RenderFontJme.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public BitmapFont getFont() {
    return font;
}