Hey, thanks again for your input. I tried to define the variables according with the original source code, now it displays everything but I simply get the four textures displayed one on top of the other. Should I set the TextureStages’ modes? Could it be an issue with UV or normals?
BTW, here is the code:
[TerrainRegion class and HEIGHTMAP_SCALE]
class TerrainRegion():
def __init__(self,minimum,maximum,texture,textureObject):
self.minimum = minimum
self.maximum = maximum
self.texture = texture
self.textureObject = textureObject
HEIGHTMAP_SCALE = 2.0
[updated code]
self.terrainRegions = [
TerrainGenerator.TerrainRegion(0.0, 50.0 * HEIGHTMAP_SCALE, 0, loader.loadTexture("GLSL_TUTORIAL/content/textures/dirt.JPG")),
TerrainGenerator.TerrainRegion(51.0 * HEIGHTMAP_SCALE, 101.0 * HEIGHTMAP_SCALE, 0, loader.loadTexture("GLSL_TUTORIAL/content/textu
res/grass.JPG")),
TerrainGenerator.TerrainRegion(102.0 * HEIGHTMAP_SCALE, 203.0 * HEIGHTMAP_SCALE, 0, loader.loadTexture("GLSL_TUTORIAL/content/text
ures/rock.JPG")),
TerrainGenerator.TerrainRegion(204.0 * HEIGHTMAP_SCALE, 255.0 * HEIGHTMAP_SCALE, 0, loader.loadTexture("GLSL_TUTORIAL/content/text
ures/snow.JPG"))
]
ts1 = TextureStage('gnd1')
ts2 = TextureStage('gnd2')
ts3 = TextureStage('gnd3')
ts4 = TextureStage('gnd4')
ts1.setSort(0)
ts2.setSort(1)
ts3.setSort(2)
ts4.setSort(3)
self.tRoot.setTexture(ts1,self.terrainRegions[0].textureObject)
self.tRoot.setTexture(ts2,self.terrainRegions[1].textureObject)
self.tRoot.setTexture(ts3,self.terrainRegions[2].textureObject)
self.tRoot.setTexture(ts4,self.terrainRegions[3].textureObject)
shader = Shader.load(vertex='GLSL_TUTORIAL/content/shaders/terrain.vert',fragment='GLSL_TUTORIAL/content/shaders/terrain.frag',lang=Shader.SL_GLSL)
self.tRoot.setShaderInput("tilingFactor",HEIGHTMAP_SCALE)
self.tRoot.setShaderInput("region1.max",self.terrainRegions[0].maximum)
self.tRoot.setShaderInput("region1.min",self.terrainRegions[0].minimum)
self.tRoot.setShaderInput("region2.max",self.terrainRegions[1].maximum)
self.tRoot.setShaderInput("region2.min",self.terrainRegions[1].minimum)
self.tRoot.setShaderInput("region3.max",self.terrainRegions[2].maximum)
self.tRoot.setShaderInput("region3.min",self.terrainRegions[2].minimum)
self.tRoot.setShaderInput("region4.max",self.terrainRegions[3].maximum)
self.tRoot.setShaderInput("region4.min",self.terrainRegions[3].minimum)
self.tRoot.setShaderInput("region1ColorMap",0)
self.tRoot.setShaderInput("region2ColorMap",1)
self.tRoot.setShaderInput("region3ColorMap",2)
self.tRoot.setShaderInput("region4ColorMap",3)
self.tRoot.setShader(shader)
self.terrain.update()
here is a screenshot:
and here is the original source code(the TerrainRegion struct and the part in which it sets the variables):
[TerrainRegion struct]
struct TerrainRegion
{
float min;
float max;
GLuint texture;
std::string filename;
};
[var setup]
handle = glGetUniformLocation(g_terrainShader, "tilingFactor");
glUniform1f(handle, HEIGHTMAP_TILING_FACTOR);
// Update terrain region 1.
handle = glGetUniformLocation(g_terrainShader, "region1.max");
glUniform1f(handle, g_regions[0].max);
handle = glGetUniformLocation(g_terrainShader, "region1.min");
glUniform1f(handle, g_regions[0].min);
// Update terrain region 2.
handle = glGetUniformLocation(g_terrainShader, "region2.max");
glUniform1f(handle, g_regions[1].max);
handle = glGetUniformLocation(g_terrainShader, "region2.min");
glUniform1f(handle, g_regions[1].min);
// Update terrain region 3.
handle = glGetUniformLocation(g_terrainShader, "region3.max");
glUniform1f(handle, g_regions[2].max);
handle = glGetUniformLocation(g_terrainShader, "region3.min");
glUniform1f(handle, g_regions[2].min);
// Update terrain region 4.
handle = glGetUniformLocation(g_terrainShader, "region4.max");
glUniform1f(handle, g_regions[3].max);
handle = glGetUniformLocation(g_terrainShader, "region4.min");
glUniform1f(handle, g_regions[3].min);
// Bind textures.
glUniform1i(glGetUniformLocation(g_terrainShader, "region1ColorMap"), 0);
glUniform1i(glGetUniformLocation(g_terrainShader, "region2ColorMap"), 1);
glUniform1i(glGetUniformLocation(g_terrainShader, "region3ColorMap"), 2);
glUniform1i(glGetUniformLocation(g_terrainShader, "region4ColorMap"), 3);