[newbie question] - object not visible

This is most likely my lack of knowledge & experience with jme. My problem is that i'm not able to see a sphere that I added

to my world. Here's the code (check the sphere variable towards the bottom of the init method)



import java.nio.FloatBuffer;
import java.util.ArrayList;
import com.jme.app.BaseGame;
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.image.Texture;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput ;
import com.jme.math.Ray;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.Text;
import com.jme.scene.TriMesh ;
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.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.TextureManager ;
import com.jme.util.Timer;
import com.jme.util.geom.BufferUtils ;
import com.jme.scene.state.AlphaState;

public class Wall3d extends BaseGame
{
    protected Timer timer;
    private Camera cam;     
    private Node scene;      
    private int width, height, depth, freq;
    private boolean fullscreen;
   
    Node snode;
    Sphere sphere;
    
    private Quad hudQuad;
    private Node hudNode;
    private int textureHeight,textureWidth;
 
  
    public static void main(String[] args)
    {
        Wall3d app = new Wall3d();
        app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG, Wall3d.class.getClassLoader().getResource("jmetest/data/images/FlagRush.png"));
        app.start();
    }
 
  
    protected void update(float interpolation) {
     
        if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
            this.finish();
        }
        
        timer.update ();
        scene.updateGeometricState(0.0f, true);
        scene.updateRenderState();
    }
  
 
  
    protected void render(float interpolation) {
        display.getRenderer().clearBuffers();
        display.getRenderer().draw(scene);
    }
  

  
    protected void initSystem()
    {
        //store the properties information
        width = properties.getWidth();
        height = properties.getHeight();
        depth = properties.getDepth();
        freq = properties.getFreq();
        fullscreen = properties.getFullscreen();
     
        try
        {
            display = DisplaySystem.getDisplaySystem(properties.getRenderer());
            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, 100);
        Vector3f loc = new Vector3f( 0.0f, 0.0f, 45.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(properties.getRenderer());
        display.getRenderer().setCamera(cam);
        KeyBindingManager.getKeyBindingManager().set("exit",KeyInput.KEY_ESCAPE);
    }
 

    protected void initGame()
    {
        scene = new Node("Scene graph node");
                                
        hudQuad = new Quad("hud",width,height);
        hudNode = new Node("hudNode");
        hudQuad.setRenderQueueMode(Renderer.QUEUE_ORTHO);
        hudQuad.setLocalTranslation (new Vector3f(width/2,height/2,1.0f));       
        hudQuad.setLightCombineMode(LightState.OFF);
        hudNode.attachChild(hudQuad);
        
        TextureState ts1 = display.getRenderer().createTextureState();
        ts1.setTexture(TextureManager.loadTexture(getClass().getClassLoader().getResource("notebook.jpg"),Texture.FM_LINEAR,Texture.FM_LINEAR , 2.0f, false));
        textureWidth = ts1.getTexture().getImage().getWidth();
        textureHeight = ts1.getTexture().getImage().getHeight();
        ts1.setEnabled(true);
        FloatBuffer texCoords1 = BufferUtils.createVector2Buffer(4);
        texCoords1.put(getUForPixel(0)).put(getVForPixel(height));
        texCoords1.put(getUForPixel(0)).put(getVForPixel(0));
        texCoords1.put(getUForPixel(width)).put(getVForPixel(0));
        texCoords1.put(getUForPixel(width)).put(getVForPixel(height));
        hudQuad.setRenderState(ts1);
 
        com.jme.scene.state.AlphaState as = display.getRenderer ().createAlphaState();
        as.setBlendEnabled(true);
        as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
        as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
        as.setTestEnabled(false);
        as.setEnabled(true);
        hudQuad.setRenderState(as);
        scene.attachChild (hudNode);
        
        ColorRGBA textColor = new ColorRGBA(0.5f, 0.8f, 0.3f, 1);
        String textValue = "hello";
        Text text = Text.createDefaultTextLabel(" g" + ".text", textValue);                
        text.setDefaultColor(textColor);
        text.setCullMode(Spatial.CULL_NEVER);
        text.setLocalTranslation(new Vector3f(width/2,height/2,1.0f));
        scene.attachChild(text);
        
        snode = new Node("snode");
        sphere = new Sphere("Sphere", 10, 10,10f);
        sphere.setRandomColors();
        sphere.setCenter(new Vector3f(0,0,-0.7f));
        snode.attachChild(sphere);
        scene.attachChild(snode);
                
        //update the scene graph for rendering
        scene.updateGeometricState(0.0f, true);
        scene.updateRenderState();
    }
 
   
    private float getUForPixel(int xPixel) {
        return (float)xPixel/textureWidth;
    }  
  
   
    private float getVForPixel(int xPixel){
        return (float)xPixel/textureHeight;
    }
  
  
    protected void reinit() {
        display.recreateWindow(width, height, depth, freq, fullscreen);
    }
 
   
    protected void cleanup() {
          System.gc();
    }
}



When you run this, you get this huge texture on the Quad and a string. But my sphere is not being displayed. Thanks.

Perhaps unrelated (or maybe not), but if you're using BaseGame, make sure you have a ZBuffer state. Look in BaseSimpleGame  if you want to know how to set this up

I played around with the objects, specifically with the quad and the sphere, and noticed that sometimes, although the quad may "cut through the sphere",

only the quad is shown. I tried setting both sphere and quad at x = y = 0 and changed only the z coordinate and that's how i found out. Is there any setting

that I'm missing to be able to see the quad cut through the sphere as i'm expecting? Thanks.

Like I said, you have no ZBufferState… there's a tutorial in the wiki that explains SimpleGame… it also includes a ZBufferState.



ZBuffer = the thing that makes sure the object you expect to be in front of the other object is actually drawn that way.

Thanks llama.  Removed

hudQuad.setRenderQueueMode(Renderer.QUEUE_ORTHO);

and added the zbuffer code


 ZBufferState buf = display.getRenderer().createZBufferState();
        buf.setFunction(ZBufferState.CF_LEQUAL);
        buf.setWritable(true);
        hudNode.setRenderState(buf);



and that solved my problem. Still need to read some more about zbuffer... thanks a lot for the hint!