Problem with skybox

Hi all, I'm kind of new to jME, although I can say that a have a good grip of the bases, but now I have run into a problem that I'm not sure of how to go about solving. I built a skybox that builds and shows correctly:


private void buildSkyBox() {
      skybox = new Skybox("skybox", 10, 10, 10);

       Texture north = TextureManager.loadTexture(
               TestSkybox.class.getClassLoader().getResource(
               "com/c0mrade/sv/data/textures/north.jpg"),
               Texture.MinificationFilter.BilinearNearestMipMap,
               Texture.MagnificationFilter.Bilinear, Image.Format.GuessNoCompression, 0.0f, true);
           Texture south = TextureManager.loadTexture(
               TestSkybox.class.getClassLoader().getResource(
               "com/c0mrade/sv/data/textures/south.jpg"),
               Texture.MinificationFilter.BilinearNearestMipMap,
               Texture.MagnificationFilter.Bilinear, Image.Format.GuessNoCompression, 0.0f, true);
           Texture east = TextureManager.loadTexture(
               TestSkybox.class.getClassLoader().getResource(
               "com/c0mrade/sv/data/textures/east.jpg"),
               Texture.MinificationFilter.BilinearNearestMipMap,
               Texture.MagnificationFilter.Bilinear, Image.Format.GuessNoCompression, 0.0f, true);
           Texture west = TextureManager.loadTexture(
               TestSkybox.class.getClassLoader().getResource(
               "com/c0mrade/sv/data/textures/west.jpg"),
               Texture.MinificationFilter.BilinearNearestMipMap,
               Texture.MagnificationFilter.Bilinear, Image.Format.GuessNoCompression, 0.0f, true);
           Texture up = TextureManager.loadTexture(
               TestSkybox.class.getClassLoader().getResource(
               "com/c0mrade/sv/data/textures/top.jpg"),
               Texture.MinificationFilter.BilinearNearestMipMap,
               Texture.MagnificationFilter.Bilinear, Image.Format.GuessNoCompression, 0.0f, true);
           Texture down = TextureManager.loadTexture(
               TestSkybox.class.getClassLoader().getResource(
               "com/c0mrade/sv/data/textures/bottom.jpg"),
               Texture.MinificationFilter.BilinearNearestMipMap,
               Texture.MagnificationFilter.Bilinear, Image.Format.GuessNoCompression, 0.0f, true);

           skybox.setTexture(Skybox.Face.North, north);
           skybox.setTexture(Skybox.Face.West, west);
           skybox.setTexture(Skybox.Face.South, south);
           skybox.setTexture(Skybox.Face.East, east);
           skybox.setTexture(Skybox.Face.Up, up);
           skybox.setTexture(Skybox.Face.Down, down);
           skybox.preloadTextures();
          
           this.skybox.updateRenderState();
      
       CullState cullState = display.getRenderer().createCullState();
       cullState.setCullFace(CullState.Face.None);
       cullState.setEnabled(true);
       skybox.setRenderState(cullState);

       ZBufferState zState = display.getRenderer().createZBufferState();
       zState.setEnabled(false);
       skybox.setRenderState(zState);

       FogState fs = display.getRenderer().createFogState();
       fs.setEnabled(false);
      
       skybox.setRenderState(fs);

       skybox.setLightCombineMode(Spatial.LightCombineMode.Off);
       skybox.setCullHint(Spatial.CullHint.Never);
       skybox.setTextureCombineMode(TextureCombineMode.Replace);
       skybox.updateRenderState();
      
       skybox.lockBounds();
       skybox.lockMeshes();
      
   }


So this is how I made the skybox and this is how I rendered it in the simpleUpdate() method:


protected void simpleUpdate()  {
skybox.draw(display.getRenderer());
skybox.updateGeometricState(0.0f, true);
/*more code here*/
}


The problem is that when I move around the screen, using a model attached to a ThirdPersonHandler,
the skybox flickers and distorts the screen, but returns to normal when I stop moving. However, when I looked at another example using a skybox, it looks fine. Any suggestions?

I'm not sure, but it might not be good to do rendering in the update method.

Is there a specific reason why you're using skybox.draw(display.getRenderer());?

As far as I know, it usually works fine without that.

I also see you're not attaching your skybox to the scene in that code snippet, are you doing it somewhere else?

As tumaini said, there's an update and a render pass done on the scenegraph. You should not be rendering the skybox in the update part, especially in this case where you explicitly render then update (if the skybox is moving with your camera, you're basically drawing it THEN moving it which isn't good).



If you attached the skybox to the root node, most likely drawing it, updating it, then drawing it again (since its attached to the scenegraph) is causing the flickering, since you're drawing it twice - in two different positions, each frame. Also, you don't need to call updateGeometricState on it - if it's attached to the root node then it'll automatically get updated. So you really do not need to override the simpleUpdate() method here. Just make sure the skybox is attached to the root node, and then translate it according to your camera position and you should be fine.

Thanks for the replies! Hey Starnick, your suggestion about only setting the local translation once worked! Instead of updating the local translation everytime, I only set it to happen once. Thanks again, to both of you.