Thought I'd start a series of threads titled
DBP Method - to help intermediate user learn how to program useful functions using DarkBasic Profesional.
I've decided to start the ball rolling with this rather dull but simple method of detecting the desktop aspect ratio and using this value to adjust the camera aspect ratio to suit.
Why?, well with the influx of monitors of differing resolutions and aspects, i.e. widescreen displays. this code will adjust a standard screen setting of 800x600's aspect ratio to that of the desktop thus eliminating the squashing effect this has.
`*** DBP Method - Setting Screen Aspect ratio to match Desktop Aspect ratio
`*** this should eliminate the stretching cause when viewing a normal 4:3 application
`*** on a 8:5 or 16:9 monitor
`* 4:3 (1.33) VGA,SVGA,XGA etc.
`* 3:2 (1.50) DVD 720x480
`* 5:4 (1.25) SXGA 1280x1024
`* 8:5 (1.60) WIDE iMac
`* 16:9 (1.77) HDTV 720p, 1080p
If Init_Display(800,600,32)
Make Object Cube 1,50
Position Camera 0,0,0,-100 : Point Camera 0,0,0,0
Do
Text 0,0,Str$(Screen FPS())+" FPS "
Sync
Loop
EndIf
End
`***
Function Init_Display(SW,SH,SD)
` Check that display mode is supported by the hardware
If Check Display Mode(SW,SH,SD)
` Get desktop resoulution to calculate aspect ratio
Load Dll "User32.dll",1
DW# = Call Dll (1,"GetSystemMetrics",0)
DH# = Call Dll (1,"GetSystemMetrics",1)
Delete Dll 1
AR# = DW#/DH# `<- Calculate Aspect Ratio
` Set display mode, aspect ratio and sync rate
Set Display Mode SW,SH,SD
Hide Mouse : AutoCam Off
Set Camera Aspect AR#
Sync Rate 0 : Sync On : Sync
ExitFunction 1 `<- Process was succesful so exit here
EndIf
EndFunction 0
`*** END ***
Go Create...
*note If you have a better or more readable method of achieving the same, feel free to post an example.
Cyberspace was becoming overcrowded and slummy so I decided to move. These nice chaps gave me a lift.