Page 1 of 1

Keeps saying texture invalid

Posted: Wed Oct 16, 2019 9:12 am
by pfaber11
Hi Guys been stuck on this a couple of days . Tried everything I can think of . keeps saying texture invalid . Here's the offending code . If you could steer me in the right direction I would be grateful . Thanks for reading .

Code: Select all

InitEngine3D()
InitKeyboard()

InitSprite()

OpenScreen(1366,768,32,"my screen")


Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models", #PB_3DArchive_FileSystem)
LoadMesh(1,"barrel.mesh")
LoadTexture(2,"spheremap.png")

 CreateMaterial(1,2) 
 
        CreateEntity(2,1,0,  60, 0, 0)

CreateCamera(0, 50,50, 100,150)
It gets to create material and that's where it falls down. I have tried using my own mesh's and textures as well as ones from the help files .

Re: Keeps saying texture invalid

Posted: Wed Oct 16, 2019 10:47 am
by #NULL
- Did you check the return value of functions? What does LoadTexture() return?
- You also need to use TextureID() instead of just the texture number at CreateMaterial()
- Similarly at CreateEntity() you need to use MeshID(1) and MaterialID(1) and also your material number is 1, not 0.

Code: Select all

InitEngine3D()
InitKeyboard()

InitSprite()

;OpenScreen(1366,768,32,"my screen")
OpenWindow(0, 0,0,1366,768,"")
OpenWindowedScreen(WindowID(0),0,0,1366,768)

Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models", #PB_3DArchive_FileSystem)
Debug LoadMesh(1,"barrel.mesh")
Debug LoadTexture(2,"spheremap.png")

Debug CreateMaterial(1,TextureID(2))
Debug CreateEntity(2, MeshID(1), MaterialID(1),  60, 0, 0)

CreateCamera(0, 50,50, 100,150)

Re: Keeps saying texture invalid

Posted: Wed Oct 16, 2019 11:05 am
by pfaber11
Thanks for the input #null I'll try again . Driving me mad but I'll get there . Thanks for the advice.

Re: Keeps saying texture invalid

Posted: Wed Oct 16, 2019 11:43 am
by spikey
pfaber11 wrote:Driving me mad but I'll get there
There is a subtle but important idiosyncracy that you should be aware of:-

PureBasic maintains its own list of identifying numbers to various objects. These are referred to as #Object, or 'some object' number. (This also applies to the the dynamic numbering value #PB_Any although that is a variation in its own right).

Additionally the operating system maintains its own list of identifying numbers to objects. The help file refers to these as IDs or handles.

Some functions work with object numbers some with IDs. Supplying the wrong type as an argument will stop things working or generate runtime errors (as you've just discovered). This caveat particularly applies to the graphics libraries.

I strongly recommend you read these articles from the help file:
https://www.purebasic.com/documentation ... jects.html
https://www.purebasic.com/documentation ... ndles.html

Re: Keeps saying texture invalid

Posted: Wed Oct 16, 2019 11:50 am
by pfaber11
Hi I'm back again it's saying texture not initialised . What does that mean ? This is how my code is looking now . It gets as far as create material. on the debug screen it says 0 0

Code: Select all

InitEngine3D()
InitKeyboard()

InitSprite()
OpenWindow(0, 0,0,1366,768,"")
OpenWindowedScreen(WindowID(0),0,0,1366,768)

Add3DArchive(#PB_Compiler_Home + "C:/Documents/AGKProjects/fantasy flight simulator/media", #PB_3DArchive_FileSystem)
Debug LoadMesh(1,"paulstree.mesh")
Debug LoadTexture(1,"paulstree.png")

Debug CreateMaterial(1,TextureID(1))
Debug CreateEntity(2, MeshID(1), MaterialID(1),  60, 0, 0)

CreateCamera(0, 50,50, 100,10)

begin:
WindowEvent3D()
ExamineKeyboard() 
If KeyboardPushed(#PB_Key_Return) 
  End
EndIf
RotateCamera(0,10,0,0)
;RotateEntity(2,0,1,0)
RenderWorld()
FlipBuffers()

Goto begin

Re: Keeps saying texture invalid

Posted: Wed Oct 16, 2019 12:01 pm
by spikey
This:

Code: Select all

#PB_Compiler_Home + "C:/Documents/AGKProjects/fantasy flight simulator/media"
will resolve to:

Code: Select all

C:\Program Files\PureBasic\C:/Documents/AGKProjects/fantasy flight simulator/media
which makes no sense at all!

Re: Keeps saying texture invalid

Posted: Wed Oct 16, 2019 5:16 pm
by pfaber11
Thanks that was just what I needed . All working now .