// Computer Graphics - Amir Hesami // This program shows the effect of the mouse motion callback function. // freehand2.cpp #include #pragma comment(lib, "opengl32.lib") // Link OpenGL32.lib #pragma comment(lib, "glu32.lib") // Link Glu32.lib #pragma comment(lib, "glut32.lib") // Link Glut32.lib #pragma comment(linker, "/entry:\"mainCRTStartup\"" ) // set the entry point to be main() #pragma comment(linker, "/subsystem:\"Windows\"" ) // set the entry point to be main() #define passive 0 #define active 1 void display(); void reshape(GLsizei, GLsizei); void init(); void mydisplay(int ,int); void mousemotion(int, int); const int wh=500,ww =500; //The size of the window int main(int argc, char** argv) { int mode=active; glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(ww,wh); glutInitWindowPosition(100,100); glutCreateWindow("Mouse Motion Freehand"); glutDisplayFunc(display); glutReshapeFunc(reshape); if (mode==active) glutMotionFunc(mousemotion); else glutPassiveMotionFunc(mousemotion); init(); glutMainLoop(); return 0; } void mousemotion(int mousex, int mousey) { GLint x = mousex; GLint y = wh - mousey; mydisplay(x,y); } void display(void) {} void mydisplay(int xmin,int ymin) { glColor3f(1.0,0.0,0.0); glPointSize(3.0); glBegin(GL_POINTS); glVertex2i(xmin,ymin); glEnd(); glFlush(); } void init(void) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, (GLdouble)ww,0.0 , (GLdouble)wh,-1.0,1.0); glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); } void reshape(int ww, int wh) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, (GLdouble)ww,0.0 , (GLdouble)wh,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0,0,ww, wh); glClearColor(1.0,1.0,1.0,1.0); glClear(GL_COLOR_BUFFER_BIT); }