Mutitexturing terrain

Blitz3D Forums/Blitz3D Beginners Area/Mutitexturing terrain

How do you put a racetrack texture on the terrain?
I've been trying to figure out how all day but it isn't working.

Should get you going...

Const TERRAIN_SIZE=16
Graphics3D 800,600,0,2
SetBuffer BackBuffer()
cam=CreateCamera(): PositionEntity cam,(TERRAIN_SIZE*.5)-1,10,-TERRAIN_SIZE
light=CreateLight(1,cam): PositionEntity light,40,40,-40
worldPiv=CreatePivot(): PositionEntity worldPiv,(TERRAIN_SIZE*.5),0,(TERRAIN_SIZE*.5)
EntityParent cam,worldPiv

terrain=CreateTerrain(TERRAIN_SIZE)
TerrainShading terrain,True
For x=0 To TERRAIN_SIZE-1
For z=0 To TERRAIN_SIZE-1
	ModifyTerrain terrain,x,z,Rnd(1,10)
Next
Next

terrainTex=CreateTexture(64,64)
Color 50,100,50
Rect 0,0,64,64,True
Color 70,140,70
For x=0 To 127
	Plot Rand(0,63),Rand(0,63)
Next
CopyRect 0,0,64,64,0,0,BackBuffer(),TextureBuffer(terrainTex)
EntityTexture terrain,terrainTex,0,0

trackTex=CreateTexture(256,256)
Color 255,255,255
Cls
Oval 0,0,255,255,False
CopyRect 0,0,256,256,0,0,BackBuffer(),TextureBuffer(trackTex)
EntityTexture terrain,trackTex,0,1
ScaleTexture trackTex,TERRAIN_SIZE,TERRAIN_SIZE
TextureBlend trackTex,3

PointEntity cam,worldPiv

While Not KeyHit(1)
	TurnEntity worldPiv,0,1,0
	RenderWorld
	Flip
Wend


Thanks, that code works great, but when I tried to add in my racetrack texture, instead of the created texture, it tiled it across the whole terrain.

The quick solution is to use multitexturing. Although, the resolution of the track will be low this way.
I think a racetrack should not be made with a simple texture, but with an additional track mesh. Maybe you can create yourself some kind of Track tiles set so you can build your tracks with a simple editor. Just make sure they are tiling nicely.

Ok but what if I want to make dirt ground turn into desert?

Not sure what you mean. BTW make sure your track texture uses the same size as the created one.


when I tried to add in my racetrack texture, instead of the created texture, it tiled it across the whole terrain



You see that line in the code I posted where the track texture is scaled by the size of the terrain? That's the answer... if your terrain is sized at 128x128, for example, then scale the texture by 128 along both axes to have it fit exactly. (Note it's the UV's you're scaling, not the pixel resolution of the texture... that doesn't matter.)

EDIT: Brain spasm.