Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include <gl/glut.h>
  2. #include <stdio.h>
  3. #define GLUT_DISABLE_ATEXIT_HACK
  4. //Clipping window limits
  5. float xwmin=0, xwmax=640, ywmin=0, ywmax=480;
  6. //Application window dimensions
  7. int windowWidth=640, windowHeight=480;
  8. GLfloat xw1=0,yw1=0;
  9. GLfloat xw2=xw1+20,yw2=yw1+20;
  10. void display()
  11. {
  12. glClearColor(1,1,1,0);
  13. glClear(GL_COLOR_BUFFER_BIT);
  14. glRectf(xw1,yw1,xw2,yw2);
  15. glFlush();
  16. }
  17. void mouseButtonClicked(int button,int state,int x, int y)
  18. {
  19. if(state==GLUT_DOWN)
  20. {
  21. printf("Mouse click event detected (button down).\n");
  22. //Converting coordinates captured by event handler to world coordinates
  23. xw1=(float)(xwmin+(float)(x)*(xwmax-xwmin)/(float)(windowWidth));
  24. yw1=(float)(ywmin+(float)(windowHeight-y)*(ywmax-ywmin)/(float)(windowHeight));
  25. xw2=xw1+20;
  26. yw2=yw1+20;
  27. if (button==GLUT_LEFT_BUTTON)
  28. glColor3f(1,0,0);
  29. else if (button==GLUT_MIDDLE_BUTTON)
  30. glColor3f(0,1,0);
  31. else if (button==GLUT_RIGHT_BUTTON)
  32. glColor3f(0,0,1);
  33. //Generate a display event
  34. glutPostRedisplay();
  35. }
  36. }
  37. int main(int argc, char** argv)
  38. {
  39. glutInit(&argc,argv);
  40. glutInitWindowPosition(50,50);
  41. glutInitWindowSize(windowWidth,windowHeight);
  42. glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
  43. glutCreateWindow("Mouse active motion events");
  44. glMatrixMode(GL_PROJECTION);
  45. gluOrtho2D(xwmin,xwmax,ywmin,ywmax);
  46. glutDisplayFunc(display);
  47. //glutMotionFunc(mouseActiveMotion);
  48. glutMouseFunc(mouseButtonClicked);
  49. glutMainLoop();
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement