January 28, 2020, 02:52:45 PM

Author Topic: Pure Basic How to use a height map for terrain  (Read 1090 times)

Offline Pfaber11

  • Sr. Member
  • ****
  • Posts: 476
  • Bonjour
    • FABERSGAMES
Pure Basic How to use a height map for terrain
« on: October 19, 2019, 12:58:38 PM »
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 .
Celeron N3060 1.6 ghz duel core  4 Gb ram 32 gig storage  HD400 Graphics 160 gig external hard drive....

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1037
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Naughty Alien

  • Hero Member
  • *****
  • Posts: 679
Re: Pure Basic How to use a height map for terrain
« Reply #2 on: October 19, 2019, 02:56:17 PM »
Code: [Select]
    ;- 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)

Offline Pfaber11

  • Sr. Member
  • ****
  • Posts: 476
  • Bonjour
    • FABERSGAMES
Re: Pure Basic How to use a height map for terrain
« Reply #3 on: October 19, 2019, 10:34:35 PM »
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 .
Code: [Select]
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()
Celeron N3060 1.6 ghz duel core  4 Gb ram 32 gig storage  HD400 Graphics 160 gig external hard drive....

Offline Pfaber11

  • Sr. Member
  • ****
  • Posts: 476
  • Bonjour
    • FABERSGAMES
Re: Pure Basic How to use a height map for terrain
« Reply #4 on: October 19, 2019, 10:48:20 PM »
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 .
Celeron N3060 1.6 ghz duel core  4 Gb ram 32 gig storage  HD400 Graphics 160 gig external hard drive....

Offline Pfaber11

  • Sr. Member
  • ****
  • Posts: 476
  • Bonjour
    • FABERSGAMES
Re: Pure Basic How to use a height map for terrain
« Reply #5 on: October 20, 2019, 03:36:13 PM »
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.
Celeron N3060 1.6 ghz duel core  4 Gb ram 32 gig storage  HD400 Graphics 160 gig external hard drive....

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1037
Re: Pure Basic How to use a height map for terrain
« Reply #6 on: October 20, 2019, 05:36:03 PM »
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
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Kris

  • Jr. Member
  • **
  • Posts: 91
Re: Pure Basic How to use a height map for terrain
« Reply #7 on: October 20, 2019, 06:46:34 PM »
Fabe, you could take the simplest terrain example and just take out all the extra bits one by one. That's what i did.


Code: [Select]


  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
     

Offline Pfaber11

  • Sr. Member
  • ****
  • Posts: 476
  • Bonjour
    • FABERSGAMES
Re: Pure Basic How to use a height map for terrain
« Reply #8 on: October 20, 2019, 07:23:21 PM »
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 .
Code: [Select]
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)
Celeron N3060 1.6 ghz duel core  4 Gb ram 32 gig storage  HD400 Graphics 160 gig external hard drive....

Offline Pfaber11

  • Sr. Member
  • ****
  • Posts: 476
  • Bonjour
    • FABERSGAMES
Re: Pure Basic How to use a height map for terrain
« Reply #9 on: October 20, 2019, 07:26:30 PM »
Hi Kris yes I am trying your approach of taking the necessary code and dumping the rest to try and simplify things .
Celeron N3060 1.6 ghz duel core  4 Gb ram 32 gig storage  HD400 Graphics 160 gig external hard drive....

Offline Kris

  • Jr. Member
  • **
  • Posts: 91
Re: Pure Basic How to use a height map for terrain
« Reply #10 on: October 20, 2019, 08:52:20 PM »
Fabe, check out my code.  It works and it's kinda the bare minimum.

Offline Pfaber11

  • Sr. Member
  • ****
  • Posts: 476
  • Bonjour
    • FABERSGAMES
Re: Pure Basic How to use a height map for terrain
« Reply #11 on: October 21, 2019, 09:34:47 AM »
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 .
Celeron N3060 1.6 ghz duel core  4 Gb ram 32 gig storage  HD400 Graphics 160 gig external hard drive....

Offline Pfaber11

  • Sr. Member
  • ****
  • Posts: 476
  • Bonjour
    • FABERSGAMES
Re: Pure Basic How to use a height map for terrain
« Reply #12 on: October 30, 2019, 12:17:00 PM »
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 .
Celeron N3060 1.6 ghz duel core  4 Gb ram 32 gig storage  HD400 Graphics 160 gig external hard drive....

Offline Pfaber11

  • Sr. Member
  • ****
  • Posts: 476
  • Bonjour
    • FABERSGAMES
Re: Pure Basic How to use a height map for terrain
« Reply #13 on: October 31, 2019, 02:21:07 PM »
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
Celeron N3060 1.6 ghz duel core  4 Gb ram 32 gig storage  HD400 Graphics 160 gig external hard drive....

Offline Pfaber11

  • Sr. Member
  • ****
  • Posts: 476
  • Bonjour
    • FABERSGAMES
Re: Pure Basic How to use a height map for terrain
« Reply #14 on: November 02, 2019, 09:38:44 AM »
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 .   
Celeron N3060 1.6 ghz duel core  4 Gb ram 32 gig storage  HD400 Graphics 160 gig external hard drive....