PureBasic Terrain.png

Started by Pfaber11, October 21, 2019, 18:41:00

Previous topic - Next topic

Pfaber11

Good evening I'm back again still no terrain . I feel I'm nearly there but would be happy if some kind soul could explain where I'm going wrong . It runs ok up to addmateriallayer , then create terrain , then build terrain . when debugged the all return a 0 . why I don't know .I have tried using different sized .png files and it makes no difference . Anyway here's the code as it stands . I have no idea why it won't work but you might . Thanks for reading .
UsePNGImageDecoder()
UsePNGImageEncoder()

InitEngine3D()
InitSprite()
InitKeyboard()
Add3DArchive("C:/Users/pfabe/Documents",#PB_3DArchive_FileSystem)
OpenScreen(1366,768,32,"")
Debug LoadTexture(1,"blue.png")
Debug LoadTexture(2,"paulstree.png")
Debug LoadImage(4,"amaze12.png")
Debug CreateMaterial(4, TextureID(1))
Debug AddMaterialLayer(4, TextureID(2))
Debug CreateTerrain(4, 513,10240,1,2,"terrain", "dat")
Debug BuildTerrain(4)
CreateCamera(0,0,0,100,100)
CameraLookAt(0,100,10,2000)
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
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

By the way blue.png and paulstree.png are both 512x512 and amaze12.png is 2048x2048. Don't know if that makes any difference . could it be a problem with the .png format ? not sure . will keep experimenting while I wait for the answers hopefully . Thanks for taking the time to read this .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

Coder Apprentice

#2
Just by looking at your code, I see you did not setup the terrain by the SetupTerrains() function. If you read the manual it tells you at the CreateTerrain() function that SetupTerrains() has to be called before you use it. By checking out SetupTerrains() you would also see that you have to define a light and assign it to the terrain. It's in that bare minimum terrain code I posted in the other terrain topic you created.

Pfaber11

Hey thanks Kris I'm onto it . I've been using the pure basic book from version 4 and I think there's been a few changes since then.
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

#4
The only one giving me a debug 0 now is BuildTerrain(0) so must be nearly there . Here's the amended code . I just want to know if I'm doing something really stupid. Does anybody know of a good book on Pure Basic I've got 3 of them
PureBasic a begginers guide
PureBasic Reference Manual 2019
And Programming 2D scrolling Games for Pure Basic 5

PureBasic a begginers guide would be great but I think it's changed a bit since it was written for PB 4
Any way could anybody suggest a recent manual or tutorial . Thanks for reading.
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
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

Well I just junked all my code on building a terrain . I think I was doing things in the wrong order . I'll be laughing at this in a couple of weeks . Gonna start with a fresh sheet . I know more about what I'm doing now . onwards and upwards . Thanks for all the code and advice . Happy coding
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

#6
just been going over my code and i'm trying to load my main terrain base as an image file is this correct if not where do I put it to be used . thanks for reading. its the amaze12.png file i'm referring to. 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

Well I've got a bit further I now have something on the screen although not really what I expected . Gonna start again tonight with a fresh sheet.  Have been missing out the create material bit . Hopefully this time around I'll get it right .  been at it a few days now . 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

Pfaber11

Good afternoon just a couple of questions. firstly what is the difference between a texture and a material. or are they both the same. some terrain tutorials say add material layer others add texture.
I have managed to get my terrain onto the screen but it manifests itself as a 2d image of one of my height maps as a square in the middle of the screen . what is going on ? Any suggestions would be quite useful at this point . 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

Steve Elliott

It might be best to also ask on the official Pure BASIC Forum too.   :)
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Pfaber11

Yeah thanks Steve. I'll work it out eventually.
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

#11
Quote
what is the difference between a texture and a material. or are they both the same. some terrain tutorials say add material layer others add texture.

a material is a group of things / properties applied to a surface

a mesh can have one/several surface(s)

a surface is made of vertices and triangles

a material has usually these properties :
color
alpha
blend
fx
texture(s) (there can be several textures (one above of an other, and blended with the below one as you define it)

(just in case : a material is called a brush in Blitz3d)

a texture is only made of texels with color/alpha properties. usually it must be "power of two" meaning its width and its height must be of a size of 2 or 4 or 8 or 16 or 32 or 64 or 128 or 256 or 512 or 1024 or 2048 etc, and you use UVs to set how the texture is applied on the surface (which texels in which triangles)

on a terrain, usually you can have a color layer (full texture) (with a texel size each 1.0unit) and a detail layer (tiled texture) (with a texel size really small like each 0.01unit)

Pfaber11

Thanks RemiD I'll get this sorted eventually. Been at it a few days now and am pretty pissed off with it. I think the examples in the book I've been reading are pretty useless and very different to what's in the examples that come with pure basic. Way to complicated. But maybe that's as simple as they could make them . Anyhow I shall persist. 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

Steve Elliott

Yes that's the problem when the language changes so much over time.  I have 2 books on Pure BASIC and neither would compile code today, online sources are your best bet.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

RemiD

maybe, to understand the concept, do some experiments with Blitz3d (quite simple, several code examples) or AGK, then try to convert in purebasic.