I have probably a simple math problem that I'm having surprisingly hard time figuring out. I have a resizable LWJGL (OpenGL) window. The game I'm making is in 2D, but I use glFrustum() to get depth for my sprites. Here's a (little bit simplified) snippet from my projection code:
double divider = 64.0;
double left = -vw / divider;
double right = vw / divider;
double bottom = vh / divider;
double top = -vh / divider;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(left * aspect, right * aspect, bottom, top, 8, 65536);
float zModifier = -256;
float vRatio = Game.HEIGHT / Display.getHeight();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-vw / 2.0f, -vh / 2.0f, zModifier * vRatio);
(I must admit that I don't understand the frustum bit very well, I found this piece of code somewhere in the Internet and it has served me well...)
However, I am rendering my own cursor with a sprite, and switch to native cursor when the cursor comes in contact with the window border. This worked all well until I made the window resizable.
Now my problem is, when I resize the window, the native cursor is "out of sync" with the sprite cursor relative to the vRatio
. It "jumps" a bit, or a bit more, depending of the resized window size.
When the sprite cursor comes in contact with border, I do the following:
- Hide the sprite cursor
- Show the native cursor
- Set the native cursor's location to sprite cursor's location (this does not work correctly anymore)
I feel like there's a simple math solution to this but I cannot figure it out (I've tried things... but..).
I hope my question isn't too vague, and that I provided enough information!