/* Auteur: Nicolas JANEY */ /* Avril 2001 */ /* Illustration de l'utilisation */ /* de la souris en OpenGL + Aux */ #include "windows.h" #include #include #include #include static float x = 0.0F ; static float y = 0.0F ; static float w = 0.0F ; static float h = 0.0F ; void myinit(void) { GLfloat light_ambient[] = { 0.0F,0.0F,0.0F,1.0F }; GLfloat light_diffuse[] = { 1.0F,1.0F,1.0F,1.0F }; GLfloat light_specular[] = { 1.0F,1.0F,1.0F,1.0F }; GLfloat light_position[] = { 1.0F,1.0F,1.0F,0.0F }; glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular); glLightfv(GL_LIGHT0,GL_POSITION,light_position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); } void CALLBACK display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(x,y,0.0F); auxSolidSphere(10.0); glPopMatrix(); glFlush(); auxSwapBuffers(); } void CALLBACK myReshape(int ww,int hh) { w =(float) ww ; h =(float) hh ; glViewport(0,0,ww,hh); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-w/2,w/2,-h/2,h/2,-10.0,10.0); glMatrixMode(GL_MODELVIEW); } void CALLBACK mouseUp(AUX_EVENTREC *event) { x =(float) event->data[AUX_MOUSEX] - w/2 ; y =(float) h/2 - event->data[AUX_MOUSEY] ; } void main(void) { auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH); auxInitPosition(0,0,300,300); auxInitWindow("Une sphère déplacée à la souris"); myinit(); auxMouseFunc(AUX_LEFTBUTTON,AUX_MOUSEUP,mouseUp); auxMouseFunc(AUX_RIGHTBUTTON,AUX_MOUSEUP,mouseUp); auxReshapeFunc(myReshape); auxMainLoop(display); }