Ok, So if does front to back, then why is quad drawing over q1? I assume if u do front to back, then you would only render what can be seen underneath whats in front of the current object being drawn. But here, it looks like it doesn't care whats in front and just draws over it.
Nope, nothing should be transparent btw.
I've attached the full source below
import com.jme.app.*;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.*;
import com.jme.input.action.*;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.*;
import com.jme.scene.state.*;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.TextureManager;
import com.jme.util.Timer;
import com.jme.renderer.*;
public class Lesson2 extends BaseGame {
protected Timer timer;
//Our camera object for viewing the scene
private Camera cam;
//the root node of the scene graph
private Node scene;
//display attributes for the window. We will keep these values
//to allow the user to change them
private int width, height, depth, freq;
private boolean fullscreen;
private ThirdPersonHandler thirdPersonHandler;
protected void update(float interpolation) {
//update the time to get the framerate
timer.update();
interpolation = timer.getTimePerFrame();
thirdPersonHandler.update(interpolation);
//if escape was pressed, we exit
if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
finished = true;
}
}
protected void render(float interpolation) {
//Clear the screen
display.getRenderer().clearBuffers();
display.getRenderer().draw(scene);
}
protected void initSystem() {
//store the properties information
int width = 640;
int height = 480;
int depth = 24;
int freq = 50;
boolean fullscreen =false;
try {
display = DisplaySystem.getDisplaySystem();
display.createWindow(width, height, depth, freq, fullscreen);
cam = display.getRenderer().createCamera(width, height);
} catch (JmeException e) {
e.printStackTrace();
System.exit(1);
}
//set the background to black
display.getRenderer().setBackgroundColor(ColorRGBA.black);
//initialize the camera
cam.setFrustumPerspective(45.0f, (float)width / (float)height, 1, 1000);
Vector3f loc = new Vector3f(0.0f, 0.0f, 50.0f);
Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
// Move our camera to a correct place and orientation.
cam.setFrame(loc, left, up, dir);
/** Signal that we've changed our camera's location/frustum. */
cam.update();
/** Get a high resolution timer for FPS updates. */
timer = Timer.getTimer();
display.getRenderer().setCamera(cam);
KeyBindingManager.getKeyBindingManager().set("exit",KeyInput.KEY_ESCAPE);
}
protected void initGame() {
scene = new Node("Scene graph node");
scene.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
//Create our Sphere
Arrow arrow = new Arrow("Arrow", 5, 1);
arrow.setModelBound(new BoundingBox());
arrow.updateModelBound();
Node arrowNode = new Node("arrowNode");
arrowNode.setLocalTranslation(new Vector3f(0,0,0));
arrowNode.attachChild(arrow);
// create a third person handler
thirdPersonHandler = new ThirdPersonHandler(arrowNode,cam);
InputAction leftAction = new LeftAction();
KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();
keyboard.set("leftAction",KeyInput.KEY_LEFT);
thirdPersonHandler.addAction(leftAction,"leftAction",false);
scene.attachChild(arrowNode);
Quad q1 = new Quad("q1",5f,5f);
q1.setDefaultColor(ColorRGBA.red);
q1.setModelBound(new BoundingBox());
q1.updateModelBound();
Node q1Node = new Node("q1Node");
q1Node.setLocalTranslation(new Vector3f(0,5,-5f));
q1Node.attachChild(q1);
scene.attachChild(q1Node);
// buidl background
Quad quad = new Quad("background",40f,40f);
quad.setDefaultColor(ColorRGBA.blue);
quad.setModelBound(new BoundingBox());
quad.updateModelBound();
Node quadNode = new Node("quadNode");
quadNode.setLocalTranslation(new Vector3f(0,0,-25f));
quadNode.attachChild(quad);
scene.attachChild(quadNode);
//update the scene graph for rendering
scene.updateGeometricState(0.0f, true);
scene.updateRenderState();
}
protected void reinit() {
display.recreateWindow(width, height, depth, freq, fullscreen);
}
protected void cleanup() {
}
public class LeftAction extends InputAction{
public void performAction(InputActionEvent evt){
System.out.println("Left button action performed");
thirdPersonHandler.setTurnSpeed(0.1f);
thirdPersonHandler.setDoGradualRotation(true);
}
}
public static void main(String[] args) {
Lesson2 app = new Lesson2();
app.start();
}
}