Hello,
I’m programming my first project with jMonkey engine 3.1 alpha 1. It’s a planetarium, or night sky simulator, for android with Google Cardboard VR support.
I used the jme-cardboard plugin to handle the rendering on android, using the CardBoardHarnessFragment. I had some troubles with the camera rotating in the inverted Y direction (pitch) and the display being distorted, which I successfully solved by modifying the source code of jme-cardboard.
I was then able to show some stars in the sky, and run the application on my Samsung Galaxy S5 phone.
Next step is adding an user interface. I cannot use the guiNode for displaying, the interface with jme-cardboard, so I decided to use Lemur to display the interface inside the rootNode, so the interface appears like a floating panel in the 3D world.
I tried to show a window (container), containing a label. It works well on my computer (Ubuntu Linux x64), but some glitches appear instead of the fonts when I try to run my project on my android device (Samsung Galaxy S5) using CardboardHarnessFragment from jme-cardboard. It works fine with the standard AndroidHarnessFragment.
I tried to troubleshoot the problem and found out that the issue is caused by BitmapText that does not correctly render when using CardboardHarnessFragment. I made a test application to demonstrate this particular issue:
package mygame;
import com.jme3.app.FlyCamAppState;
import com.jme3.app.SimpleApplication;
import com.jme3.font.BitmapFont;
import com.jme3.font.BitmapText;
import com.jme3.font.Rectangle;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.Bucket;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
public class Main extends SimpleApplication {
public static void main(String[] args){
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
// Create a bitmap text and add it to root node
BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
BitmapText txt = new BitmapText(fnt, false);
txt.setBox(new Rectangle(0, 0, 6, 3));
txt.setLocalTranslation(0, 0, -14);
txt.setQueueBucket(Bucket.Transparent);
txt.setSize(1.0f);
txt.setText("Hello world!");
rootNode.attachChild(txt);
// Create a green box and add it to root node
Box boxMesh = new Box(1f,1f,1f);
Geometry boxGeo = new Geometry("Green Box", boxMesh);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Green);
boxGeo.setMaterial(mat);
boxGeo.setLocalTranslation(0, 0, -15);
rootNode.attachChild(boxGeo);
// Set up camera
flyCam.setEnabled(false);
stateManager.detach(stateManager.getState(FlyCamAppState.class));
cam.setLocation(Vector3f.ZERO);
cam.lookAt(boxGeo.getWorldTranslation(), Vector3f.UNIT_Y);
}
}
When running this code on my PC, I get this:
With CardboardHarnessFragment, I get this:
With AndroidHarnessFragment, I get this:
There is clearly a problem with CardboardHarnessFragment that alters the displaying of the BitmapText but I cannot find what. Maybe is it related to the multiple viewports in CardBoardHarnessFragment?
My knowledge of the internals of JME is very basic since this is my first project, but I’m higly motivated to fix this bug that prevents me from moving forward.
Does anybody there have some clues about what is happening and how to prevent it?
BTW, thanks to all the developers involved in JME, for building this amazing piece of software and distributing it under an open source license!