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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:05:36+00:00 2026-05-17T03:05:36+00:00

The issue is that the further the mouse click is from the top left

  • 0

The issue is that the further the mouse click is from the top left origin (0,0) the greater the height inaccuracy when the vertex is plotted. Any ideas?

int WindowWidth = 19;
int WindowHeight = 13;
int mouseClickCount = 0;
int rectPlotted;
GLint x1;
GLint y1;
GLint x2;
GLint y2;

//Declare our functions with prototypes:
void display(void);
void init (void);
void processNormalKeys(unsigned char key, int x, int y);
void on_vertex_selected(GLint x, GLint y);
void on_mouse_event(int button, int state, int x, int y);
/////////////////////////////////// MAIN ////////////////////////////////
int main(int argc, char** argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  //start calculation of max window size available at 19:13 aspect ratio
  int screenWidth = glutGet(GLUT_SCREEN_WIDTH);
  int screenHeight = glutGet(GLUT_SCREEN_HEIGHT);
  screenWidth = screenWidth/WindowWidth;
  WindowWidth = WindowWidth*screenWidth;
  screenHeight = screenHeight/WindowHeight;
  WindowHeight = screenHeight*WindowHeight;
  //end calculation
  glutInitWindowSize (WindowWidth, WindowHeight);
  glutInitWindowPosition (0, 0);
  glutCreateWindow ("Plot a rectangle!");
  glutDisplayFunc(display);
  glutKeyboardFunc(processNormalKeys);
  glutMouseFunc(on_mouse_event);
  init();
  glutMainLoop();
  return 0;
}
/////////////////////////////////////////////////////////////////////////

void display(void)
{
 glClear (GL_COLOR_BUFFER_BIT); //clear all pixels
 glFlush();
}

void init (void)
{
  /* select clearing (background) color */
  glClearColor (1.0, 1.0, 1.0, 0.0);

  /* initialize viewing values */
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0, WindowWidth, 0, WindowHeight, -1.0, 1.0);
}

void processNormalKeys(unsigned char key, int x, int y) {
 if (key == 27) //esc
  exit(0);
//Allows color change of most recently plotted rectangle
 if (key == 98){ //b
  glColor3f(0.0, 0.0, 1.0);
  glBegin(GL_QUADS);
  glVertex2i(x1, y1);
  glVertex2i(x1, y2);
  glVertex2i(x2, y2);
  glVertex2i(x2, y1);
  glEnd();
  glFlush();
 }
 if (key == 114){ //r
  glColor3f(1.0, 0.0, 0.0);
  glBegin(GL_QUADS);
  glVertex2i(x1, y1);
  glVertex2i(x1, y2);
  glVertex2i(x2, y2);
  glVertex2i(x2, y1);
  glEnd();
  glFlush();
 }
 if (key == 103){ //g
  glColor3f(0.0, 1.0, 0.0);
  glBegin(GL_QUADS);
  glVertex2i(x1, y1);
  glVertex2i(x1, y2);
  glVertex2i(x2, y2);
  glVertex2i(x2, y1);
  glEnd();
  glFlush();
 }
}

void on_vertex_selected(GLint x, GLint y){
 if(mouseClickCount == 0){
  x1 = x;
  y1 = y;
  glColor3f(0.0, 0.0, 0.0);
  glEnable(GL_POINT_SMOOTH);
  glPointSize(5.0);
  glBegin(GL_POINTS);
  glVertex2i(x1, y1);
  glEnd();
  glFlush();
 }
 else{
  x2 = x;
  y2 = y;
  glBegin(GL_POINTS);
  glColor3f(1.0, 1.0, 1.0);
  glVertex2i(x1,y1); //"clears" previous point to make way for the rectangle
  glEnd();
  glColor3f(0.0, 0.0, 0.0);
  glBegin(GL_QUADS);
  glVertex2i(x1, y1);
  glVertex2i(x1, y2);
  glVertex2i(x2, y2);
  glVertex2i(x2, y1);
  glEnd();
  glFlush();
 }
}

void on_mouse_event(int button, int state, int x, int y){
 if(button==GLUT_LEFT_BUTTON && state ==GLUT_DOWN && mouseClickCount == 0){
  //y = y+20; //adjusts for VM mouse tracking error
  on_vertex_selected(x, WindowHeight - y);
  rectPlotted = 0;
    }
 if(button==GLUT_LEFT_BUTTON && state ==GLUT_UP && mouseClickCount == 0){
  if(rectPlotted == 1){
   return;
  }
  else{
   mouseClickCount++;
  }
 }
 if(button==GLUT_LEFT_BUTTON && state ==GLUT_DOWN && mouseClickCount == 1){
   //y = y+20; //adjusts for VM mouse tracking error
   on_vertex_selected(x, WindowHeight - y);
   mouseClickCount = 0;
   rectPlotted = 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-05-17T03:05:36+00:00Added an answer on May 17, 2026 at 3:05 am

    I was compiling and running my code within Parallels VM v.6. This was the issue leading to inaccurate mouse coordinates being returned. I compiled and ran the exact same code on OS X without problem.

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

Sidebar

Related Questions

This question follows on from a previous question, that has raised a further issue.
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
So I have an issue that I'm not 100% sure on how to solve.
I have an issue that (I think) might have to do with scope, but
I have an issue that is driving me nuts and hoping someone can help.
I am having an issue that I can't seem to figure out. Hopefully somebody
I have an issue that seems like very flaky behavour, is this a problem
I have an issue that looks like a race condition with a webview callback
There is an issue that I cannot solve, I've been looking a lot in
I have a strange issue that has arisen recently: Whenever I enter text, even

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.