Hi!
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]
http://www.mofirouz.com/wordpress/wp-content/gallery/jme-3dsnl-creation/tree.jpg
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…
- 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…
- Im very new to jme, so i still need to learn alot more stuff… so… lol.how 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 java.net.URISyntaxException;
import com.jme.app.SimplePassGame;
import com.jme.app.AbstractGame.ConfigShowMode;
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");
@Override
protected void simpleInitGame() {
try {
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(TestBG.class.getResource("jmetest/data/images/")));
} catch (URISyntaxException e) {
e.printStackTrace();
}
// set up the 3 Nodes: 3D-Scene | Background | Hud
setUpScene();
setUpBackground();
setUpHUD();
// create two RenderPasses
RenderPass basicPass = new RenderPass();
RenderPass bgPass = new RenderPass();
// first add the Background Pass to the PassManager
pManager.add(bgPass);
bgPass.add(bgNode);
// then add the main Pass tot the PassManager
pManager.add(basicPass);
basicPass.add(sceneNode);
basicPass.add(hudNode);
// update renderstates of our Nodes
hudNode.updateRenderState();
bgNode.updateRenderState();
sceneNode.updateRenderState();
// 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
sceneNode.setRenderState(rootNode.getRenderState(StateType.Light));
sceneNode.setRenderState(rootNode.getRenderState(StateType.ZBuffer));
Sphere s = new Sphere("s", 15, 15, 2);
s.setModelBound(new BoundingSphere());
s.updateModelBound();
s.setLocalTranslation(-5, 5, -2);
sceneNode.attachChild(s);
Box b = new Box("b", new Vector3f(), 1, 1, 1);
b.setModelBound(new BoundingBox());
b.updateModelBound();
b.setLocalTranslation(-2, -3, 1);
sceneNode.attachChild(b);
}
// Set up the hud which is drawn infront of the scene
private void setUpHUD() {
TextureState hudTs = display.getRenderer().createTextureState();
hudTs.setTexture(TextureManager.loadTexture(ResourceLocatorTool.locateResource(
ResourceLocatorTool.TYPE_TEXTURE, "checkup.png")));
Quad q1 = new Quad("hud 1", 300, 70);
q1.setModelBound(new BoundingBox());
q1.updateModelBound();
q1.setRenderState(hudTs);
q1.setLocalTranslation(400, 200, 0);
hudNode.attachChild(q1);
hudNode.setCullHint(CullHint.Never);
hudNode.setLightCombineMode(LightCombineMode.Off);
hudNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
}
// 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.updateModelBound();
bg.setLocalTranslation(display.getWidth()/2, display.getHeight()/2, 0);
TextureState ts = display.getRenderer().createTextureState();
ts.setTexture(TextureManager.loadTexture(ResourceLocatorTool.locateResource(
ResourceLocatorTool.TYPE_TEXTURE, "Monkey.jpg")));
bgNode.setRenderState(ts);
bgNode.attachChild(bg);
bgNode.setCullHint(CullHint.Never);
bgNode.setLightCombineMode(LightCombineMode.Off);
bgNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
}
public static void main(String[] args) {
TestBG game = new TestBG();
game.setConfigShowMode(ConfigShowMode.AlwaysShow);
game.start();
}
}
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();
buf.setEnabled(true);
buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
baseNode.setRenderState(buf);
rootNode.setRenderState(buf);
// 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();
mainLight.setDiffuse(ColorRGBA.cyan);
mainLight.setEnabled(true);
lightState.attach(mainLight);
// will draw the board, and give it a 2D texture
this.create_drawBoard();
this.createToken();
this.drawToken(0);
this.moveToken(0, 1);
hud.show_bumping();
rootNode.attachChild(baseNode);
BasicPassManager pManager = new BasicPassManager();
RenderPass scenePass = new RenderPass();
RenderPass bgPass = new RenderPass();
bgPass.add(bgNode);
pManager.add(bgPass);
bgPass.doRender(display.getRenderer());
scenePass.add(rootNode);
pManager.add(scenePass);
//rootNode is a custom node that i have made, and everything get connected to this, as the tree structure showed
bgNode.updateRenderState();
rootNode.updateRenderState();
mainLight.setLocation(cam.getLocation());
}
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.updateModelBound();
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));
bgNode.setRenderState(ts);
bgNode.attachChild(bg);
bgNode.setCullHint(CullHint.Never);
bgNode.setLightCombineMode(LightCombineMode.Off);
bgNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
}
}
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 renderer....am i correct?
Thank you
mo
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
THANK YOU!