Page 1 of 1

Screen opens for only a few seconds.

Posted: Sun May 15, 2022 9:12 pm
by pfaber11
Good Evening I am pretty new to this in PureBasic. I really don't see what is wrong with my code and was hoping somebody could take a look and hopefully explain where I'm going wrong . I have migrated from App Game Kit Studio and about 3 years ago I did write a small game in PureBasic but although I know a little about PureBasic I'm very much starting from the beginning . I've been at this for 3 weeks so far and I really have to succeed.
Here is the code which opens for about 4 seconds then quits for some reason .

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
UsePNGImageDecoder()
UsePNGImageEncoder()
Add3DArchive("3darchive", #PB_3DArchive_FileSystem)


OpenScreen(1920,1080,32,"3db",#PB_Screen_NoSynchronization,60)

RenderWorld()
FlipBuffers()
LoadMesh(1,"window_dae.mesh")
LoadTexture(1,"hellow.png")
CreateMaterial(1,1)
CreateEntity(1,MeshID(1),MaterialID(1))
CreateCamera(1,0,0,100,100)
CreateLight(1,RGB(255,255,255),10,5,5)
CameraRange(1,1,1000)
CameraBackColor(1,#Green)
MoveEntity(1,10,10,10,#PB_Absolute)
CameraLookAt(1,10,10,10)
FlipBuffers()
Repeat
  
  CameraBackColor(1,#Green)
  
  If KeyboardPushed(#PB_Key_Escape)
    End 
    EndIf
 
  FlipBuffers()
ForEver
End
could somebody please take a look and point me in the right direction . thanks for reading .

Re: Screen opens for only a few seconds.

Posted: Mon May 16, 2022 1:50 pm
by Ampli
Hello, Something like this maybe...

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

OpenScreen(1920,1080,32,"3db",#PB_Screen_NoSynchronization,60)
UsePNGImageDecoder()
UsePNGImageEncoder()
Add3DArchive("3darchive", #PB_3DArchive_FileSystem)

LoadMesh(1, "window_dae.mesh")
LoadTexture(1,"hellow.png")
CreateMaterial(1, TextureID(1))
CreateEntity(1,MeshID(1),MaterialID(1))
CreateCamera(1,0,0,100,100)
CreateLight(1,RGB(255,255,255),10,5,5)
CameraRange(1,1,1000)
CameraBackColor(1,#Green)
MoveEntity(1,10,10,10,#PB_Absolute)
CameraLookAt(1,10,10,10)

Repeat

	RenderWorld()
  	
  	ExamineKeyboard()
  	
  	If KeyboardPushed(#PB_Key_Escape)
    		End 
    	EndIf
 
 Delay(1) :  FlipBuffers()
ForEver

Re: Screen opens for only a few seconds.

Posted: Mon May 16, 2022 7:48 pm
by pfaber11
Thanks I managed to get it working . Never used a debugger before but with it's help I was able to pick out the errors . Now I have something working I feel a lot better . The ups and downs(when nothing seems to work) of programming . Thanks again for your help. The entity I have turning and twisting about looks very smooth . Next it's text on the screen to tackle (failed at this so far but I'll nail that tommorow hopefully).

Re: Screen opens for only a few seconds.

Posted: Mon May 16, 2022 10:30 pm
by pfaber11
Hi I fixed it in the end . Thanks for the replies .

Re: Screen opens for only a few seconds.

Posted: Tue May 17, 2022 7:54 am
by Shardik
pfaber11 wrote: Mon May 16, 2022 10:30 pm Hi I fixed it in the end . Thanks for the replies .
It would be nice if you would have posted the solution to your original problem for those that might have the same problem. Or you might have posted a link to your parallel thread at the syntaxbomb forum which contains several helpful comments.

You have described the solution for your original posting at the top of this PureBasic thread in the syntaxbomb thread:
Pfaber11 wrote:... I did learn now to use the debugger and it was create material that had the problem ...

Re: Screen opens for only a few seconds.

Posted: Tue May 17, 2022 10:28 am
by pfaber11
OK I will post solution ,

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()

UsePNGImageDecoder()
UsePNGImageEncoder()
Add3DArchive("3darchive", #PB_3DArchive_FileSystem)
ExamineDesktops()

OpenWindow(1,0,0,1920,1080,"3db")
OpenWindowedScreen(WindowID(1),0,0,1920,1080)
SetFrameRate(60)
RenderWorld()
FlipBuffers()
LoadMesh(1,"window_dae.mesh")
;LoadTexture(1,"hellow1.png")
CreateMaterial(1,LoadTexture(1,"hellow1.png"))
CreateEntity(1,MeshID(1),MaterialID(1)) 
CreateCamera(1,0,0,100,100)
CreateLight(1,RGB(255,255,255),10,10,1)
CameraRange(1,1,100)
CameraBackColor(1,#Green)

MoveEntity(1,5,10,10,#PB_Absolute)
CameraLookAt(1,5,10,10)
  TextGadget(1,200,200,100,100,"Bonjour")
 
RenderWorld()
a=1
FlipBuffers()
Repeat
  a=a+2
  If a >=360 
    a=1
  EndIf
  b=b+3
  If b>=360
    b=1
    EndIf
  
  RotateEntity(1,a,a,b)
 ExamineKeyboard() 
  If KeyboardPushed(#PB_Key_Escape)
    End
  EndIf
  WindowEvent()
  If WindowEvent()=(#PB_Event_CloseWindow)
    End 
    EndIf
RenderWorld()
  FlipBuffers()
ForEver 

Where it says create material would not work until I altered it and now does work fine . Strange but true the command on the next line up is edited out . I'm hoping PB 6 will be finished when I'm ready to create. Thanks for your time.

Re: Screen opens for only a few seconds.

Posted: Tue May 17, 2022 11:15 am
by pfaber11
Yes indeed I will . I have found it slow in this forum which was why the dual thread . Although a few on syntax bomb use PB . I will come here often and maybe answer some questions when I know exactly what I'm doing.

Re: Screen opens for only a few seconds.

Posted: Wed May 18, 2022 7:56 am
by pfaber11
I intend to visit this forum often and post regularly. Really looking forward to using PureBasic 6 when it is out of beta testing . Have a nice day.