Quick Texture Question

Hi everyone,



I created my terrain with a custom heightmap made in photoshop:



Now I want to put a texture on it! For testing this idea I enlarged the heightmap picture REALLY much and painted a little green on the edge!







When I put it on my terrain it stays black everywhere! So my quick question is:


  • Is this method right? Can I just paint the contour of the image and put it on the terrain ??


  • Should I change the light?



    Here is some of my code:


   private void initLight() {
       DirectionalLight light = new DirectionalLight();
      light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
      light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, .5f));
      light.setDirection(new Vector3f(1, -1, 0));
      light.setShadowCaster(true);
      light.setEnabled(true);

      /** Attach the light to a lightState and the lightState to rootNode. */
      LightState lightState = disp.getRenderer().createLightState();
      lightState.setEnabled(true);
      lightState.setGlobalAmbient(new ColorRGBA(.2f, .2f, .2f, 1f));
      lightState.attach(light);
      rootNode.setRenderState(lightState);

   }



and the TerrainMaker File:

public static TerrainPage buildSampleTerrain(DisplaySystem display) {

      RawHeightMap heightMap = new RawHeightMap(Start.class.getClassLoader().getResource(
      "data/terrain/heights.raw").getFile(), 513,
      RawHeightMap.FORMAT_16BITLE, false);

            
      Vector3f terrainScale = new Vector3f(1.5f, 0.0002f, 1.5f);
      heightMap.setHeightScale(0.0001f);
      TerrainPage page = new TerrainPage("Terrain", 33, heightMap.getSize(),
            terrainScale, heightMap.getHeightMap(), false);

      page.setDetailTexture(1, 16);

      ProceduralTextureGenerator pt = new ProceduralTextureGenerator(
            heightMap);
      pt.addTexture(new ImageIcon(TerrainManager.class.getClassLoader()
            .getResource("data/terrain/unbenannt2.png")),  -128, 0, 128);

      pt.createTexture(512);

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

      return page;
   }



So I am happy for any quick responses ;)

Thanks Rapidm

call updateRenderState() after setting RenderStates or at least once after initializing everything. Dont know if that will fix things though  :wink:

I believe that is not the problem, because I got that in my IngameState already!

It may or may not be the problem depending on your heightmap, but looks like you are using ProceduralTextureGenerator when you don't need to be. It is intended to blend multiple textures based on the height of the terrain. With only one texture like that, it has no data outside the height range -128 to 128.



Try just loading your texture and applying your texture directly to the terrain.

Hi,



that seemed to be the problem.  I used:


RawHeightMap heightMap = new RawHeightMap(Start.class.getClassLoader().getResource(
      "data/terrain/heights.raw").getFile(), 513,
      RawHeightMap.FORMAT_16BITLE, false);

            
      Vector3f terrainScale = new Vector3f(1.5f, 0.0002f, 1.5f);
      heightMap.setHeightScale(0.0001f);
      TerrainPage page = new TerrainPage("Terrain", 33, heightMap.getSize(),
            terrainScale, heightMap.getHeightMap(), false);

       // This will be the texture for the terrain.
        URL texture=HelloTerrain.class.getClassLoader().getResource(
            "data/terrain/unbenannt3.png");
       
        // Add the texture
        TextureState ts=display.getRenderer().createTextureState();
        ts.setTexture(
                TextureManager.loadTexture(texture,Texture.MM_LINEAR,Texture.FM_LINEAR)
        );
        page.setRenderState(ts);



instead and now it's not black anymore! But it still not the right fit! My terrain is 512px big ans is scaled Vector3f terrainScale = new Vector3f(1.5f, 0.0002f, 1.5f);  So can what size should I make my terrainimage? I just want to use one that fits on the terrain nicely ;)

Thanks

Your texture should fit your terrain exactly regardless of their sizes. Make sure you don't have any tiling set.

Also, check if you need to flip the image.