This small and incomplete tutorial will show you how to create a terrain and the texture for the CreateTerrain() function in Purebasic.
Please Note: If you know better tools or something else please don't wait and add your knowledge to this thread !
To show a nice terrain like the one you can see at the Purebasic's Terrain demo you need 2 things:
A terrain and a texture.
To create a terrain you can take one of this tools (i prefer terragen):
http://www.planetside.co.uk/
http://www.tenermerx.com/sc3maped/
You need also a tool to create the texture from the terrain (i prefer terrTexGen).
http://www.delphigl.de/projects/terrtexgen.html
or a PlugIn for Photoshop (i never tested it)
http://developer.nvidia.com/object/nv_t ... tools.html
The terrain:
OK. At first you have to create a terrain and save it as bitmap file.
(Terragen can only save the terrain as raw file - use PaintShop or a similar programm to convert the .raw files to .bmp)
Make sure the size of your terrain is (n*8+1)*(n*8+1) pixel: also 129*129 or 257*257 or 513*513 usw.
IMPORTANT: make sure the file is in 8 bit depth and greyscale. This different greycolors give the altitude information of the terrain.
The texture:
Start TerrTexGen or similar, load the terrain and create the right texture for it (make sure you have about the same size). The programm is very simple and i think it isn't neccessarily to explaint how to do it. TerrTexgen saves the file and bitmap when you press "Generate". Then you take your painting programm again and resize the just saved bitmap texture to the right size (256*256 -> 257*257 usw.)
Move both pictures to you folder and create a programm like this:
Code: Select all
;
#CameraSpeed = 5
IncludeFile "..\Screen3DRequester.pb"
DefType.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
UsePNGImageDecoder()
If Screen3DRequester()
AmbientColor(RGB(255,255,255))
If CreateMaterial (0, LoadTexture(0, "texture12.png"))=0 ;<-- An you texture here
MessageRequester("","Error CreateMaterial",0):End:EndIf
If CreateTerrain("terrain13.png", MaterialID(0), 4, 0.6, 4, 4)=0 ;<-- An you terrain here
MessageRequester("","Error CreateTerrain",0):End:EndIf
CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0, 128, 25, 128)
Add3DArchive("dome.zip",#PB_3DArchive_Zip)
SkyDome("dome1.bmp",0)
Repeat
Screen3DEvents()
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_a)
KeyX = -#CameraSpeed*2
ElseIf KeyboardPushed(#PB_Key_d)
KeyX = #CameraSpeed*2
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_w)
KeyY = -#CameraSpeed*2
ElseIf KeyboardPushed(#PB_Key_s)
KeyY = #CameraSpeed*2
Else
KeyY = 0
EndIf
EndIf
If ExamineMouse()
MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
EndIf
Height.f = TerrainHeight(CameraX(0), CameraZ(0))
RotateCamera(0, MouseX, MouseY, RollZ)
MoveCamera (0, KeyX, -CameraY(0)+Height+8, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
If you take a look to the Purebasic Terrain demo, you will see Fred uses a second texture to show more "details". Unfortunately i couldn't figure out how to create an other one


I hope this small tutorial will help you to use terrains in future.
Have a nice one ... + MFG
WolfgangS