Hello all
I was working on how to change Resolution in PGDK, I think This is a good example
Feel free to improve on it.
I was trying to get it to go from full Screen 1440x900x32 into windowed mode 800x600x32 at runtime but The Parent window can only be called once at runtime unless someone else know a good trick or two
Another Method I was thinking of was to have the menu as a program and then load the main program and set windowed mode that way, just an idea.
Best Regards
Kevin
Declare dbSetResolution(Width, Height, Depth, Flag=#CDS_FULLSCREEN)
Declare dbCheckDisplayMode(Width, Height, Depth)
ExamineDesktops()
; ---> #PB_Window_BorderLess For FullScreen or Windowed ->#PB_Window_SystemMenu
OpenWindow(0,0,0,DesktopWidth(0),DesktopHeight(0),"PureGDK Change Resolution Test",#PB_Window_BorderLess)
If dbCheckDisplayMode(1440,900,32)
hDBWnd=OpenDBWnd(WindowID(0),0,0,1440,900)
Else
End
EndIf
_Vsync_Flag=#True
If _Vsync_Flag=#True
dbSyncRate(DesktopFrequency(0)) ; Mine is 60 FPS by Default
Else
dbSyncRate(0) ; Unlimited FPS
EndIf
dbGetD3DCapabilities(@Result.D3DCaps)
If Result\Antialias=#True
_Antialias_Flag=#True
Else
_Antialias_Flag=#False
EndIf
dbSetDisplayMode(1440,900, _Vsync_Flag, _Antialias_Flag, 0) ; Reload all of your assets after this command...
SetWindowPos_(WindowID(0),#HWND_TOPMOST,0,0,1440,900,#SWP_NOREPOSITION) ; Resize Main Window
MoveWindow_(hDBWnd,0,0,DesktopWidth(0),DesktopHeight(0),1) ; Pgdk Render Window Size
dbMakeObjectCube(1,10)
;/ 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(10,10,"1440x900")
dbText(10,30,Str(dbScreenFPS()))
dbSync()
Repeat
Event=WindowEvent()
If Event=#PB_Event_CloseWindow
End
EndIf
Until Event=0
Until WindowEvent()=#WM_CLOSE Or dbKeyState(#VK_SPACE)=#True
Repeat : WindowEvent()
Until dbKeyState(#VK_SPACE)=#False
If dbCheckDisplayMode(800,600,32)
If (dbSetResolution(800,600,32))=#True
dbSetDisplayMode(800,600, _Vsync_Flag, _Antialias_Flag, 0) ; Reload all of your assets after this command...
SetWindowPos_(WindowID(0),#HWND_TOPMOST,0,0,800,600,#SWP_NOREPOSITION) ; Resize Main Window
MoveWindow_(hDBWnd,0,0,800,600,1) ; PGDK Render Window Size
Else
End
EndIf
EndIf
dbMakeObjectCube(1,10)
;/ 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(10,10,"800x600x32")
dbText(10,30,Str(dbScreenFPS()))
dbSync()
Repeat
Event=WindowEvent()
If Event=#PB_Event_CloseWindow
End
EndIf
Until Event=0
Until WindowEvent()=#WM_CLOSE Or dbKeyState(#VK_SPACE)=#True
Repeat : WindowEvent()
Until dbKeyState(#VK_SPACE)=#False
If dbCheckDisplayMode(1024,768,32)
If (dbSetResolution(1024,768,32))=#True
dbSetDisplayMode(1024,768, _Vsync_Flag, _Antialias_Flag, 0) ; Reload all of your assets after this command...
SetWindowPos_(WindowID(0),#HWND_TOPMOST,0,0,1024,768,#SWP_NOREPOSITION) ; Resize Main Window
MoveWindow_(hDBWnd,0,0,1024,768,1) ; PGDK Render Window Size
Else
End
EndIf
EndIf
dbMakeObjectCube(1,10)
;/ 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(10,10,"1024x768x32")
dbText(10,30,Str(dbScreenFPS()))
dbSync()
Repeat
Event=WindowEvent()
If Event=#PB_Event_CloseWindow
End
EndIf
Until Event=0
Until WindowEvent()=#WM_CLOSE Or dbKeyState(#VK_SPACE)=#True
Repeat : WindowEvent()
Until dbKeyState(#VK_SPACE)=#False
End
; <--- Set Resolution(Width, Height, Depth, Flag)
Procedure dbSetResolution(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
Procedure dbCheckDisplayMode(Width, Height, Depth)
Protected i.w, Result.w
;/ Check if Display Mode Exists
While EnumDisplaySettings_(0,i.w,@DevMode.DEVMODE) And Result.w=0
If (DevMode\dmPelsWidth)=Width And (DevMode\dmPelsHeight)=Height And (DevMode\dmBitsPerPel)=Depth : Result=#True
Else
Result=#False
EndIf
i+1
Wend
ProcedureReturn Result
EndProcedure