Flickering and Boxes


The problem is that my boxes i draw to generate a coordinate system are flickering all the time:



1. does anybody know how to solve this problem?

2. is it better practice to use terrainbox instead of boxes to draw the surface?

3. if i use terrainbox, how can i prevent that the texture scales over the hole terrainbox? i would prefer if the texture is repeated over the whole surface in its original size.


thx sebastian

It looks like you have z-fighting going on. Can you post some code showing how you setup your box with the coord texture?


hmm i dont know what zfighting is and how to prevent it, but my code to istantiate the ground looks like this:


rootNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
      fpsNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
      display.getRenderer().setBackgroundColor(ColorRGBA.blue);
      
      CullState cs = display.getRenderer().createCullState();
      cs.setCullMode(CullState.CS_BACK);
      cs.setEnabled(true);
      rootNode.setRenderState(cs);
      
      URL monkeyLoc;
      monkeyLoc = CP_Controller.class.getClassLoader().getResource("data/Grid.png");
      
      TextureState ts = display.getRenderer().createTextureState();
   
      Texture t = TextureManager.loadTexture(monkeyLoc, Texture.MM_LINEAR, Texture.FM_LINEAR);
      ts.setTexture(t);
      
      for (int i = 1; i < 5; i++) {
         for (int j = 1; j < 5; j++) {
            Box box = new Box("box", new Vector3f(i*50, 0, j*50), 50f, 0.01f, 50f);
            box.setRenderState(ts);
            rootNode.attachChild(box);
         }
      }
      
      Box y = new Box("y" ,new Vector3f(0,0,0), 0.1f, 100f, 0.1f);
      Box x = new Box("x", new Vector3f(0,0,0), 100f, 0.1f, 0.1f);
      Box z = new Box("z", new Vector3f(0,0,0), 0.1f, 0.1f, 100f);
      
      rootNode.attachChild(x);
      rootNode.attachChild(y);
      rootNode.attachChild(z);
   }



i hope someone can help me

ps. because you said something about z-fighting i post this code because it has a z in it :D

ZBufferState buf = display.getRenderer().createZBufferState();
      buf.setEnabled(true);
      buf.setFunction(ZBufferState.CF_LEQUAL);
      rootNode.setRenderState(buf);



this code is in my init method

You create the first box with a y value of 0 and a y extent of 0.1.

You do thze same for the other boxes.

The problem now is that essentiale the top sides of the boxes take the same space.

Replace the extent for your grid boxes with something like 0.11.

Or just use a quad that you layer on top of the other box.

Z-fighting is when you have more than one surface in the same location and in the same plane. You get a sketchy appearance like you have because during rendering parts of both get rendered on top each other due to numerical errors.

thx for you answers, but nevertheless i dont know exactly how to solve the problem. i have to draw all this boxes beaucse of the grid. as i have mentioned bevor, if i take the terrain block instead, the texture isn't correctly drawn.

i did a little bit of searching this forum and i found an explanation to use this piece of code:


((ZBufferState)this.rootNode.getRenderState(ZBufferState.RS_ZBUFFER)).setWritable(false);



if i insert this line the situation is better, but nevertheless solved. i think i should use it not for alle the node but only for some of them? right?

@pflanzenmoerder: if you like you can explain me your post in german ;) maybe i understand i better ;)

no one knows anything?? a hint would be a great help!

you draw 25 boxes, which overlap each other.

if you do a:

Box box = new Box("box", new Vector3f(2*i*50, 0, 2* j*50), 50f, 0.01f, 50f);


they won't overlap anymore and thus no more z-fighting.

thx a lot! ah ok know i understand why this is happening. but with your code the problem isn't solved, because then the boxes aren't draw in the right position anymore.

well you should actually just create a Box like this: Box("bla", new Vector3f(0,0,0), x,y,z);

And then move it t the correct position with box.setLocalTranslation(x,y,z).



The 2nd Parameter is the center of the Box, which should usually be 0,0,0.

ok im getting closer! thx a lot for all the hints.



i have only some small flickering on the lines. see the white points: is there any change to solve this?