Pure Basic How to use a height map for terrain

Started by Pfaber11, October 19, 2019, 12:58:38

Previous topic - Next topic

Pfaber11

Well I think the title pretty much says it . I have many height maps that I have previously used in AGK2 so don't need to know that . What I would like to know is how to use one to create a 3D world in Pure Basic . A simple terrain if you like . Can't seem to find much info on it . Thanks for reading .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz


Naughty Alien


    ;- Terrain definition
    SetupTerrains(LightID(Light), 3000, #PB_Terrain_NormalMapping)
    ; initialize terrain
    CreateTerrain(0, 513, 12000, 600, 3, "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")
    AddTerrainTexture(0,  1,  30, "grass_green-01_diffusespecular.jpg", "grass_green-01_normalheight.jpg")
    AddTerrainTexture(0,  2, 200, "growth_weirdfungus-03_diffusespecular.jpg", "growth_weirdfungus-03_normalheight.jpg")
   
    ; Build terrains
    For ty = #TerrainMiniY To #TerrainMaxiY
      For tx = #TerrainMiniX To #TerrainMaxiX
        Imported = DefineTerrainTile(0, tx, ty, "terrain513.png", ty % 2, tx % 2) 
      Next
    Next 
    BuildTerrain(0) 
   
    InitBlendMaps()
    UpdateTerrain(0)

Pfaber11

Well I have not had any success yet . Here is my latest code I have been working on . The examples are not very clear to follow but anyway this is what I came up with . If anyone can see where I'm going wrong I would be most grateful , Thanks for reading .
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()
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

Hi naughty alien had a look at that code and looks pretty complex . I think I am close with that code I put up And I'll be keeping at it until I start getting some results . Looked through the help files and examples but still it alludes me . Anyway have a nice evening and thanks for the response .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

what I would really like is if some kind person could explain how to make the most simplest of terrain without any fancy bits just a plain terrain in as few a lines as possible . I shall not give up and will eventually do it . If anybody could help me along I would be very grateful. Bonjour.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

RemiD

#6
if you want to progress, i suggest that you take the habit to search/read the documentation, search for posts about the same topic/problem on forums, and experiment a little by yourself (that's what i still do today!)
so for your topic/problem :

read the documentation :
www.purebasic.com/documentation/terrain/index.html

search on purebasic forums using google :
www.google.fr/search?q=creating+a+terrain+site%3Apurebasic.fr%2Fenglish%2F
there are many posts about that...

then experiment !

good luck

Coder Apprentice

#7
Fabe, you could take the simplest terrain example and just take out all the extra bits one by one. That's what i did.





  InitEngine3D()
  InitSprite()
  InitKeyboard()
 
 
    OpenWindow(0,x,y,800,600,"Barebone Terrain",#PB_Window_ScreenCentered)
    OpenWindowedScreen(WindowID(0),0,0,800,600)
   

   
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/nvidia", #PB_3DArchive_FileSystem)
   
   
    ; Light
   
    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))
   
    ; Camera
   
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0,  800, 400, 80, #PB_Absolute)
    CameraBackColor(0, RGB(50, 50, 175))
    CameraFOV(0,75)
 
    ; Setup Terrain
   
    SetupTerrains(LightID(Light), 3000, #PB_Terrain_NormalMapping)
    CreateTerrain(0, 513, 6000, 600, 1, "TerrainGroup", "dat")
    AddTerrainTexture(0,  0, 100, "dirt_grayrocky_diffusespecular.jpg",  "dirt_grayrocky_normalheight.jpg")
    DefineTerrainTile(0, tx, ty, "terrain513.png", #False, #False)
   
    ; Build Terrain #0

    BuildTerrain(0) 
   

   
    Repeat
     
      WindowEvent()
      ExamineKeyboard()       
      RenderWorld()
      FlipBuffers()
     
    Until KeyboardPushed(#PB_Key_Escape)   
   
    End
     

Pfaber11

Yes experimentation is happening . Haven't nailed it yet but still trying . Here's my latest attempt . It runs but no terrain as of yet . I was expecting this to take a few days .
UsePNGImageEncoder()
UsePNGImageDecoder()
InitEngine3D()
InitSprite()
InitKeyboard()
Add3DArchive("C:\Users\pfabe\Documents",#PB_3DArchive_FileSystem)
OpenScreen(1366,768,32,"")
CreateCamera(0,0,0,100,100)
CameraLookAt(0,0,0,0)
CameraBackColor(0,#Red)
Debug LoadTexture(1,"brick.png")

Debug CreateMaterial(1,TextureID(1))
Debug LoadTexture(2,"mazeblank.png")

Debug CreateMaterial(2,TextureID(2))

Debug LoadImage(1,"amaze12.png")
ResizeImage(1,10+1,10+1)
StartDrawing(ImageOutput(1))
StopDrawing()
Debug BuildTerrain(0)
RenderWorld()
FlipBuffers()
Delay(10000)
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

Hi Kris yes I am trying your approach of taking the necessary code and dumping the rest to try and simplify things .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Coder Apprentice

#10
Fabe, check out my code.  It works and it's kinda the bare minimum.

Pfaber11

ok  Kris gonna check out your code and have a play with it . I was at the point where this would of been my next task in AGK2 . I had simple height maps working in that but that was pretty much it . Thanks for your help .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

The whole height map thing is different on AGK to pure basic but I have now gone further on in pure basic than I did in AGK . I'm now using proper terrain instead of colored hills and and a special moving background .  All Good .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

#13
I've now got the height map thing down in PB they don't work the same as they do in AGK and both have their merits just depends what you want to do with them .For example to make a 3d maze in AGK with height maps is very easy but I don't see myself using them in that way with PB although the results are very nice just different . I never got around to doing proper textures in AGK but am now quite capable in PB so I've moved on a notch up the ladder . I'm hoping PB will be the last iteration of basic I learn for many years and regard it very highly . Really glad I went back and took another look at it as the first time I looked at it I dismissed it after a short time . It just looked complex to me at that time but like most things once you get to know the syntax and it becomes familiar it all starts to make sense . Some of the things in PB are easier than in AGK like 3d model hit detection its a doddle in PB but not in AGK . For me anyhow . Nobody has asked me which I find to be the better language In all honesty the clear winner is wait for it . It depends whether you want Android compatibility or Brute force . Personally I prefer PB now I've got used to it over the last  2 or 3 weeks . AGK is a great place to start though and I'm glad I started with it . Although I did make a couple of games in Blitz3d before I got AGK2 .
  If I had to learn one language and one only with all the experience I've had over the years PB would easily be the winner with AGK in second place . Third place would probably be Python although I did find it a bit on the slow side . Mind you python is free . But not fast enough for what I want . I think what I'll do is use AGK2 for Android and PB for windows Mac Linux . So there you are I'm now a duel tool user . Bonjour
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

#14
It turns out the height maps pretty much work exactly the same in PureBasic as they do in AGK2 . In PureBasic they need to be shades of red to work whereas in AGK2 I was able to use black and white and shades of grey. Any How there it is got it sorted in the end .

Been playing with height maps all morning all going well . I think I Know all I need to know. All works really well with the skybox . So far very pleased with PureBasic. Will start a new project soon as I'm at that point . I just used to get a language and make a game straight away and overcome the obstacles as they present themselves , this time I took a few weeks to learn the basics first and I'm glad I did . Anyway onward and upward . Bonjour and thanks for reading .   
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz