SyntaxBomb - Indie Coders

Languages & Coding => PureBasic => Topic started by: Pfaber11 on October 21, 2019, 06:41:00 PM

Title: PureBasic Terrain.png
Post by: Pfaber11 on October 21, 2019, 06:41:00 PM
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 .
Code: [Select]
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
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 21, 2019, 06:48:07 PM
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 .
Title: Re: PureBasic Terrain.png
Post by: Kris on October 21, 2019, 09:49:06 PM
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.
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 21, 2019, 10:00:36 PM
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.
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 21, 2019, 10:50:46 PM
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.
Code: [Select]
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
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 22, 2019, 01:19:49 PM
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
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 22, 2019, 04:30:55 PM
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
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 23, 2019, 08:43:24 PM
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 .
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 24, 2019, 04:39:57 PM
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.
Title: Re: PureBasic Terrain.png
Post by: Steve Elliott on October 24, 2019, 04:41:35 PM
It might be best to also ask on the official Pure BASIC Forum too.   :)
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 24, 2019, 05:16:01 PM
Yeah thanks Steve. I'll work it out eventually.
Title: Re: PureBasic Terrain.png
Post by: RemiD on October 24, 2019, 05:29:20 PM
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)
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 24, 2019, 06:48:40 PM
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.
Title: Re: PureBasic Terrain.png
Post by: Steve Elliott on October 24, 2019, 07:01:01 PM
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.
Title: Re: PureBasic Terrain.png
Post by: RemiD on October 24, 2019, 07:16:44 PM
maybe, to understand the concept, do some experiments with Blitz3d (quite simple, several code examples) or AGK, then try to convert in purebasic.
Title: Re: PureBasic Terrain.png
Post by: Kris on October 24, 2019, 08:42:11 PM
Older documentation is good for having a kind of reference of techniques but in a case of PureBasic you constantly need to check everything if it has changed or not. In your case, you should rely more on the combination of the supplied sample codes (there are at least 8 material focused samples) and the built in help witch is pretty good. For example the answer to your question is right there in the help file just at the beginning of the material chapter.

"Materials are composed of one or several textures and sometimes of some colors. They are widely used by the other objects of the 3D world like the entities, billboards and particles to give them a skin. Each material has a lot a properties like the shading, ambient and specular color, etc. to allow realistic looking material like wood, water, glass and more."

Studying the material command index below can give you an idea how the whole thing works. Check out all the material focused samples. Trying to learn from a book that hasn't been updated can give you a lot of unnecessary frustration.
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 25, 2019, 12:18:28 PM
I think I understand the terrain problem now . When I create a terrain I have a blank screen with a square in the middle . Been experimenting and the problem seems to be the files I'm using . I was just using any old .png files that were square 512x512 in size . And the map I was using was from my maze game at 2048x2048  which was a 2d map used for a height map. This I think is where the problem lies . This is way more complex than I am used to in AGK with height maps . Any way I think I nearly understand this stuff but a bit confused about needing 7 pics for a terrain as in desert07.zip in the examples . I've been over this many times and it seems you can't throw just any file in there and it'll work. Thanks for reading any further advice about suitable files would be most welcome .
Title: Re: PureBasic Terrain.png
Post by: Kris on October 25, 2019, 04:03:11 PM
The desert.zip pack contains 6 pictures named desert07_BK, desert07_DN, desert07_FR, desert07_LF, desert07_RT, desert07_UP, that are used for the SkyBox() that generates a cube object with 6 sides and assigns each picture as a texture to it's respective side of the cube.   
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 25, 2019, 04:55:37 PM
nice one Kris will have a play with that. I've really gotta make this work . thanks
Title: Re: PureBasic Terrain.png
Post by: RemiD on October 25, 2019, 06:09:12 PM
what i have described about material properties is the old way to render, now materials have others properties/textures, like normalmap, specularmap, emissive, etc... as Kris mentionned...
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 25, 2019, 09:36:33 PM
Well I've got the skybox thing nailed so got something to play with now . My first bit of success in days . I was expecting to be a few days on this part of the learning curve . Gotta nail the terrain over the weekend then I'll hopefully know enough to start a project .
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 26, 2019, 09:24:09 AM
I have tried using the terrain files from the textures nvidia folder but all I get are black squares which are floating and no terrain. Does this sound familiar? I really can't see what I'm doing wrong .
Title: Re: PureBasic Terrain.png
Post by: RemiD on October 26, 2019, 10:58:56 AM
would this help if i post a simple code example (with comments) on how to make a terrain with a color texture + a detail texture (for Blitz3d) ?
(if you want to understand the concept)
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 26, 2019, 05:54:39 PM
It might do can't hurt to take a look . I have no idea why what I'm doing is not working . I'm even using the example files . I've been over it so many times . Thanks
Title: Re: PureBasic Terrain.png
Post by: RemiD on October 26, 2019, 06:35:57 PM
maybe your problem is not that you are doing something wrong but that your gpu is too old/crap and not compatible with the rendering way of ogre (the graphics engine that purebasic apparently uses) ?
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 26, 2019, 07:11:03 PM
You Know I would agree with you but it runs the examples . I have no problem with producing Entities and displaying them on the screen and moving them about and detecting collisions . It's just the terrain . I might put the code up again to see if anybody can tell me where I'm going wrong . In fact I'll do that now.
 Here it is maybe if I stare at it long enough it'll work
