Page 1 of 1

Not run (dll and window3d)

Posted: Sat May 03, 2014 12:33 pm
by slagusev
Create DLL

Code: Select all

ProcedureDLL win3d(Height.i, Width.i, Title.s)
If OpenWindow3D(0, 100,100,Height.i,Width.i,Title.s)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event3D_CloseWindow
Quit =1
EndIf
Until Quit = 1
EndIf
EndProcedure
Use in prog.

Code: Select all

If OpenLibrary(0, "win3d.dll")
CallFunction(0, "win3d", 800, 600, @"3D View")
CloseLibrary(0)
EndIf
Run -> [ERROR] Invalid memory access. (Write error at adress 9)

how to solve the problem?

Re: Not run (dll and window3d)

Posted: Sat May 03, 2014 3:43 pm
by IdeasVacuum
The error is caused by @"3D View"
Use @ to reference a pre-defined string:

Code: Select all

Define sMyString.s = "3D View"
CallFunction(0, "win3d", 800, 600, @sMyString)
Not sure the DLL will actually work though, since mostly the 3D stuff is dependent on a lib.

Re: Not run (dll and window3d)

Posted: Sat May 03, 2014 3:54 pm
by TI-994A
Hi slagusev. The OpenWindow3D() function is more complex than PureBasic's standard OpenWindow(). In order to use it, the 3D engine has to be initialised, along with the sprite, keyboard and mouse environments, and it will only work within a screen. Furthermore, the 3D GUI elements have to be loaded using the Add3DArchive() function, with the path properly set. Here's an example adapted from PureBasic's help file:

(win3D.dll)

Code: Select all

ProcedureDLL win3D(width, height, title.s)
  Enumeration 
    #MainWindow
    #Window3D
    #Button3D
  EndEnumeration
  
  If InitEngine3D() And InitSprite() And InitKeyboard() And InitMouse()
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/GUI", #PB_3DArchive_FileSystem)
    wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
    OpenWindow(#MainWindow, 0, 0, width, height, "OpenWindow3D() Example", wFlags)
    OpenWindowedScreen(WindowID(#MainWindow), 0, 0, width, height, 0, 0, 0)
    CreateCamera(0, 0, 0, 100, 100)
    OpenWindow3D(#Window3D, 10, 10, 300, 100, "The 3D Window...")
    ButtonGadget3D(#Button3D, 150, 40, 120, 25, "Quit")
    ShowGUI(200, 1)
    alive3D = 1
    Repeat
      If ExamineKeyboard() And ExamineMouse()
        Input$ = KeyboardInkey()
        If alive3D
          InputEvent3D(MouseX(), MouseY(), MouseButton(#PB_MouseButton_Left), Input$, 0)
        EndIf
      EndIf
      Repeat
        Event = WindowEvent3D()
        Select Event
          Case #PB_Event3D_CloseWindow
            ShowGUI(128, 0)
            CloseWindow3D(#Window3D)
            SetWindowTitle(#MainWindow, "3D window closed - press ESC to end...")
            alive3D = 0
          Case #PB_Event3D_Gadget
            appQuit = 1
        EndSelect
      Until Event = 0
      RenderWorld()
      FlipBuffers()    
    Until KeyboardPushed(#PB_Key_Escape) Or appQuit = 1
  EndIf
EndProcedure
(the test code)

Code: Select all

If OpenLibrary(0, "win3D.dll")
  CallFunction(0, "win3D", 640, 480, @"OpenWindow3D() Example")
  CloseLibrary(0)
EndIf
Hope it helps! :D