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 9071827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:00:55+00:00 2026-06-16T18:00:55+00:00

I’m using SDL and OpenGL for this project. My screen at program start up

  • 0

I’m using SDL and OpenGL for this project. My screen at program start up is 640 x 480 and so is my glOrtho setup. So the program starts out synchronized. But my program allows the user to create a selection with the mouse of a portion of the display to zoom into. For example, a user could select the area from 320,240 (_mouseStart) to 640,480 (_mouseEnd). This selection area is then passed into glOrtho so that it can center and zoom into the selected area. My problem is when I try to select an area of an already zoomed in area because SDL mouse coordinates are in the range from 0,0 to 640,480 instead of the new area selected which in this case was 320, 240 to 640,480. I need a way to calculate what the real mouse position is when trying to select and already zoomed in area.

I could not post pictures here but I have created a post in gamedev.net which you could refer to if you need more information. http://www.gamedev.net/topic/636257-opengl-2d-selection-scaling-multiple-times/

Here is where I calculate all the mouse position stuff after the user has selected an area (WHICH IS NOW CORRECT)

// modify mouse coordinates to fit scaled image
            _mouseStart.x = ((_mouseStart.x / SCREEN_WIDTH) * (_portionEnd.x - _portionStart.x)) + _portionStart.x;
            _mouseStart.y = ((_mouseStart.y / SCREEN_HEIGHT) * (_portionEnd.y - _portionStart.y)) + _portionStart.y;
            _mouseEnd.x = ((_mouseEnd.x / SCREEN_WIDTH) * (_portionEnd.x - _portionStart.x)) + _portionStart.x;
            _mouseEnd.y = ((_mouseEnd.y / SCREEN_HEIGHT) * (_portionEnd.y - _portionStart.y)) + _portionStart.y;

Here is how I reset glOrtho to center and display the selected area.

glLoadIdentity();
glOrtho(_portionStart.x, _portionEnd.x, _portionEnd.y, _portionStart.y, 1, -1);
  • 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-16T18:00:57+00:00Added an answer on June 16, 2026 at 6:00 pm

    I created an image which explains the process (i hope)

    • The blue rectangle is your (unzoomed) base viewport.
    • The small green rectangle is the area selected in the base viewport
    • The large green rectangle is the new zoomed viewport
    • Within the zoomed viewport a new rectangle is selected (the red one)

    The red coordinates at the red rectangle are the coordinates you should get from your mouse position. You can use this coordinates to compute the values for your current zoomed viewport (the green coordinates). To get the final unzoomed coordinates (the blue values) you have to add the offset of the green rectangle (228,88).

    Please note that my example isn’t the best because the offset of the green rectangle and the height of the green rectangle are identical (both values are 228)

    computation

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
this is what i have right now Drawing an RSS feed into the php,

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.