It is currently Tue Nov 24, 2020 1:44 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Terrain creation
PostPosted: Sat Oct 19, 2019 10:25 pm 
Offline
User
User

Joined: Sat Apr 13, 2019 12:17 pm
Posts: 48
Been busy today trying to get some terrain working . I Haven't had any success yet and am a little dismayed so I am going to post my code here and perhaps someone can tell me where I'm going wrong .
Code:
Debug LoadTexture(6,"mazeblank.png")
Debug LoadTexture(7,"brick.png")
Debug CreateMaterial(8,TextureID(6))
Debug AddMaterialLayer(8,TextureID(7),#PB_Material_Add)

Debug CreateTerrain(0, 513, 12000, 2, 2, "amaze12.png", "dat")
BuildTerrain(0)
RenderWorld()
FlipBuffers()


Top
 Profile  
Reply with quote  
 Post subject: Re: Terrain creation
PostPosted: Sun Oct 20, 2019 1:27 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:34 pm
Posts: 1008
Location: Canada
Not sure what anyone is suppose to do with the code you posted since you can't actually compile it ;)

Why don't you try looking in the folder: "PureBasic/Examples/3D"
Maybe start with "Terrain.pb" to get an idea of how things work then adapt to your need.

_________________
Image Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Terrain creation
PostPosted: Sun Oct 20, 2019 5:38 am 
Offline
Addict
Addict

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1404
Look the concise and simple way to create a terrain in Comtois code here: viewtopic.php?f=36&t=65855&p=526034#p489107


Top
 Profile  
Reply with quote  
 Post subject: Re: Terrain creation
PostPosted: Sun Oct 20, 2019 3:14 pm 
Offline
User
User

Joined: Sat Apr 13, 2019 12:17 pm
Posts: 48
I was thinking maybe someone who knows could explain how to make the most simple of terrains . I don't need any fancy stuff or moving cameras I would just like some very simple terrain and from there I can build on it . Thanks for reading .


Top
 Profile  
Reply with quote  
 Post subject: Re: Terrain creation
PostPosted: Mon Oct 21, 2019 7:10 pm 
Offline
User
User

Joined: Sat Apr 13, 2019 12:17 pm
Posts: 48
Well here is my latest effort and I think I'm getting the idea build terrain is coming up with an 0 using debug and I can't work out why. the terrain is a height map 2048x2048 and the material are 512x512 . they are all .png files but I can't see why this would be a problem . Thanks for reading and please try and help.
Code:
UsePNGImageDecoder()
UsePNGImageEncoder()

InitEngine3D()
InitSprite()
InitKeyboard()
Add3DArchive("C:/Users/pfabe/Documents",#PB_3DArchive_FileSystem)
OpenScreen(1366,768,32,"")

  light = CreateLight(#PB_Any ,RGB(255, 255, 190), 4000, 1200, 1000,#PB_Light_Directional)
    SetLightColor(light, #PB_Light_DiffuseColor, RGB(250,250,230))
    LightDirection(light ,0.55, -0.3, -0.75)
    AmbientColor(RGB(10,10,10))
Debug SetupTerrains(LightID(Light), 3000, #PB_Terrain_NormalMapping)
Debug LoadImage(4,"amaze12.png")
Debug LoadTexture(1,"blue.png")
Debug LoadTexture(2,"paulstree.png")


Debug CreateMaterial(#PB_Any,TextureID(1))
;Debug AddMaterialLayer(#PB_Any, TextureID(2))

Debug CreateTerrain(#PB_Any, 513,600,60,1,"terraingroup", "dat")
Debug BuildTerrain(5)
CreateCamera(0,0,0,100,100)
MoveCamera(0,300,200,200)

CameraLookAt(0,40,10,500)
CameraBackColor(0,#Green)
Repeat
RenderWorld()
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_A)
       
        a=a-2
        RotateCamera(0,0,a,0)
      EndIf
      If KeyboardPushed(#PB_Key_D)
       
        a=a+2
        RotateCamera(0,0,a,0)
      EndIf
      If KeyboardPushed(#PB_Key_W)
        b=0
        b=b+2
        MoveCamera(0,0,0,b)
      EndIf
      If KeyboardPushed(#PB_Key_S)
        b=0
        b=b-2
        MoveCamera(0,0,0,b)
      EndIf
     
    Until KeyboardPushed(#PB_Key_Escape)   
   
    End


Top
 Profile  
Reply with quote  
 Post subject: Re: Terrain creation
PostPosted: Tue Oct 22, 2019 12:26 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1274
Location: right here
Is that name pfabe (without an r) correct in that path?
LoadImage() will look in the current directory (use Debug GetCurrentDirectory() to see) and not use the archives like LoadTexture etc. does.
Also read the doc for BuildTerrain()
Quote:
Before building a terrain, tiles have to be defined with DefineTerrainTile(), and textures added with AddTerrainTexture().


Top
 Profile  
Reply with quote  
 Post subject: Re: Terrain creation
PostPosted: Tue Oct 22, 2019 12:33 pm 
Offline
User
User

Joined: Sat Apr 13, 2019 12:17 pm
Posts: 48
Hi Null yes the directory is correct. Thanks for replying . been at this for two days now . pfabe without the r. It finds the files ok. will take on board what you said and look at it again. Thanks for taking the time to reply .


Top
 Profile  
Reply with quote  
 Post subject: Re: Terrain creation
PostPosted: Thu Oct 24, 2019 5:20 pm 
Offline
User
User

Joined: Sat Apr 13, 2019 12:17 pm
Posts: 48
Well I still haven't got any terrain but I think I'm Getting there. What is the shortest amount of lines to create a terrain .? I really need something simple to start with. A simple height map or small piece of terrain.
I'm finding the examples to be too complicated.


Top
 Profile  
Reply with quote  
 Post subject: Re: Terrain creation
PostPosted: Thu Oct 24, 2019 9:16 pm 
Offline
Addict
Addict

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1404
Quote:
what is the shortest amount of lines to create a terrain

only 5 lines, all the other code is an accessories such as the materials, the camera is essential it is your eyes exactly watching the virtual world
here is the shortest demo, it adapted from terrain.pb from the purebasic 3D example, i have removed many lines, also removing the screenRequester , i have added a very big Sphere in the terrain center. and the camera ie our eyes is looking to it
i have also removed the ability to compile with opengl context to reduce the code size
Code:
; adapted from terrain.pb from 3D examples
#CameraSpeed = 10

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
 
  InitSprite()
  InitKeyboard()
  InitMouse()
 
  OpenWindow(0, 0, 0, 1000, 600, "terrain", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
  OpenWindowedScreen(WindowID(0), 0, 0, 800, 600, 0, 0, 0)


    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/nvidia", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
   
    ;- Light
    ;
    light = CreateLight(#PB_Any ,RGB(190, 190, 190), 4000, 1200, 1000,#PB_Light_Directional)
    SetLightColor(light, #PB_Light_SpecularColor, RGB(255*0.4, 255*0.4,255*0.4))
    LightDirection(light ,0.55, -0.3, -0.75)
    AmbientColor(RGB(255*0.2, 255*0.2,255*0.2))
   
    ;- Camera
    ;
    CreateCamera(0, 0, 0, 100, 100)
    ;MoveCamera(0,  800, 400, 80, #PB_Absolute)
    MoveCamera(0,  896, 502, 5500, #PB_Absolute)
    CameraBackColor(0, RGB(5, 5, 10))
    ;CameraRenderMode(0, #PB_Camera_Wireframe)

    ;- Terrain definition
    SetupTerrains(LightID(Light), 3000, #PB_Terrain_NormalMapping)
    ; initialize terrain
    CreateTerrain(0, 513, 12000, 600, 1, "TerrainGroup", "dat")
    ; set all texture will be use when terrrain will be constructed
    AddTerrainTexture(0,  0, 100, "dirt_grayrocky_diffusespecular.jpg",  "dirt_grayrocky_normalheight.jpg")
    ; Build terrains
    DefineTerrainTile(0, 0, 0, "terrain513.png", 0, 0) 
    BuildTerrain(0) 
   
       
    ; SkyBox
    ;
    SkyBox("desert07.jpg")
   
    CreateMaterial(6, LoadTexture(1, "ValetCoeur.jpg"))
    MaterialCullingMode(6, #PB_Material_NoCulling        )
    sphere = CreateSphere(#PB_Any, 1000)
    sphere = CreateEntity(#PB_Any, MeshID(sphere), MaterialID(6), 0, 400,0 )
   
   
   Repeat
   
    Repeat   
      Event = WindowEvent()
     
      If Event = #PB_Event_CloseWindow  ; If the user has pressed on the close button
        Quit = 1
     
      EndIf 
     
    Until Event = 0

           
      If ExamineKeyboard()       
       
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed
        Else
          KeyX = 0
        EndIf
       
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed
        Else
          KeyY = 0
        EndIf
       
        If KeyboardReleased(#PB_Key_A)
          ; to deremine the current coordinates of the camera
          Debug CameraX(0)
          Debug CameraY(0)
          Debug CameraZ(0)
        EndIf
       
       
      EndIf
     
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      MoveCamera(0, CameraX(0), TerrainHeight(0, CameraX(0), CameraZ(0)) + 60, CameraZ(0), #PB_Absolute)
      MoveCamera  (0, KeyX, 0, KeyY)
      RotateCamera(0,  MouseY, MouseX, 0, #PB_Relative) 
     
      RenderWorld()
      FlipBuffers()
     
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
   
    End


EndIf



Edit: notes:
1- change number 60 in line 101 to 400 and the camera appears as if it is riding a tall Giraffe
2- remove line 101 and the camera will not be restricted to the terrain surface and we can move anywhere, this useful to go high and see the terrain from high altitude
3- DefineTerrainTile(0, tx, ty, "terrain513.png", ty % 2, tx % 2)
the "terrain513.png" is the HeightMap, position the mouse on the function DefineTerrainTile and press F1 to get all the help and info about it
4- number 600 in line 38 is the scale , make it more and we will get more bumpy terrain
6- use another HeightMap such as "Lensflare5.jpg" but change the scale from 600 to 2000 and we will get a volcano
7- you may need to change #CameraSpeed = 10 to more values to speed the camera movement


Top
 Profile  
Reply with quote  
 Post subject: Re: Terrain creation
PostPosted: Sun Oct 27, 2019 1:04 am 
Offline
User
User

Joined: Sat Apr 13, 2019 12:17 pm
Posts: 48
Hi everybody I found out why my code would never run correctly and the answer was it needed Directx 9c to be able to do the terrain stuff . Downloaded this than installed done a restart and bobs your uncle it works . So if you're running windows 10 and having problems with terrain download the older Directx 9c and for me it sorted it . Bonjour .


Top
 Profile  
Reply with quote  
 Post subject: Re: Terrain creation
PostPosted: Sun Oct 27, 2019 9:11 am 
Offline
User
User

Joined: Sat Apr 13, 2019 12:17 pm
Posts: 48
Hi was just wondering what is the best method for making a height map for pure basic.shades of red or shades of grey. I have made many in AGK2 but not sure what the best way to do it with PB. Only been using PB for a couple of weeks and really like it . Really glad I got on board . Great forum too. Thanks for reading .


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye