// Computer Graphics - Amir Hesami // This program shows the effect of the mouse callback function. // freehand1.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() GLsizei wh=500,ww=500;// initial window size void display(void); void init(void); void mouse(int,int,int,int); void mydisplay(int x1,int y1); void reshape(int w, int h); void key(unsigned char, int, int); int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500, 500); glutInitWindowPosition(100,100); glutCreateWindow("FREEHAND 1"); init(); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutDisplayFunc(display); glutMainLoop(); return 0; } 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); glFlush(); } 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); glFlush(); } void mouse(int button, int state, int x, int y) { static int x1,y1,x2,y2; if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN) { x1=x; y1=wh-y; } mydisplay(x1,y1); }