Page support for BitmapText

Still another problem.



In BitmapFont, near the end of the file, instead of return maxLineWidth I had to put

[java]

return Math.max(maxLineWidth,lineWidth);

[/java]



Currently max is called only on newlines - for single-line case, which is quite common, it is returning zero. This happens for things with box already assigned, so error is not visible on freshly created text nodes.

Thank you!

Fixed in svn. rev. 6509

Fixed bug about multi-page BitmapText and

added setWordWrap() method to enable/disable word wrap functionality.

rev. 6533

NiftyGUI doesn’t support multi-page BitmapTexture.

So I made an fix to use multi-texture but it doesn’t work.

I don’t know what I missed. :cry:

Comments more than welcome.



[patch]

Index: src/niftygui/com/jme3/niftygui/RenderFontJme.java

===================================================================

— src/niftygui/com/jme3/niftygui/RenderFontJme.java (revision 6567)

+++ src/niftygui/com/jme3/niftygui/RenderFontJme.java (working copy)

@@ -43,7 +43,6 @@

private NiftyJmeDisplay display;

private BitmapFont font;

private BitmapText text;

  • private Texture texture;

    private float actualSize;



    /**

    @@ -53,7 +52,6 @@

    public RenderFontJme(String name, NiftyJmeDisplay display) {

    this.display = display;

    font = display.getAssetManager().loadFont(name);
  •    texture = font.getPage(0).getTextureParam(&quot;ColorMap&quot;).getTextureValue();<br />
    

text = new BitmapText(font);

actualSize = font.getPreferredSize();

text.setSize(actualSize);

@@ -63,10 +61,6 @@

return text;

}


  • public Texture2D getTexture(){
  •    return (Texture2D) texture;<br />
    
  • }

    -

    /**
  • get font height.
  • @return height

    Index: src/niftygui/com/jme3/niftygui/RenderDeviceJme.java

    ===================================================================

    — src/niftygui/com/jme3/niftygui/RenderDeviceJme.java (revision 6567)

    +++ src/niftygui/com/jme3/niftygui/RenderDeviceJme.java (working copy)

    @@ -175,11 +175,9 @@

    return;



    RenderFontJme jmeFont = (RenderFontJme) font;
  •    Texture2D texture = jmeFont.getTexture();<br />
    

BitmapText text = jmeFont.getText();



niftyMat.setColor("Color", convertColor(color));

  •    niftyMat.setTexture(&quot;Texture&quot;, texture);<br />
    

niftyMat.setInt("Mode", 4);

niftyMat.getAdditionalRenderState().setBlendMode(convertBlend());

text.setMaterial(niftyMat);

Index: src/core/com/jme3/font/QuadList.java

===================================================================

— src/core/com/jme3/font/QuadList.java (revision 6567)

+++ src/core/com/jme3/font/QuadList.java (working copy)

@@ -60,17 +60,6 @@

return actualSize;

}


  • /**
  • * Sets the size of any remaining quads to 0, 0<br />
    
  • */<br />
    
  • void cleanTail(){
  •    if (quads.size() &gt; actualSize){<br />
    
  •        for (int i = actualSize; i &lt; quads.size(); i++){<br />
    
  •            quads.get(i).setSize(0, 0);<br />
    
  •        }<br />
    
  •    }<br />
    
  • }

    -

    FontQuad newQuad() {

    FontQuad q = null;

    if (actualSize == quads.size()) {

    Index: src/core/com/jme3/font/BitmapText.java

    ===================================================================

    — src/core/com/jme3/font/BitmapText.java (revision 6567)

    +++ src/core/com/jme3/font/BitmapText.java (working copy)

    @@ -31,6 +31,7 @@

    */

    package com.jme3.font;



    +import com.jme3.material.Material;

    import com.jme3.math.ColorRGBA;

    import com.jme3.renderer.RenderManager;

    import com.jme3.renderer.queue.RenderQueue.Bucket;

    @@ -180,9 +181,6 @@

    } else {

    lineWidth = font.updateTextRect(block, quadList, wordWrap);

    }
  •    // set size to zero of any quads at the end that<br />
    
  •    // were not updated<br />
    
  •    quadList.cleanTail();<br />
    

for (int i = 0; i < textPages.length; i++) {
textPages.assemble(quadList);
@@ -191,9 +189,10 @@
}

public void render(RenderManager rm) {
- for (BitmapTextPage entry : textPages) {
- //mat.render(entry, rm);
- entry.getMaterial().render(entry, rm);
+ for (BitmapTextPage page : textPages) {
+ Material mat = page.getMaterial();
+ mat.setTexture("Texture", page.getTexture());
+ mat.render(page, rm);
}
}
}
Index: src/core/com/jme3/font/BitmapTextPage.java
===================================================================
--- src/core/com/jme3/font/BitmapTextPage.java (revision 6567)
+++ src/core/com/jme3/font/BitmapTextPage.java (working copy)
@@ -34,13 +34,13 @@
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
-import java.util.LinkedList;

import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer;
import com.jme3.scene.VertexBuffer.Type;
+import com.jme3.texture.Texture2D;
import com.jme3.util.BufferUtils;

class BitmapTextPage extends Geometry {
@@ -50,6 +50,7 @@
private final short[] idx;
private final byte[] color;
private final int page;
+ private final Texture2D texture;
private final QuadList quadList = new QuadList();

BitmapTextPage(BitmapFont font, boolean arrayBased, int page) {
@@ -67,6 +68,7 @@
}

setMaterial(mat);
+ this.texture = (Texture2D) mat.getTextureParam("ColorMap").getTextureValue();

// initialize buffers
Mesh m = getMesh();
@@ -100,6 +102,10 @@
BitmapTextPage(BitmapFont font) {
this(font, false, 0);
}
+
+ Texture2D getTexture() {
+ return texture;
+ }

@Override
public BitmapTextPage clone() {

[/patch]

commintted in svn. rev. 6578

What was the problem? :slight_smile:

My bitmap textures were wrong for nifty. :cry:

So does it work now? Your latest fix seems to have done the trick

There was nothing wrong in the patch.

I used some text images to test but it was not the right type used at nifty shader.