PureGDK Open Beta - DarkBasic for PureBasic

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

This is how to embed the DarkBasic render window inside of a PureBasic window.

Code: Select all

OpenWindow(0,0,0,540,380,"Container Window",#PB_Window_SystemMenu|#PB_Window_Invisible)
hDBWnd=OpenDBWnd(0,0,320,240,32,#GDK_Window_BorderLess,WindowID(0))

; Unhide PureBasic window container
HideWindow(0,0)

; Don't lose focus to the new DarkBasic window
SetForegroundWindow_(WindowID(0))

; Do something cool
dbmakeobjectcube(1,3)
dbScaleObject(1,35,35,35)
dbPositionObject(1,-1.65,1.3,0)

Repeat: Delay(1)
	x.f+0.1: y.f+0.3: z.f+0.4
	dbRotateObject(1,x.f,y.f,z.f)
	dbSync()
Until WindowEvent()=#WM_CLOSE
And this is how to make the window full-screen. There is bug that's causing the program to hang when End is called so I'm using ExitProcess_(0) instead. This will be fixed.

Code: Select all

screenw=GetSystemMetrics_(#SM_CXSCREEN)
screenh=GetSystemMetrics_(#SM_CYSCREEN)
hDBWnd=OpenDBWnd(0,0,screenw,screenh,32,#GDK_Window_BorderLess)

; Always on top
SetWindowPos_(hDBWnd,#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOREPOSITION|#SWP_NOSIZE)

i=10
Repeat: Delay(1000)
	dbPrint("This window will close in "+Str(i))
	dbSync()
	i-1
	If i=0
		ExitProcess_(0)
	EndIf
ForEver
sigi
User
User
Posts: 79
Joined: Fri Apr 25, 2003 7:16 pm
Location: Germany

Post by sigi »

Perfect, Thank You. :D
Athlon X2 7850 - Geforce 8800 GTS 640mb - 8 GB Ram - Vista Home Premium 64 bit SP2
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Added a tutorial and examples on how to use the PureGDK framework for adding command libraries for your own plugins.

See the second post for links and information.
darryl_bartlett wrote:I am very very impressed with PureGDK. You can consider me a customer when this is released.

I have several other DBPro extensions so I am going to try converting some of these. I will post more when they are done.
Please post some pictures too for those who are not familiar with these extensions.
sigi
User
User
Posts: 79
Joined: Fri Apr 25, 2003 7:16 pm
Location: Germany

Post by sigi »

Can`t get menus to work. I can close the window, but menus don`t react.
Nearly the same code works with B3DSDK.

Edit: There is something wrong with constants: if i replace the integers 800, 600 in OpenDBWnd(0,0,800, 600,32,#GDK_Window_BorderLess ,WindowID(0)) with #screenwidth = 800
#screenheight = 600 then i get another result.

Code in PureGDK:

Code: Select all

#screenwidth = 800
#screenheight = 600

OpenWindow(0,0,0,#screenwidth,#screenheight,"Container Window", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_Invisible) 
 hDBWnd=OpenDBWnd(0,0,800, 600,32,#GDK_Window_BorderLess ,WindowID(0)) 

;CreateGadgetList (WindowID (0))
If CreateMenu(0, (WindowID (0)))
          MenuTitle("Project")
          MenuItem(0, "New")
          MenuItem(1, "Quit")
          MenuTitle("Objects")
          MenuItem(2,"Load...")
          MenuTitle("Sky")
          MenuItem(3,"Load SkyBox...")
          MenuItem(4,"Load SkyDome...")
          MenuTitle("Lights")
          MenuItem(5,"Change Ambient Light...")
          MenuTitle("Textures")
          MenuItem(6,"Load Texture...")
          MenuTitle("Particle")
          MenuItem(7,"New Particles...")
          MenuTitle("About")
          MenuItem(8, "About...")
EndIf

; Unhide PureBasic window container 
HideWindow(0,0) 

; Don't lose focus to the new DarkBasic window 
SetForegroundWindow_(WindowID(0)) 

; Do something cool 
dbMakeObjectCube(1,3) 
dbScaleObject(1,35,35,35) 
dbPositionObject(1,-1.65,1.3,0) 

Repeat

   Delay(1)
   x.f+0.1: y.f+0.3: z.f+0.4 
   dbRotateObject(1,x.f,y.f,z.f) 
      
    EventID = WindowEvent()
            
    If EventID = #PB_Event_Menu  ; ToolBar are acting as menu
    
      Select EventMenu()
                      
        Case 1  ; Quit                  
          End
        Case 2
          StandardFile$ = "C:\"   ; anfänglichen Pfad + Dateiname festlegen
          ; Mit dem nächsten String werden die Pattern (mit "|" als Trennzeichen) für anzuzeigende
          ; Dateitypen festgelegt:
          ; Erster:  "Text (*.txt)" als Name, ".txt" und ".bat" als erlaubte Dateiendungen
          ; Zweiter: "PureBasic (*.pb)" als Name, ".pb" al erlaubte Dateiendung
          ; Dritter: "Alle Dateien (*.*) als Name, "*.*" als erlaubte Dateiendung, gültig für alle Dateien
           Pattern$ = "B3D (*.b3d)|*.b3d|X (*.x)|*.x|3DS (*.3ds)"  
           Pattern = 0    ; wir verwenden den ersten von drei möglichen Pattern als Standard
           file$ = OpenFileRequester("Bitte Datei zum Laden auswählen", StandardFile$, Pattern$, Pattern)
           index = SelectedFilePattern()
            If file$
              ;entity=bbLoadAnimMesh (file$)
              ;bbMoveEntity (entity, 0, 0, 100)
            Else
              MessageRequester("Information", "Der Requester wurde abgebrochen.", 0) 
            EndIf                     
      EndSelect
        
    EndIf
    
    dbSync()
    
    Until WindowEvent()=#WM_CLOSE
    
End 
This is with B3DSDK and works fine:

Code: Select all

XIncludeFile "blitz3dsdk.pbi"

;EnableExplicit

#screenwidth = 800
#screenheight = 600


window = OpenWindow (#PB_Any, 0, 0, #screenwidth, #screenheight, "Blitz3D in a PB Window", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
;CreateGadgetList (WindowID (window))
If CreateMenu(0, (WindowID (window)))
          MenuTitle("Project")
          MenuItem(0, "New")
          MenuItem(1, "Quit")
          MenuTitle("Objects")
          MenuItem(2,"Load...")
          MenuTitle("Sky")
          MenuItem(3,"Load SkyBox...")
          MenuItem(4,"Load SkyDome...")
          MenuTitle("Lights")
          MenuItem(5,"Change Ambient Light...")
          MenuTitle("Textures")
          MenuItem(6,"Load Texture...")
          MenuTitle("Particle")
          MenuItem(7,"New Particles...")
          MenuTitle("About")
          MenuItem(8, "About...")
EndIf          


; Blitz3D Setup...

bbSetBlitz3dHWND (WindowID (window))
bbBeginBlitz3D ()
bbGraphics3D (#screenwidth, #screenheight, 0, #GFX_WINDOWED)

; Create Entities...

cam = bbCreateCamera ()
cube = bbCreateCube ()
bbEntityColor(cube, 255, 0, 0)
lite = bbCreateLight ()

;bbCreatePlane()

;Position Entities...

bbMoveEntity (cube, 0, 0, 5)
bbMoveEntity (lite, -10, 5, -2)
bbPointEntity (lite, cube)

AddKeyboardShortcut(window, #PB_Shortcut_Up, 100)
AddKeyboardShortcut(window, #PB_Shortcut_Down, 101)
AddKeyboardShortcut(window, #PB_Shortcut_Left, 102)
AddKeyboardShortcut(window, #PB_Shortcut_Right, 103)
AddKeyboardShortcut(window, #PB_Shortcut_R, 104)

Repeat

  bbTurnEntity (cube, 0.2, 0.2, 0.2)

    EventID = WindowEvent()
            
    If EventID = #PB_Event_Menu  ; ToolBar are acting as menu
    
      Select EventMenu()
                      
        Case 1  ; Quit
        
          bbEndBlitz3D ()
          End
        Case 2
          StandardFile$ = "C:\"   ; anfänglichen Pfad + Dateiname festlegen
          ; Mit dem nächsten String werden die Pattern (mit "|" als Trennzeichen) für anzuzeigende
          ; Dateitypen festgelegt:
          ; Erster:  "Text (*.txt)" als Name, ".txt" und ".bat" als erlaubte Dateiendungen
          ; Zweiter: "PureBasic (*.pb)" als Name, ".pb" al erlaubte Dateiendung
          ; Dritter: "Alle Dateien (*.*) als Name, "*.*" als erlaubte Dateiendung, gültig für alle Dateien
           Pattern$ = "B3D (*.b3d)|*.b3d|X (*.x)|*.x|3DS (*.3ds)"  
           Pattern = 0    ; wir verwenden den ersten von drei möglichen Pattern als Standard
           file$ = OpenFileRequester("Bitte Datei zum Laden auswählen", StandardFile$, Pattern$, Pattern)
           index = SelectedFilePattern()
            If file$
              entity=bbLoadAnimMesh (file$)
              bbMoveEntity (entity, 0, 0, 100)
            Else
              MessageRequester("Information", "Der Requester wurde abgebrochen.", 0) 
            EndIf
        Case 100
          bbMoveEntity (entity, 0, 0, 0.1)
        Case 101                      
          bbMoveEntity (entity, 0, 0, -0.1)
        Case 102
          bbMoveEntity (entity, -0.1, 0, 0)  
        Case 103
          bbMoveEntity (entity, 0.10, 0, 0)
        Case 104
         bbTurnEntity (entity, 0, 1.0, 0)  
                      
      EndSelect
        
    EndIf
    
      
  bbRenderWorld ()
  bbFlip ()  
    
  Until EventID = #PB_Event_CloseWindow ; If the user has pressed on the close button
  
  bbEndBlitz3D ()

End
Athlon X2 7850 - Geforce 8800 GTS 640mb - 8 GB Ram - Vista Home Premium 64 bit SP2
darryl_bartlett
User
User
Posts: 13
Joined: Tue Apr 29, 2003 8:26 am
Location: South Wales, UK

Post by darryl_bartlett »

Hi Sigi,

Something strange is going on. I can replicate your problem. Here is why I say something weird is going on:

The first time I ran you example code using the PureGDK examples it worked fine i.e. selecting the Objects -> Load menu option displayed the File Open dialog box.

When I quit the program and re-ran it, the menu options did not respond.

I went into task manager and shut down the PBCompiler.exe process (I assume this is the same thing as selecting the Restart compiler menu option from within the PureBasic IDE). I re-ran it and it worked again.

Just to confirm, I then stopped and re-ran your code and the menus didn't respond. Also, the red X close button didn't respond either.
r_hyde
Enthusiast
Enthusiast
Posts: 155
Joined: Wed Jul 05, 2006 12:40 am

Post by r_hyde »

I think the DB window is stealing the focus, or perhaps swallowing messages. I noticed that the menu event handlers would trigger only after moving the mouse over the menu or non-client area of the form. I was able to get the menus to respond more consistently by adding SetFocus_(MenuID(0)) after If EventID = #PB_Event_Menu.

BTW, Great work on PureGDK, Mistrel 8)
darryl_bartlett
User
User
Posts: 13
Joined: Tue Apr 29, 2003 8:26 am
Location: South Wales, UK

Post by darryl_bartlett »

@r_hyde,

In a round-about way, I have come to the same conclusion. I have changed Sigi's original code to output to a console whenever the EventID variable is not equal to 0. With this new code the menu event trigger every time. Here is the code I am testing with:

Code: Select all

#screenwidth = 800
#screenheight = 600

OpenWindow(0,0,0,#screenwidth,#screenheight,"Container Window", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_Invisible)
 hDBWnd=OpenDBWnd(0,0,800, 600,32,#GDK_Window_BorderLess ,WindowID(0))

;CreateGadgetList (WindowID (0))
If CreateMenu(0, (WindowID (0)))
          MenuTitle("Project")
          MenuItem(0, "New")
          MenuItem(1, "Quit")
          MenuTitle("Objects")
          MenuItem(2,"Load...")
          MenuTitle("Sky")
          MenuItem(3,"Load SkyBox...")
          MenuItem(4,"Load SkyDome...")
          MenuTitle("Lights")
          MenuItem(5,"Change Ambient Light...")
          MenuTitle("Textures")
          MenuItem(6,"Load Texture...")
          MenuTitle("Particle")
          MenuItem(7,"New Particles...")
          MenuTitle("About")
          MenuItem(8, "About...")
EndIf

; Unhide PureBasic window container
HideWindow(0,0)

; Don't lose focus to the new DarkBasic window
SetForegroundWindow_(WindowID(0))

; Do something cool
dbMakeObjectCube(1,3)
dbScaleObject(1,35,35,35)
dbPositionObject(1,-1.65,1.3,0)


OpenConsole()

Repeat

   Delay(1)
   x.f+0.1: y.f+0.3: z.f+0.4
   dbRotateObject(1,x.f,y.f,z.f)
     
    EventID = WindowEvent()
    
    If EventID <> 0
     PrintN(Str(EventID))
    EndIf
    
    If EventID = #PB_Event_Menu  ; ToolBar are acting as menu
      Select EventMenu()
          
        Case 1  ; Quit                 
          End
        Case 2
          StandardFile$ = "C:\"   ; anfänglichen Pfad + Dateiname festlegen
          ; Mit dem nächsten String werden die Pattern (mit "|" als Trennzeichen) für anzuzeigende
          ; Dateitypen festgelegt:
          ; Erster:  "Text (*.txt)" als Name, ".txt" und ".bat" als erlaubte Dateiendungen
          ; Zweiter: "PureBasic (*.pb)" als Name, ".pb" al erlaubte Dateiendung
          ; Dritter: "Alle Dateien (*.*) als Name, "*.*" als erlaubte Dateiendung, gültig für alle Dateien
           Pattern$ = "B3D (*.b3d)|*.b3d|X (*.x)|*.x|3DS (*.3ds)" 
           Pattern = 0    ; wir verwenden den ersten von drei möglichen Pattern als Standard
           file$ = OpenFileRequester("Bitte Datei zum Laden auswählen", StandardFile$, Pattern$, Pattern)
           index = SelectedFilePattern()
            If file$
              ;entity=bbLoadAnimMesh (file$)
              ;bbMoveEntity (entity, 0, 0, 100)
            Else
              MessageRequester("Information", "Der Requester wurde abgebrochen.", 0)
            EndIf                     
      EndSelect
       
    EndIf
   
    dbSync()
   
    Until WindowEvent() = #WM_CLOSE
   
CloseConsole()
End
I am still having problems with the close window event though. It seem clicking on the close window button triggers an event value of 16 but it only responds after clicking on it about 3 times. Then it just hangs there and I have to manually kill the application process.
sigi
User
User
Posts: 79
Joined: Fri Apr 25, 2003 7:16 pm
Location: Germany

Post by sigi »

hmm, this is ? because i was never be able to open the load object requester. no responses to the menu everywhere. Hi Mistrel :?
Athlon X2 7850 - Geforce 8800 GTS 640mb - 8 GB Ram - Vista Home Premium 64 bit SP2
darryl_bartlett
User
User
Posts: 13
Joined: Tue Apr 29, 2003 8:26 am
Location: South Wales, UK

Post by darryl_bartlett »

Hi Sigi,

Have you tried running my updated version of your code? If so, do you get any values displayed in the Console window when you select a menu option?


Interestingly, if I change the until line of code to add an Or EventID = 16 clause (so the line now reads)

Code: Select all

Until WindowEvent() = #WM_CLOSE Or EventID = 16
the close event triggers every time instead of every 3 or 4 clicks on the close window button.
sigi
User
User
Posts: 79
Joined: Fri Apr 25, 2003 7:16 pm
Location: Germany

Post by sigi »

@darryl_bartlett
i have tried your updated code and the first time there was a console output (can`t remember the details). But starting it now again i have always mysterious errors and not always the same. Don`t know what`s wrong here.
Athlon X2 7850 - Geforce 8800 GTS 640mb - 8 GB Ram - Vista Home Premium 64 bit SP2
darryl_bartlett
User
User
Posts: 13
Joined: Tue Apr 29, 2003 8:26 am
Location: South Wales, UK

Post by darryl_bartlett »

@sigi,

Weird eh? This is quite similar to a problem with using the initial version of the Blitz3d SDK within a C#.net winforms apps. The SDK was "swallowing" most of the windows events before .net could process them.


Try this - change the Delay(1) line to something like Delay(100).

Obviously, your app will run more slowly, but this may give PureBasic "more time" to process the window events.

Edit : If you add the Delay(100) try selecting the Objects -> Load menu option several times and see if it eventually responds.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

New beta 0.4.2b is out
0.4.2b - Feb. 22, 2008 Changelog:

* The DarkBasic render window no longer steals focus from its parent window when the ParentWindowID parameter is used with OpenDBWnd().
* The PureGDK executable will no longer hang when the program ends by reaching the end of the source or if the End command is encountered.
There is a bug in your code which is causing messages to be list. You call WindowEvent() twice which is causing the #WM_CLOSE message to be removed from the message stack.

This is best explained in WaitWindowEvent()
WaitWindowEvent() can only be called once per event loop, because else events will be "lost" (every event can only be processed once and isn't available anymore for a second time after first processing).
sigi
User
User
Posts: 79
Joined: Fri Apr 25, 2003 7:16 pm
Location: Germany

Post by sigi »

Change Delay(100) doesn`t change anything, only the app is slower responding. No really menu responding.

Edit: Oouch, something new from the Boss of this, must try it. :)
Last edited by sigi on Sat Feb 23, 2008 12:52 am, edited 1 time in total.
Athlon X2 7850 - Geforce 8800 GTS 640mb - 8 GB Ram - Vista Home Premium 64 bit SP2
darryl_bartlett
User
User
Posts: 13
Joined: Tue Apr 29, 2003 8:26 am
Location: South Wales, UK

Post by darryl_bartlett »

Ah ha - good spot there Mistrel. It didn't even occur to me WindowEvent() was running twice within one loop iteration so would miss events!!!! That is definitely a "Doh!!" moment!!!

That also explains why it worked for me when I put in the or EventID = 16 in the until statement!!!!

Thanks for the update as well. Downloading now - will let you know how things go.

Keep up the excellent work.


Edit - Update has fixed all the issues. Once again, thanks.
Last edited by darryl_bartlett on Sat Feb 23, 2008 12:57 am, edited 1 time in total.
r_hyde
Enthusiast
Enthusiast
Posts: 155
Joined: Wed Jul 05, 2006 12:40 am

Post by r_hyde »

update works well for me. Impressively fast fix!
Post Reply