PureGDK uses the DarkBasic Professional 3D engine and although most of the commands are similar there are some fundamental differences that must be acknowledged.
Fundamental Differences
Command Revisions
DarkBasic Professional uses a method called operator overloading when declaring many of its function prototypes within its DLLs. Operator overloading is not supported by PureBasic and many of PureGDK's commands have been altered to reflect this.
Several functions have also been removed from the DarkBasic Professional command libraries due to inconsistencies, compatibility, or for duplicating native functions already present in PureBasic. Please refer to the Revised Commands section of the documentation for a list of changes.
Compiling to the source directory
PureBasic compiles to the computer's temp directory by default in contrast to DarkBasic Professional which can cause problems if your source assumes a media directory relative to the executable. To compile to the source directory like DBP select from the IDE file menu "Compiler -> Compiler Options -> Compile/Run" and enable "Create temporary executable in source directory" by selecting the check box.
Float evaluation
DarkBasic Professional treats each individual expression separately when evaluating a larger expression. For example, in DarkBasic Professional the following code will display the value 0.75.
n#=(15/4)/4.0
print n#In PureBasic this same expression will display the value 0.9375. This is because the first part of the expression (15/4) is treated as an integer division by DarkBasic Professional. To convert this example to PureBasic the first part of the expression must be cast to an integer before it is divided.
n.f=Int(15/4)/4.0
Debug n.fData structures to replace vector and matrix IDs
PureGDK uses structures to instead of IDs to pass vector and matrix data between functions. To pass a vector to a function it must first be passed by address using the " @ " operator. The following example will create two variables with vector 2 structures and then add them together.
;/ Declare variables with pre-defined structures
Vector2a.Vector2
Vector2b.Vector2
Vector2Result.Vector2;/ Set vector data
Vector2a\x=3: Vector2b\x=7
Vector2a\y=5: Vector2b\y=5;/ Add vectors together
dbAddVector2(@Vector2Result, @Vector2a, @Vector2b);/ Output results
Debug Vector2Result\x ; 3 + 7 = 10
Debug Vector2Result\y ; 5 + 5 = 10How to use optional flags
PureBasic uses optional parameter flags in some functions like OpenWindow(). To use these optional flags simply use the bitwise OR operator " | " to separate each flag. For example:
WindowID = OpenWindow(#PB_Any, 0 ,0, 320, 240, "Window Title", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)This will open the DarkBasic render window with a titlebar and center it on the screen by using a combination of the #PB_Window_SystemMenu and #PB_Window_ScreenCentered flags.
How to change the resolution:
In PureGDK only the resolution of the render window can be specified at runtime. Additional steps are necessary to change the resolution of the user's screen and also to perform non-destructive resizing (resizing the window without changing its resolution).
Here is an example on how to change the screen resolution in PureBasic by calling the Windows API function ChangeDisplaySettings_(). You should always use EnumDisplaySettings_() to identify supported resolutions prior to calling this function:
Procedure SetResolution(Width, Height, Depth, Flag=#CDS_FULLSCREEN)
Protected Result,dmScreenSettings.DEVMODE
dmScreenSettings\dmSize=SizeOf(DEVMODE)
dmScreenSettings\dmPelsWidth=Width
dmScreenSettings\dmPelsHeight=Height
dmScreenSettings\dmBitsPerPel=Depth
dmScreenSettings\dmFields=#DM_PELSWIDTH|#DM_PELSHEIGHT|#DM_BITSPERPEL
If ChangeDisplaySettings_(@dmScreenSettings, Flag)=#DISP_CHANGE_SUCCESSFUL
Result=#True
EndIf
ProcedureReturn Result
EndProcedure
SetResolution(1280,1024,32)
Delay(3000)PureGDK supports only the full screen windowed method of creating full screen applications. Full screen exclusive mode is obsolete on modern hardware and is not supported by PureGDK.
Here is an example of how to match the render window resolution to the screen resolution. Additional API functions can be used to prevent other windows from stealing focus such as SetWindowPos_():;/ Initialize PureBasic desktop library
ExamineDesktops()
;/ Show the PureGDK render window
OpenWindow(0,0,0,DesktopWidth(0),DesktopHeight(0),"DarkBasic Professional - PureGDK",#PB_Window_BorderLess)
hDBWnd=OpenDBWnd(WindowID(0),0,0,DesktopWidth(0),DesktopHeight(0))
dbsetdisplaymode(DesktopWidth(0),DesktopHeight(0),32,0)
;/ Set the window to the to the top of the z-order
SetWindowPos_(hDBWnd,#HWND_TOPMOST,0,0,0,0,#SWP_NOREPOSITION|#SWP_NOSIZE)
dbMakeObjectCube(1,3)
;/ Rotate the cube and update the screen
Repeat
x.f+0.2: y.f+0.4: z.f+0.8
dbRotateObject(1,x.f,y.f,z.f)
dbText(15,15,Str(dbscreenfps()))
dbSync()
Until WindowEvent()=#WM_CLOSE Or Not dbInKey()=""
End
Unlike DBP, PureGDK does not stretch the resolution of the render window by default. If you want to use a lower resolution at a higher screen size then you can resize the window yourself:
;/ Initialize PureBasic desktop library
ExamineDesktops()
;/ Show the PureGDK render window
OpenWindow(0,0,0,DesktopWidth(0),DesktopHeight(0),"DarkBasic Professional - PureGDK",#PB_Window_BorderLess)
hDBWnd=OpenDBWnd(WindowID(0),0,0,640,480)
MoveWindow_(hDBWnd,0,0,DesktopWidth(0),DesktopHeight(0),1)
;/ Set the window to the to the top of the z-order
dbSetWindowSize(DesktopWidth(0),DesktopHeight(0))
dbMakeObjectCube(1,3)
;/ Rotate the cube and update the screen
Repeat
x.f+0.2: y.f+0.4: z.f+0.8
dbRotateObject(1,x.f,y.f,z.f)
dbText(15,15,Str(dbscreenfps()))
dbSync()
Until WindowEvent()=#WM_CLOSE Or Not dbInKey()=""
EndIdentifying supported resolutions is also very easy using the Win32 API. Consider this example which lists all resolutions supported by the user's monitor that is of the same frequency and aspect ratio:
;/ Initialize PureBasic desktop library
ExamineDesktops()
;/ Iterate through supported display settings and display only select criteria
While EnumDisplaySettings_(0,i,@DevMode.DEVMODE)
If DesktopWidth(0)*1.0/DesktopHeight(0)=DevMode\dmPelsWidth*1.0/DevMode\dmPelsHeight And DevMode\dmDisplayFrequency=DesktopFrequency(0) And DevMode\dmBitsPerPel=DesktopDepth(0)
Debug Str(DevMode\dmPelsWidth)+" "+Str(DevMode\dmPelsHeight)+" "+Str(DevMode\dmDisplayFrequency)
EndIf
i+1
Wend
Other Changes
dbSyncOff() is no longer supported and Sync is now on by default.