Setting a wallpaper for the background


I am trying to make a board game, and i would like to change the black background of the renderer to something fancy (say a texture)…

Now I have been trying to set a box/quad in ORTHO mode with the same height and width of the display, but it seems like it takes over everything else (it sits on top of everything). Below is the tree structure of my game:

[HUD = heads up display]

Only the HUD and the Wallpaper is on ORTHO mode and the rest of the stuff are on normal mode.

Please advise if there is any sort of solutions.

Thank you

add a zbuffer state to the quad and disable writing maybe?

hey thanks for the reply…

  1. Do i really need a zbuffer? my thought was that since im not rendering 3d, i dont need a zbuffer…the quad got 0 as z for its coord…

  2. Im very new to jme, so i still need to learn alot more stuff… so… do you disable write? is it the same as setLock()?

    Thank you!

The ortho queue is rendered last, since ortho mode is usually used for hud elements.

If you want to draw a background picture, it might be easiest to use renderpasses.


import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.light.PointLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.renderer.pass.RenderPass;
import com.jme.scene.Node;
import com.jme.scene.Spatial.CullHint;
import com.jme.scene.Spatial.LightCombineMode;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Quad;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.RenderState.StateType;
import com.jme.util.TextureManager;
import com.jme.util.resource.ResourceLocatorTool;
import com.jme.util.resource.SimpleResourceLocator;

public class TestBG extends SimplePassGame {
   private Node bgNode = new Node("bg Node");
   private Node hudNode = new Node("hud Node");
   private Node sceneNode = new Node("scene Node");
   protected void simpleInitGame() {
      try {
               new SimpleResourceLocator(TestBG.class.getResource("jmetest/data/images/")));
      } catch (URISyntaxException e) {
      // set up the 3 Nodes: 3D-Scene | Background | Hud
      // create two RenderPasses
      RenderPass basicPass = new RenderPass();
      RenderPass bgPass = new RenderPass();

      // first add the Background Pass to the PassManager
      // then add the main Pass tot the PassManager
      // update renderstates of our Nodes
      // notice we dont add anything to SimpleGame's rootnode its not used.

   // create a simple 3D Scene
   private void setUpScene() {
      // simply get the rootNode's renderstates
      Sphere s = new Sphere("s", 15, 15, 2);
      s.setModelBound(new BoundingSphere());
      s.setLocalTranslation(-5, 5, -2);
      Box b = new Box("b", new Vector3f(), 1, 1, 1);
      b.setModelBound(new BoundingBox());
      b.setLocalTranslation(-2, -3, 1);

   // Set up the hud which is drawn infront of the scene
   private void setUpHUD() {
      TextureState hudTs = display.getRenderer().createTextureState();
            ResourceLocatorTool.TYPE_TEXTURE, "checkup.png")));
      Quad q1 = new Quad("hud 1", 300, 70);
      q1.setModelBound(new BoundingBox());
      q1.setLocalTranslation(400, 200, 0);

   // set up the Background Quad, which will be rendererd in its own renderpass
   private void setUpBackground() {
      Quad bg = new Quad("bg", display.getWidth(), display.getHeight());
      bg.setModelBound(new BoundingBox());
      bg.setLocalTranslation(display.getWidth()/2, display.getHeight()/2, 0);
      TextureState ts = display.getRenderer().createTextureState();
            ResourceLocatorTool.TYPE_TEXTURE, "Monkey.jpg")));

   public static void main(String[] args) {
      TestBG game = new TestBG();

hey THANK YOU for putting your time in answering my question, and sorry that i am replying late.

I have tried your way, (i am using BaseGame)

 public void init()
// create zbuffer for the board to look 3d
        ZBufferState buf = display.getRenderer().createZBufferState();
// just a testing code ... basically your own code is copied in the constructor... just a copy-paste
        BgTexture background = new BgTexture(bgNode, display);
// HUD of the game....
        hud = new HUD(display, rootNode, lightState);
        PointLight mainLight = new PointLight();
// will draw the board, and give it a 2D texture
        this.moveToken(0, 1);

        BasicPassManager pManager = new BasicPassManager();

        RenderPass scenePass = new RenderPass();
        RenderPass bgPass = new RenderPass();

//rootNode is a custom node that i have made, and everything get connected to this, as the tree structure showed



Now, the problem is that everything gets shown apart from the background... here is the code for the 'bgTexture':

public class BgTexture

    public BgTexture(Node bgNode, DisplaySystem display)
        Quad bg = new Quad("bg", display.getWidth(), display.getHeight());
        bg.setModelBound(new BoundingBox());
        bg.setLocalTranslation(display.getWidth() / 2, display.getHeight() / 2, 0);
        TextureState ts = display.getRenderer().createTextureState();
        ts.setTexture(TextureManager.loadTexture(this.getClass().getResource("bg.jpg"), Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear));


I have even tried taking out the scenePass out of the renderpass queue, but nothing happens...

seems like the renderPass is not even connected to the i correct?

Thank you

hey hey!

THANK YOU AGAIN! worked like magic…

I put pManager.render(…) and pManager.update in the appropriate method of the baseGame and it worked like magic! THANK YOU