wide screen detection

Blitz3D Forums/Blitz3D Beginners Area/wide screen detection

Fernhout(Posted 2010) [#1]
I have a problem. I want to detect if the computer is running on a wide screen monitor or a normal one. If i check for screen resolutions i got a 640 by 480 back. there i want to write a game in. but i got it also back even if the screen is wide screen. Then all the graphics is strech out and that is something i do not want to happend.
If i can find a way if the screen is working in wide mode i can ajust the resolution and make borders on both side.
Its not the meaning that the player have to change the BIOS for this. If it is possible i will do it in my program.

Is there someone who can help me with this problem.

Bart.


Guy Fawkes(Posted 2010) [#2]
Global screenwidth
Global screenheight
Global screendepth
Global screenmode

screenwidth = 800
screenheight = 600
screendepth = 0
screenmode = 1

Graphics3D screenwidth,screenheight,screendepth,screenmode

While Not Keyhit(1)

if screenmode = 1
endif

if screenmode = 2
endif

updateworld
renderworld
flip
wend


_PJ_(Posted 2010) [#3]
That woint work, Rez since there are monitors and GPU that can display various types of resolution scales.

--

Ideally, you need to know in advance what screen ratios you will be checking for.
In a similar project, I at least checked for all those supported by my setup:

There is a way to get the current desktop resolution, but you will need to access the Windows API DLLs. This can be achieved with a decls file placed in your "userlibs" folder:

the contents of the decls file should be:
.lib "user32.dll"

api_GetSystemMetrics% (nIndex%) : "GetSystemMetrics"


With that in place, you have a new function in Blitz

api_GetSystemMetrics(nIndex)

The nIndex parameter can be used to identify the desktop resolution in the following manner:

Const RESOLUTION_TYPE_4_3%=1
Const RESOLUTION_TYPE_16_9%=2
Const RESOLUTION_TYPE_16_10%=3
Const RESOLUTION_TYPE_3_2%=4
Const RESOLUTION_TYPE_5_4%=5
Const RESOLUTION_TYPE_5_3%=6
Const RESOLUTION_TYPE_85_64%=7
Const RESOLUTION_TYPE_85_48%=8
Const RESOLUTION_TYPE_53_30%=9
Const RESOLUTION_TYPE_40_27%=10

Const RESOLUTION_TYPE_UNSUPPORTED%=0

Global RESOLUTION_WIDTH=api_GetSystemMetrics(16)
Global RESOLUTION_HEIGHT=api_GetSystemMetrics(1)

Function GetDesktopRatio()
	Return GetResolutionRatioLabel(RESOLUTION_WIDTH,RESOLUTION_HEIGHT)
End Function

Function GetResolutionRatioLabel(Width,Height)
	If ((A*3)=(B*4)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_4_3)
	If ((A*9)=(B*16)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_16_9)
	If ((A*5)=(B*8)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_16_10)
	If ((A*2)=(B*3)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_3_2)
	If ((A*4)=(B*5)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_5_4)
	If ((A*3)=(B*5)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_5_3)
	If ((A*64)=(B*85)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_85_64)
	If ((A*48)=(B*85)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_85_48)
	If ((A*30)=(B*53)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_53_30)
	If ((A*27)=(B*40)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_40_27)
	Return ResolutionModeTypeToString$(RESOLUTION_TYPE_UNSUPPORTED)
End Function

Function ResolutionModeTypeToString$(ResMode%)
	Select ResMode%
		Case RESOLUTION_TYPE_4_3:Return "4:3"
		Case RESOLUTION_TYPE_16_9:Return "16:9"
		Case RESOLUTION_TYPE_16_10:	Return "16:10 (8:5)"
		Case RESOLUTION_TYPE_3_2:	Return "12:8 (3:2)"
		Case RESOLUTION_TYPE_5_4:	Return "10:8"
		Case RESOLUTION_TYPE_5_3:Return "5:3 (10:6)"
		Case RESOLUTION_TYPE_85_64:Return "85:64"
		Case RESOLUTION_TYPE_85_48:Return "85:48"
		Case RESOLUTION_TYPE_53_30:Return "53:30"
		Case RESOLUTION_TYPE_40_27:Return "40:27"
		Default: Return "Unsupported"
	End Select
End Function




Guy Fawkes(Posted 2010) [#4]
try this:




Fernhout(Posted 2010) [#5]
Thanks i got the idea. Lets see if its work

one thing i cannot figure out. the function GetResolutionRatioLabel. What is A and B. Is that the resolution who are actualy Width and Height. Or is it something i cant see right now.

For the rest i can understand right now.


Guy Fawkes(Posted 2010) [#6]
it is the width and height of whatever certain graphics card's width and height is. it essentially is whatever u tell it.


Fernhout(Posted 2010) [#7]
Ok all

Thanks for the help. i got it. A soon i call that funciton i have to give A and B the values.

Tested in my program and its work. Now i can create a resolution that work with the real ratio of a normal screen. see if i can managed that.

Thanks a lot guy's for the big help.
Be sure your name wil be in the program for your help.


Guy Fawkes(Posted 2010) [#8]
Np! :)


Ked(Posted 2010) [#9]
it is the width and height of whatever certain graphics card's width and height is. it essentially is whatever u tell it.

Hysterically incorrect.

It's a mistype. This should be your function:
Function GetResolutionRatioLabel(Width,Height)
	If ((Width*3)=(Height*4)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_4_3)
	If ((Width*9)=(Height*16)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_16_9)
	If ((Width*5)=(Height*8)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_16_10)
	If ((Width*2)=(Height*3)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_3_2)
	If ((Width*4)=(Height*5)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_5_4)
	If ((Width*3)=(Height*5)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_5_3)
	If ((Width*64)=(Height*85)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_85_64)
	If ((Width*48)=(Height*85)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_85_48)
	If ((Width*30)=(Height*53)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_53_30)
	If ((Width*27)=(Height*40)) Then Return ResolutionModeTypeToString$(RESOLUTION_TYPE_40_27)
	Return ResolutionModeTypeToString$(RESOLUTION_TYPE_UNSUPPORTED)
End Function



Fernhout(Posted 2010) [#10]
thats right but if you did reed Rez line on my question you have already your awnser.
but thanks again. better say once to much hen never at all.

thanks


Ked(Posted 2010) [#11]
Just letting you know that there was a mistype so you didn't need to add anything extra to the code. Thanks for the attitude though.


GIB3D(Posted 2010) [#12]
You could use CameraViewport to change the camera's screen size.


_PJ_(Posted 2010) [#13]
Sorry, Fernhout - yes, A and B should be Width and Height respectively.
I had copied the functions from another project and forgotten to chaneg them all correctly. (Thanks for doing so, Ked)

Note, you may discover there are other resolution ratios available on your machine, which will be returned by this as "Unsupported", in which case, to allow for them to be considered in your program, you can make new
RESOLUTION_TYPE_* constants and new lines for the
GetResolutionRatioLabel(Width,Height)
and
ResolutionModeTypeToString$(ResMode%)
functions.

Also, bear in mind that I believe there is a hard liumit on resolution size in Blitz3D (Due to directX7 I think?) I am naot sure, but I believe it's 2400 x something ???


Serpent(Posted 2010) [#14]
One thing about the GetSystemMetrics function:
When trying to get screen width and height, if you are running a full screen application, it will affect the value returned by GetSystemMetrics.

Example:


As you can see, it returns 640 because the current graphics mode is 640. Be careful of this when using it - i.e. in a full screen blitz application, you will not be able to find out the size of Windows' resolution.

A second thing, you are using the constants 'SM_CXFULLSCREEN' and 'SM_CYSCREEN' to find the screen width and height - aka 16 and 1. I have read about people having problems using the '...FULLSCREEN' constants as parameters. Instead of 'SM_CXFULLSCREEN' (aka 16) you should probably use 'SM_CXSCREEN' (aka 0).
Replacing the 16 with 0 would probably be safer, although from my experience it doesn't seem to matter.


Serpent(Posted 2010) [#15]
One last thing, if you are using the width and height values purely for your code - i.e. you will not be showing the user the ratios - then the two inbuilt functions might be useless for your purposes. For example, I am currently writing a program that allows you to have multiple virtual desktops (something like DeskSpace if anyone's ever heard of it).
Before my program initialises anything, it calls GetSystemMetrics (with param of '0' then param of '1') to get the width and height of the screen.
At no point do I actually need to calculate within my program that the monitor works at a ratio of 'X:Y'. I scale 3D cubes into rectangular prisms to match the screen width and height, but there is no need whatsoever to call functions which determine that my screen resolution is 4:3 or 16:9. Working these ratios out, then assigning a specific code to it, and then converting it to a string may be completely useless in your program as you probably will have to convert everything back from the strings in the end anyway.


Midimaster(Posted 2010) [#16]
I would recomend not to give a string as answer of the function. You will never be sure wether you considered all possible ratios (e.g. new Netbooks: 1024x600). Better is to handle it as a FLOAT:

Function GetResolutionRatio#()
    Local Ratio#
    Local RESOLUTION_WIDTH#=api_GetSystemMetrics(0)
    Local RESOLUTION_HEIGHT#=api_GetSystemMetrics(1)
    Ratio= RESOLUTION_WIDTH/RESOLUTION_HEIGHT
    Return Ratio
End Function


This returns values between 1.0 to 2.0 and you can decide, how to react: "smoth indiviual" or "all the same for a range of ratios", without the problem the users gets a "not supported" message

normal Screens will return between 1.30 and 1.40
Wide Screens will between 1.50 and 1.90

so you are good prepared for the future of new ratios coming.

My Ati Radeon allows to turn the Desktop 90°. And my TFT-Monitor can be turned 90°. Now the resolution is W:1200xH:1920! This returns values between 0.5 to 1.0!


Kryzon(Posted 2010) [#17]
My Ati Radeon allows to turn the Desktop 90°. And my TFT-Monitor can be turned 90°. Now the resolution is W:1200xH:1920! This returns values between 0.5 to 1.0!

Well, people that play like that will probably be 0.001% of his total user base...


_PJ_(Posted 2010) [#18]
Helpful advice, Serpent & Midimaster.
Incidentally, I used GetSystemMetrics 16 through playing with the function until I found results that worked!

Of course, the ratio itself may be useful and certainly more 'crashproof'.

I also have the rotational ability for the display, but then, since I doubt any games cater for such, then it's not worth the bother in my opinion. As Kryzon says, such a small fraction of people who would just have to rotate their sscreens for a bit ;)


Fernhout(Posted 2010) [#19]
Midimaster you have stop out a little problem i did encounter to. As soon as i know the ratio aspect of the screen and i want to recalculte it to another format the the calculations were wrong. i did discover that i had to use a float to get everthing right.

but thanks anyway for the info. its make me feel good that i was not the only only one who sees it.

Now all guys a other problem.
i am stil busy making my program to work on differend screen sizes displays. ration 16:9 , 16:10 and 4:3. The last one is easy.
But i have a system where i can not make the right graphic mode. Thats the 16:10 mode. i can figure out the Graphic mode. but when i call it the program reports that it is not supported.
I know that that computer is supporting it, couse i can call it under C and C++. Even under DarkBasic Pro i can call that graphic mode. So that computer can support it. Why is BB reporting that its not supporting.
All three systems is running with DirectX 11.

the graphic mode i have to made is 780 X 480
i wont bother you how i calculate it but in the program this is the outcome.


_PJ_(Posted 2010) [#20]
Do you mean the function retuerns "NOT SUPPORTED", or that Blitz throws an actual error if you try to use that graphics mode?

What is the actual mode you are trying to achieve?


780x480 but with what colour depth and screen-mode (i.e. Full screen etc.)?


Fernhout(Posted 2010) [#21]
To serpent
Somehiow you ar right. but you mis one point. If i am calling a mode like 800 X 600 and draw a cube on the screen. The cube is stretch out. Why. The ratio in the bios is set to stretch. So as long as you programming in full screen mode en not in windowed mode you display will be streched out. And that is something i will preventing from happening.

Yes i call first this before i do anything so that i have the values. from there i can calculate my corrections to the program.
But still i have to got that graphic mode otherwise even the correction is nor working nice. Say e.g. i have to lose some data from a texture to fit on a sprite. if the sprite is 64 by 64 i have to bring it down to 60 by 64 and the texture is losing some of his information.and still the picture is not looking nice. Only when the correction is putting on the display then it wil work fine. thats why i want to have it that way.

I my case the problem is more there cause i am using a 2D visual so you see it more when the stretching is there. and that i want to lose.

I have some games also in 2D and you can see it when they are not using the correction. everything what is suppose to be round is oval. its a aful view.


Fernhout(Posted 2010) [#22]
Yes i use full screen
like Graphics 780,640,16,1

i get a error back
Unable to set graphic mode

if i do it in C
i got the full screen and no errors.
so its not the card who is not willing


_PJ_(Posted 2010) [#23]
I dont doubt your card can handle it!
Might be a DirectX issue, since despite your cards supporting DX11, Blitz is stuck at DirectX 7.
Since you are using Graphics, not Graphics3D I am a little stuck for any other possible causes, but I had another thought, I wonder if there may be an issue with the refresh rate? Though perhaps that would only affect the monitor, not something detectable by Blitz...


Fernhout(Posted 2010) [#24]
Malice
Sorry but its not the refresh rate.

I try it by calling the graphics mode on the first line of the program and i got the error.

in the other languages its not a problem. So i thing you are right about that Blitz is supporting DirectX7. And that is maybe causing the problem.
I took a lot of time in preparing the program for all the graphics in it and a lot of precoding to make all the variables in. I also make the remarks in the program of the compleet program flow. so i have it all in the program.
just starting to the real coding and then this problem is playing up. i hate that. The good idea i have is gone on one little issu.

I hate to use C or C++ its much easyer to use BB. In C or C++ you have to make a big gamecore before you can start. i think i have to switch over to Darkbasic there its working ok a lot of reprogramming has to be done. The editor there like to have al the declerations on a other way.


_PJ_(Posted 2010) [#25]
just starting to the real coding and then this problem is playing up. i hate that. The good idea i have is gone on one little issu.



Oh I've ad that happen lots of times :(

Is there another resolution you could use, perhaps one with a similar ratio? It seems an unusual screen resolution, so I doubt many would ever use it, and certainly not exclusively.


Midimaster(Posted 2010) [#26]
Using a 4:3 on a widescreen causes an error of 30%. This looks terribel and you have to react. Using 16:9 on a 16:10 widescreen is harmless. This brings an error of 12%, but this looks not very dramatic. On my dell monitor I have 1920x1200 and always use game-resoution 1920x1080 without any compesation in my programs.

If 16:10 is not working and you want to correct it, I would suggest to open a 16:9 Graphics3D on the monitor you detected a 16:10 ratio. To compesate the streching you can work with a yScale-factor of 1.12 for the camera:
ScaleEntity Camera, 1, 1.12, 1


Thats all for the 3D-Part.


Fernhout(Posted 2010) [#27]
Midimaster thanks for the idea

But as i already wrote. I work for the moment on a 2D game. So i can not use any thing from the 3D graphics. If it was possible i would use it.
But thats not possible.

I have also tried a other compiler program its also able using 3D and its also using Basic. Its called DarkBasicPro. Its downloadable for free now. There is a lot of plugh ins and a lot of DLL for making programming easier.
There is can use the correction without any problem and i found out that i can use Sprites in 2D programming to.

But thanks anyway.
All you guys when the game is ready i wil send you a copy and your names wil in it.