Reputation: 1628
In an OpenGL program I have a Camera object that sets up the projection matrix to be centered on a sprite. It worked fine until I went into fullscreen mode, there I noticed the object I focused on was off center. After messing around with my resolution I noticed that 4:3 resolutions don't have this problem(I was originally at 1680x1050) and then I found the following.
1280x1024: object is centered.
1280x960: object is centered.
1280x720: object is not centered and the entire viewport seems to have shifted left. That is, when I move my mouse left it seems to move off screen a few inches and there is a black region on the right of my screen where nothing is drawn and my mouse won't move into.
Has anyone had a problem like this? I'm on Ubuntu if that's significant.
Upvotes: 0
Views: 314
Reputation: 18005
My guess would be that your monitor is connected through VGA, and is not correctly calibrated for that resolution. So the monitor shifts the display output.
Possible solutions include:
Upvotes: 0
Reputation: 4282
Are you accounting for the aspect ratio when setting up your projection matrix ?
This tutorial might be a useful read if not.
Here is my own version (in python but it should be trivial to translate to java) if having a code sample helps; initPerspectiveMatrix takes an aspect ratio, i.e. height/width.
def calcFrustumScale(fov):
return (1.0 / np.tan(np.deg2rad(fov) / 2.0))
def initPerspectiveMatrix(aspectRatio = 1.0):
scale = calcFrustumScale(60)
ARscale = scale*aspectRatio
near = 0.5
far = 1000.0
perspMx = np.array([[ARscale, 0.0 , 0.0 , 0.0 ],
[ 0.0 , scale, 0.0 , 0.0 ],
[ 0.0 , 0.0 , (near+far)/(near-far), (2*near*far)/(near-far)],
[ 0.0 , 0.0 , -1.0 , 0.0 ]], dtype='float32')
Upvotes: 1