Advertisement
Shishu

mouse callback in visual stdio

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