open 3d window

Just starting out? Need help? Post your questions and find answers here.
pfaber11
Enthusiast
Enthusiast
Posts: 145
Joined: Sat Apr 13, 2019 12:17 pm

open 3d window

Post by pfaber11 »

Hi having trouble opening a 3d window here is the code could somebody tell me where I'm going wrong . Thanks for reading .

Code: Select all

; new 3d program
InitEngine3D()
InitKeyboard()
InitSprite()

OpenWindowedScreen(WindowID(0),0,0,1366,768)
OpenWindow3D(0,0,0,1366,768,"3D experiment")

begin:
ClearScreen(#Red)

WindowEvent3D()
FlipBuffers()

ExamineKeyboard()
If KeyboardPushed(#PB_Key_Return)
  End
  EndIf
Goto begin
User avatar
mk-soft
Always Here
Always Here
Posts: 5333
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: open 3d window

Post by mk-soft »

No beginning with Goto and Gosub. It's old and not save...

P.S.
Look more in the help and open the examples in the Example folder of Purebasic...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
pfaber11
Enthusiast
Enthusiast
Posts: 145
Joined: Sat Apr 13, 2019 12:17 pm

Re: open 3d window

Post by pfaber11 »

thanks just found the examples didn't know they were in there.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: open 3d window

Post by #NULL »

- You tried to open a screen on a window that does not exist yet. You first need a normal pb window, then open a screen on the window, then open a 3d window on the screen.
- You must process the events of the normal window
- You must also process separately the events of the 3d window.
- To actually see something on the screen you need to:
- - provide a theme for the 3d gui via Add3DArchive()
- - create and position a camera
- - call RenderWorld()
- To make the mouse cursor work you need:
- - InitMouse()
- - ExamineMouse()
- - pass mouse information to the 3d gui via InputEvent3D()
[- I would also remove the goto and use a normal loop, just for fun]

Code: Select all

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

OpenWindow(0, 100, 100, 800, 600, "window")
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/GUI", #PB_3DArchive_FileSystem)
CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI", #PB_3DArchive_FileSystem)
CompilerEndIf

OpenWindow3D(0, 10, 10, 150, 50,"3D experiment")
;ShowGUI(128, 1)

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 100, 100, #PB_Absolute)

begin:
ClearScreen(#Red)

ExamineMouse()
ExamineKeyboard()

While WindowEvent()
  If Event() = #PB_Event_CloseWindow
    End
  EndIf
Wend

InputEvent3D(MouseX(), MouseY(), MouseButton(#PB_MouseButton_Left))

Repeat
  Event = WindowEvent3D()
  If Event = #PB_Event3D_CloseWindow
    CloseWindow3D(EventWindow3D())
  EndIf
Until Event = 0

If KeyboardPushed(#PB_Key_Return) Or KeyboardPushed(#PB_Key_Escape)
  End
EndIf

RenderWorld()
FlipBuffers()

Goto begin
pfaber11
Enthusiast
Enthusiast
Posts: 145
Joined: Sat Apr 13, 2019 12:17 pm

Re: open 3d window

Post by pfaber11 »

Thanks Addict I wasn't getting on very well with the examples . will work with what you put up this evening . Thanks again.
Post Reply