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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:30:56+00:00 2026-05-29T07:30:56+00:00

Like this question states – I want to convert a click (2D) into coordinates

  • 0

Like this question states – I want to convert a click (2D) into coordinates relating to the rendering on the screen. I have the function glutMouseFunc bound to my function (below) but can not make sense of the x and y that are passed in – they seem to be relating to distance in pixels from the top left corner.

I would like to know how to convert the x and y to world coordinates 🙂

void mouse(int button, int state, int x, int y) {
  switch(button) {
  case GLUT_LEFT_BUTTON:
    printf(" LEFT ");
    if (state == GLUT_DOWN) {
        printf("DOWN\n");
        printf("(%d, %d)\n", x, y);
    }
    else 
      if (state == GLUT_UP) {
        printf("UP\n");
      }
    break;

  default:
    break;
  }
  fflush(stdout);                             // Force output to stdout
}
  • 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-05-29T07:30:57+00:00Added an answer on May 29, 2026 at 7:30 am
    GLdouble ox=0.0,oy=0.0,oz=0.0;
    void Mouse(int button,int state,int x,int y) {
      GLint viewport[4];
      GLdouble modelview[16],projection[16];
      GLfloat wx=x,wy,wz;
    
      if(state!=GLUT_DOWN)
        return;
      if(button==GLUT_RIGHT_BUTTON)
        exit(0);
      glGetIntegerv(GL_VIEWPORT,viewport);
      y=viewport[3]-y;
      wy=y;
      glGetDoublev(GL_MODELVIEW_MATRIX,modelview);
      glGetDoublev(GL_PROJECTION_MATRIX,projection);
      glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&wz);
      gluUnProject(wx,wy,wz,modelview,projection,viewport,&ox,&oy,&oz);
      glutPostRedisplay();
    }
    

    Where ox, oy, oz are your outputted values

    http://hamala.se/forums/viewtopic.php?t=20

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

Sidebar

Related Questions

Kind of like this question I have many text snippets that I use many,
I have a schema like this <h1> 5/2009 <br/> Question: This is the question
I have found this question about the special function or in scheme: Joe Hacker
As the question states. The best example of this I have right now is
Like this question , except T-SQL instead of php. 206275947 = 2062759.47 etc. The
this question is like this one , except it's for PHP testing via browser.
You may think this question is like this question asked on StackOverflow earlier. But
I know a question like this was already asked, but the situation is a
It's quite possible a question like this has been asked before, but I can't
I had an interview days ago and was thrown a question like this. Q:

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.