Using a terrainblock with Basegame

hiya,



I’ve been trying to get my terrainblock to work but Im stuck for some reason. The problem is whenever I want to render a terrain its colourless. The exact same code is used in testclass about the Splattexturegenerator. But for some reason I get this as result







while using the correct(the same) textures.

There’s probably an parameter I dont have turned on which is set automatically on in the simpleGame.

But perhaps im all wrong since I can’t seem to find what im forgetting.



A small hint would do miracles!  XD

Thanks!

It maybe a missing updateRenderstate() ? ( s. http://www.jmonkeyengine.com/wiki/doku.php?id=updatefuncs )

have you tried removing the textures and adding them back on one by one?  To me it looks like you are missing the base texture and only having the detail texture.

i think it looks like a detail texture plus a black and white basetexture…or, the height of your terrain is such that only black and white gets generated(like at big heights) ?

I made some slight progress!



Currently my code to render the terrain looks like this



private void buildTerrain()
   {
      URL grayScale=TestProceduralSplatTexture.class.getClassLoader().getResource("jmetest/data/texture/terrain.png");
      
      ImageBasedHeightMap heightMap = new ImageBasedHeightMap(new ImageIcon(grayScale).getImage());

      Vector3f terrainScale = new Vector3f(5, 0.25f, 5);
      TerrainBlock tb = new TerrainBlock("Terrain", heightMap.getSize(), terrainScale, heightMap.getHeightMap(),
            new Vector3f(0, 0, 0), true);
      tb.setDistanceTolerance(1.0f);
      tb.setDetailTexture(1, 16);
      tb.setModelBound(new BoundingBox());
      tb.updateModelBound();
      tb.setLocalTranslation(new Vector3f(0, 0, 0));
      //scene.attachChild(tb);
      //rootNode.setRenderState(cs);

      ProceduralSplatTextureGenerator pst = new ProceduralSplatTextureGenerator(heightMap);
      pst.addTexture(new ImageIcon(techDemoTerrain.class.getClassLoader().getResource(
            "jmetest/data/texture/grassb.png")), -128, 0, 128);
      pst.addTexture(new ImageIcon(techDemoTerrain.class.getClassLoader().getResource(
            "jmetest/data/texture/grassb.png")), 0, 128, 255);
      pst.addTexture(new ImageIcon(techDemoTerrain.class.getClassLoader().getResource(
            "jmetest/data/texture/grassb.png")), 128, 255, 384);

      pst.addSplatTexture(new ImageIcon(techDemoTerrain.class.getClassLoader().getResource(
            "jmetest/data/texture/terrainTex.png")), new ImageIcon(techDemoTerrain.class.getClassLoader().getResource(
            "jmetest/data/texture/water.png")));

      pst.createTexture(512);

      TextureState ts = display.getRenderer().createTextureState();
      Texture t1 = TextureManager.loadTexture(pst.getImageIcon().getImage(), Texture.MM_LINEAR_LINEAR,
            Texture.FM_LINEAR, true);
      ts.setTexture(t1, 0);

      Texture t2 = TextureManager.loadTexture(TestProceduralSplatTexture.class.getClassLoader().getResource(
            "jmetest/data/texture/Detail.jpg"), Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR);


      ts.setTexture(t2, 1);      
//      t2.setWrap(Texture.WM_WRAP_S_WRAP_T);
//
      t1.setApply(Texture.AM_COMBINE);
      t1.setCombineFuncRGB(Texture.ACF_MODULATE);
      t1.setCombineSrc0RGB(Texture.ACS_TEXTURE);
      t1.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
      t1.setCombineSrc1RGB(Texture.ACS_PRIMARY_COLOR);
      t1.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
      t1.setCombineScaleRGB(1.0f);
//
//      t2.setApply(Texture.AM_COMBINE);
//      t2.setCombineFuncRGB(Texture.ACF_ADD_SIGNED);
//      t2.setCombineSrc0RGB(Texture.ACS_TEXTURE);
//      t2.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
//      t2.setCombineSrc1RGB(Texture.ACS_PREVIOUS);
//      t2.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
//      t2.setCombineScaleRGB(1.0f);
//      
      

      
      tb.setRenderState(ts);
      tb.setDetailTexture(1, 16);
        tb.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
      
      scene.attachChild(tb);
      

      
      
      scene.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
      //fpsNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);

   
   }



When I run this it works "fine", in the sense that the terrain is coloured. Only thing lacking is the detail. Now whenever I add T2 I get the grey terrain again. Apparantly It doesnt like something from T2?

I assume the jmetest version works fine on your machine?  I can't see anything in the code that would suggest that it shouldn't work fine.  Maybe start with the simplegame version and make changes towards your code until it breaks?  Looking closely, you can tell the multitexturing is working, but it's almost as if the combine settings are off or something.

renanse said:

I assume the jmetest version works fine on your machine?  I can't see anything in the code that would suggest that it shouldn't work fine.  Maybe start with the simplegame version and make changes towards your code until it breaks?  Looking closely, you can tell the multitexturing is working, but it's almost as if the combine settings are off or something.


The jmetest version works perfect. The code is a copy of the jmetest so everything should be running. I compared it with the way terrain was rendered in the flagrush tutorial lesson 9 but couldn't find why it didnt work. It also sees the texture images because whenever the URL to a location of a texture doesnt exist the whole app doesnt even start.

Narrowing it down.. it definatly has to be some combine setting. However in the code, whenever I even add the T2 image (having nothing changed with the Combine) it still doesnt work. Adding all the combine options doesnt work either (naturally) even though the exact same combine options (For T1 and T2) are being used in the jmetest.  :?

I think ill check the combine options out individually but I fear it might be a useless effort

Maybe you could send me your class and I'll see if I can track the issue down.

You've got mail!  XD

So I got your test file and saw the grayscale terrain as you pictured, so I uncommented the t2.setCombineXXX functions and it works fine…  Can you try that again real quick?

That doesn't work. Are you sure you didnt change anything?

Perhaps you can reply me (or post here, whatever is most conveniant) your .java and I can check the exact same source?

I did not change anything else except for remove the arguments to get timer since that no longer exists as a method type locally.  I've uploaded the src with the minimal changes (uncommented t2 lines, removed package name and removed timer argument – only rolling back the comments on the t2 lines brings back the gray though) here:



http://www.renanse.com/jme/example_src/techDemoTerrain.java





I also took the liberty to clean up the code, remove a few unnecessary calls, remove clod and switch to TerrainPage, etc.  The cleaner version (which still looks the same) can be found here:



http://www.renanse.com/jme/example_src/techDemoTerrain2.java

If you still get it, I'd bet you have some cached class file somewhere that is making life difficult.

I tried both versions you’ve posted and I still get the problem.



You mention it might be my cache… How would I solve that issue then? Whenever I make a different change (e.a. other map grayscale) it does work, meaning it doesnt use cache?

To make matters worse, when toying arround with creating new class files, where I pasted your “cleaner code”, I accidently overwritten a few days work with an older version… frustration!!!  :’(



Oh well, no one to blame. I atleast thank you for the time you already spent on my problem.

Typically IDE's have a "clean" action, to make sure you're not using any old files. eg in Eclipse Project -> Clean…

If you are using Eclipse (other ide's have this as well) you can pull up the local history of a class file to recover pasted over work.  Maybe you can recover your work?



Did you try making a brand new class and pasting in my clean version?  (Maybe that's what you were saying?..)



Also, what version of jME are you using?

Apparantly updating to the latest jME build solved it!!  :-o



However, the terrain has green area's (grassb.png) and grey area's, shouldn't everything be green?

I'll figure it out myself thru the examples.



Glad I got colour again!

Thanks a million :slight_smile: