Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8535055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:20:28+00:00 2026-06-11T10:20:28+00:00

I have probably a simple math problem that I’m having surprisingly hard time figuring

  • 0

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:

  1. Hide the sprite cursor
  2. Show the native cursor
  3. 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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:20:30+00:00Added an answer on June 11, 2026 at 10:20 am

    At first your window size matches that of OpenGLs. But when you resize the window, the projection must change. So at least a scaling factor is added. This explains why the cursors are not in sync.

    If you want to get them in sync all the time, you have to map window coordinates into world coordinates. This can be accomplished with gluUnProject OpenGL: gluUnProject. You are already doing that by hand but without considering the changes in resolution which leads to your problem.

    For completeness, the reverse, going from world coordinates to window coordinates, is also possible OpenGL: gluProject

    When using these functions, you have to get your hands on model matrix, projection matrix and the viewport. Use the functions of the glGet* family for that purpose. Be sure to load these matrices at a point where they are set correctly!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi all I have a (probably) simple problem but I just can't figure out
Probably something simple, but heres my problem, I have implememnted a simple captcha into
Probably something really simple, but I'm having some real trouble with it. I have
I have a probably quite simple to solve problem. I'm trying to parse this
This should probably have a simple answer I just can't figure out. Anyway, I
i have a - probably - simple problem with gVim under Ubuntu. I can't
OK, this sounds simple and or like something that should have probably been done
I'm a newbie with WPF and c# and have a (probably very simple) problem.
Have whats probably a simple problem with using parent in if and each statements
This is probably simple, but I have spent way too much time trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.