XNA Windows Resolution / Mouse Position Bug
- by Ian Hern
In XNA, when in windowed mode and resolution (set via PreferredBackBufferWidth/Height) is close to the resolution of the display, the view is distorted (zoomed in a bit)and the mouse coordinates are wrong.
Here is what it looks like when I draw a bunch of lines to the screen.
(Normal, Error on my ASUS Notebook G73Jh, Error on my EEE PC 1001P)
In the top left of the screen the mouse position is correct, but the further you get away the more out of sync it becomes. Here are some images of the mouse in different positions and the game drawing a circle underneath where it thinks the mouse is.
(Top Left, Bottom Right)
If you shrink the resolution by a couple pixels then it goes back to working like normal, my first though at a fix was to limit the max resolution to a little smaller than the display resolution. I figured out the maximum resolution that works in a couple different modes, but there doesn't seem to be a pattern that would allow me to determine it based off the display resolution.
Computer | Screen Resolution | Max Error-Free | Difference
ASUS Notebook G73Jh | 1920x1080 | 1924x1059 | +4x-21
ASUS Notebook G73Jh | 1024x600 | 1018x568 | -6x-32
EEE PC 1001P | 1024x600 | 1020x574 | -4x-26
Because the differences don't form a pattern I can't hack in a solution, the one even has +4 which baffles me.
Here is a project that demonstrates the problem, just set the resolution to the resolution of your display.
Any ideas on how I might fix this issue?
As an insteresting aside, I tried to use FRAPS to capture a video of the issue but fraps actually records without distortion or mouse offset.