Screen opens for only a few seconds.

Started by Pfaber11, May 15, 2022, 23:02:54

Previous topic - Next topic

Pfaber11

I'm currently using OpenGL with PureBasic and it seems to work fine . I am hoping it will mean that Directx 9.0c will not be needed in the finished  app. I am eager to get started with PureBasic 6 but not sure how far it has come along . I've got a problem bit of code , the app starts but closes after a few seconds . It's a small bit of code about 30 lines and I'm going to put it up here to see if anybody can help. Thanks for reading .
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(#PB_Any))
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

  a=1
  CameraBackColor(1,#Green)
 
  If KeyboardReleased(#PB_Key_Escape)
    End
    EndIf

  FlipBuffers()
Until a = 2


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

Qube

I assume is just crashing on you. There doesn't look to be anything silly in the Repeat / Until loop. I don't know PureBasic very well but surely if you run the app in debug mode and it crashes it should tell you why?

I do have PB on my PC so I can see what happens when I try your code. Will check later on this evening.
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

STEVIE G

Don't know Purebasic but you sure it isn't KeyboardPressed, rather than released?

ricardo_sdl

Quote from: STEVIE G on May 16, 2022, 16:42:05
Don't know Purebasic but you sure it isn't KeyboardPressed, rather than released?

On PureBasic KeyboardPushed reports nonzero if the key you are checking is currently pushed or pressed, and KeyboardReleased reports nonzero when the player pressed and released the key.
Check my games at:
https://ricardo-sdl.itch.io/

ricardo_sdl

Which compiler version and operating system?
Check my games at:
https://ricardo-sdl.itch.io/

Qube

Had a quick look in PB...

Assuming your model and materials are correct ( double check the error log ) then the next error is your keyboard statement which just locks my PC until the app is closed.

To make the keyboard statement work you need to have the command ExamineKeyboard() before the If statement. Once I did this then the app didn't hang. I did rem out the model / material side as I don't have those.

Overall though if you look at the output that PB does when you run in debug mode it'll tell you what the errors are.
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

Coder Apprentice

#6
CameraBackColor(1,#Green)

What is #Green? You define color with RGB() so it should be something like RGB(0,255,0). Why is the camera background color is in the loop? It seems you just want a loop so the program doesn't quit immediately. I think that could go before the loop. As Qube also pointed out you also need an " ExamineKeyboard()" in the loop before you call any keyboard command. Nothing is changing the value of your "a" variable...so it will be never reach "2"...

Here is a working "loop code" based on yours.

Repeat
 
  a=1
 
  ExamineKeyboard()

  If KeyboardReleased(#PB_Key_Escape)
    a=a+1
  EndIf
 
Until a=2

Pfaber11

Thanks been at this all day and it is working now . I did learn now to use the debugger and it was create material that had the problem . I'm feeling a lot more positive about it now although this is gonna take time . I set myself a target of 3 months to get upto speed with where I left off with AGK studio. I think I can do this . It's taken me 3 years or so to get sort of competent with AGK and although the syntax is different I think
I'm doing ok so far. At least now I'm on my way I have something to build on . I have the incentive to succeed as it cost me 69 quid . Thanks again for all your help . I do actually think PB is good value . My operating system is windows 11 or occasionally linux. I have been using AGK all this time and never used the debugger. very useful and good advice . This forum is way better than the PureBasic forum .   
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

Hi Kris thanks for the input . #Green #Red etc can be used instead of RGB although there is not much choice but for now while I'm getting into it it will do. Thanks again .
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

Didn't know about the #Green constant and the other two colors. Don't know what's the point of either creating or using such constant instead of typing in RGB(0,255,0)...but hey I learned something. Thanks.

Just a few more things with your original code. You only need the PNG decoder to load png image. Encoder is needed when you want to save something in PNG format.  You call RenderWorld() right after you open a screen, before you create any camera, light or load any mesh. RenderWorld() should be the last thing after you do everything you wanted in the 3D world. If you do any drawing like display a sprite between RenderWorld() and FlipBuffers() it will be drawn on top of everything that was before RenderWorld().

You also don't need FlipBuffers() in the loop since no gfx stuff happening.

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(#PB_Any))
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

  a=1
  CameraBackColor(1,#Green)

  If KeyboardReleased(#PB_Key_Escape)
    End
    EndIf

  FlipBuffers()
Until a = 2

Pfaber11

This is my working code.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
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

#11
Evening my small program is not working as good as it should as every time I try and put some text on the screen it puts it under the top screen . models work fine but text no . Hey I really feel like I'm getting somewhere now . Feeling positive. What I am referring to is the word "Bonjour". I've been working on this for hours.
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