/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Avril 2001 */
/* Illustration de l'utilisation */
/* de la souris en OpenGL + Aux */
#include <stdio.h>
#include <GL/glaux.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "moduleCouleurs.h"
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_position[] = { 1.0F,1.0F,1.0F,0.0F };
glLightfv(GL_LIGHT0,GL_AMBIENT,couleurNoir());
glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurBlanc());
glLightfv(GL_LIGHT0,GL_SPECULAR,couleurBlanc());
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] ;
}
int main(int argc,char **argv) {
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);
return(0);
}