.
Code: [Select]
UsePNGImageEncoder()
UseJPEGUsePNGImageDecoder()
ImageDecoder()
UseJPEGImageEncoder()
#CameraSpeed =  2
  InitEngine3D() 
  InitSprite()
  InitKeyboard()
  InitMouse()
  OpenScreen(1366,768,32,"")
    Add3DArchive("C:/Users/pfabe/Documents/Textures", #PB_3DArchive_FileSystem)
    Add3DArchive("C:/Users/pfabe/Documents/nvidia", #PB_3DArchive_FileSystem)
    Add3DArchive("C:/Users/pfabe/Documents/New folder", #PB_3DArchive_FileSystem)
    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))
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0,  800, 400, 80,#PB_Absolute)
    SetupTerrains(LightID(Light), 3000, #PB_Terrain_NormalMapping)
   Debug CreateTerrain(0,513, 12000, 600, 3 , "TerrainGroup", "dat") 
   Debug AddTerrainTexture(0,0,100,"paul1.jpg", "paul2.jpg" )
  Debug  AddTerrainTexture(0,1,30,"paul3.jpg" , "paul4.jpg")
  Debug AddTerrainTexture(0,2,200,"paul5.jpg" , "paul6.jpg")
      DefineTerrainTile(0,0,0, "amaze12.png", #False, #True) 
 
    BuildTerrain(0)   
     
   
    SkyBox("desert07.png")
    Repeat   
      If ExamineKeyboard()           
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -5
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = 5
        Else
          KeyX = 0
        EndIf     
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -5
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = 5
        Else
          KeyY = 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)) + 20, CameraZ(0), #PB_Absolute)
      MoveCamera  (0, KeyX, 0, KeyY)
      RotateCamera(0,  MouseY, MouseX, 0, #PB_Relative)   
      RenderWorld()
      FlipBuffers() 
    Until KeyboardPushed(#PB_Key_Escape)     
    End   
   
 
 
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 26, 2019, 10:00:30 PM
@ RemiD you were very nearly correct but it turned out to be the other way around . I had to download DirectX 9.0c for it to run so in effect I had to downgrade my system. Anyway all working now . Thanks for making me take a look at my system. And thanks to you Kris for all your help . They could of told me this on the official PureBasic forum but there you go got it sorted in the end . happy coding

I'm now going to go and try and make my own hight map now thanks for again for the help. Only thing bugging me now is will my programs run on a new system . Hmm what do you think Kris is this a problem?
Title: Re: PureBasic Terrain.png
Post by: RemiD on October 26, 2019, 11:26:29 PM
Quote
ou were very nearly correct but it turned out to be the other way around . I had to download DirectX 9.0c for it to run so in effect I had to downgrade my system.
oh, good. maybe it is not downgrading but rather installing missing (old) libs... now you can continue to experiment, good luck !
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 27, 2019, 12:42:51 AM
Yes you're right missing old bits . I was preparing to admit to myself I couldn't do it but there you go if it wasn't for that directx thing I would of sorted the terrain thing a lot quicker . So glad I didn't give up . I know the terrain code backwards by now so maybe  not such a bad thing . I can't believe the people on the PureBasic website didn't mention this to me and if you hadn't said my computer might not be up to it and got me to look more closely at the required specifications I would probably of gone nuts by now. I've been at the pure basic for about two weeks now and no how to do nearly as much as over a year using AGK .
In some things Pure Basic is easier than AGK2 for example colliding objects in 3D Pure Basic wins out in that respect . For height maps AGK wins . so far anyway. I would put my latest code up that now works but I doubt anybody would like to see it although for someone starting out it might prove useful. I'll leave it for now but if anybody asks I'll be happy to share.
 Happy coding .
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 27, 2019, 10:01:23 AM
Hi Naughty Alien thanks for your input too. Pure Basic has got to be one of the best basics around . Can't wait to get something published with it. Still got plenty to learn but I've got the basics of 3D and 2D game creation coming along nicely . It's what I call a proper Basic  with a modern twist . Really can't believe how quickly I've picked it up . Had a few hiccups but I'm doing very well for 2 weeks in . when I was learning the python using pygame the graphics used to judder a bit and that I found unacceptable none of that with pure basic or AGK2 . Panda3D would of been what I'd be using for the 3D programming in python  and that seemed very uninviting and complicated.
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 27, 2019, 07:09:51 PM
Hi going a bit off topic here but I know PureBasic uses the Ogre 3D engine  but I read somewhere that you can also use openGL
is this true and Directx 9.0c . I know I'm using Ogre and Directx 9.0c and am I also using openGL . What is the relationship here. Thanks for reading . Happy coding.   
    well I've taken a day off from coding today 16 days after downloading purebasic . it really couldn't of gone much better. did get stuck for a couple of days on terrain building but discovered the problem and now all is sweet. it turned out to be a lack of directx 9.0c which was stopping some of the terrain stuff from working. free download 10 minutes and sorted once the problem was identified . happy coding. out
Title: Re: PureBasic Terrain.png
Post by: Pfaber11 on October 29, 2019, 12:03:22 PM
Well I've been learning more and now have bumpy terrain with gliding over it very similar programming to AGK to move over the hills . works flawlessly too. I am coming to the conclusion that purebasic is no harder to learn than AGK classic once you get the ball moving . I got my textures for my terrain by photographing a rug very close up and it works a treat tried a rough stone brick as well but wasn't as good . Thanks for reading .
SimplePortal 2.3.6 © 2008-2014, SimplePortal