I was able to do this using a TerrainBlock, but when I moved to using a TerrainPage I can't seem to get it to work. I'm fairly new to this, so I'm probably just not understanding something correctly.
Here is what I had for my Terrain Block:
...
Vector2f textureOffset = new Vector2f(0f, 0f);
TerrainBlock terrainBlock = new TerrainBlock("terrain", GRID_SIZE + 1, scaling, map, origin, false, 4, textureOffset, 0f);
terrainBlock.setRenderState(getGrassTextureState());
// *snip* set model bounds
return terrainBlock;
}
private TextureState getGrassTextureState() {
// Get a URL that points to the texture we're going to load
URL grassTextureLoc = TerrainBuilder.class.getClassLoader().getResource("com/polarflare/rts/textures/grass.jpg");
// Use the TextureManager to load a texture
Texture grassTexture = TextureManager.loadTexture(grassTextureLoc, Texture.MM_LINEAR, Texture.FM_LINEAR);
grassTexture.setWrap(Texture.WM_WRAP_S_WRAP_T);
// Get a TextureState
TextureState ts = display.getRenderer().createTextureState();
// Assign the texture to the TextureState
ts.setTexture(grassTexture);
return ts;
}
So I figured something like this should work with a TerrainPage:
TerrainPage terrainPage = new TerrainPage("terrain", 64, GRID_SIZE + 1, scaling, map, false);
terrainPage.setOffset(textureOffset);
terrainPage.setTotalSize(4);
terrainPage.setOffsetAmount(0f);
terrainPage.setRenderState(getGrassTextureState());
return terrainPage;
}
...but my texture appears to be stretched across the entire terrain. What am I doing wrong?