Advertisement
Tusohian

POINTS of Mouse

Apr 5th, 2019
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <GL/glut.h>
  2. #include<stdlib.h>
  3. #include<stdio.h>
  4. #include<iostream>
  5. int ww=600,wh=400;
  6. int first=0;
  7.  
  8.  
  9.  
  10. void drawLine()
  11. {
  12.  
  13. }
  14.  
  15.  
  16. void display()
  17. { glClearColor(0.0,0.0,0.0,1.0);
  18. glClear(GL_COLOR_BUFFER_BIT);
  19. glFlush();
  20. }
  21.  
  22.  
  23. void mouse(int btn,int state,int x,int y)
  24. {
  25. if(btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
  26. {
  27. exit(1);
  28. }
  29.  
  30. else if(btn == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
  31. {
  32. printf("%d %d\n", x,y);
  33. glBegin(GL_POINTS);
  34. glVertex2f(x,wh-y);
  35.  
  36. glEnd();
  37. glFlush();
  38.  
  39. }
  40. }
  41.  
  42. void reshape()
  43. {
  44. glViewport(0,0,ww,wh);
  45. glMatrixMode(GL_PROJECTION);
  46. glLoadIdentity();
  47. gluOrtho2D(0.0,(GLdouble)ww,0.0,(GLdouble)wh);
  48. glMatrixMode(GL_MODELVIEW);
  49. }
  50.  
  51.  
  52. int main(int argc,char** argv)
  53. {
  54. glutInit(&argc,argv);
  55. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  56. glutInitWindowSize(ww,wh);
  57. glutCreateWindow("Draw Line With Mouse Click");
  58. glutDisplayFunc(display);
  59. reshape();
  60. glutMouseFunc(mouse);
  61. glutMainLoop();
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement