/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Avril 2001 */
/* L'animation en OpenGL */
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <stdio.h>
#include "ModuleMenus.h"
#include "ModuleCouleurs.h"
static float x = 0.0F ;
static float y = 20.0F ;
static float dx = 1.13F ;
static float dy = 0.97F ;
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 display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(x,y,0.0F);
glutSolidSphere(10.0,36,36);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void reshape(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 idle(void) {
x += dx ;
y += dy ;
if ( x < -w/2+10 )
dx = -dx ;
if ( y < -h/2+10 )
dy = -dy ;
if ( x >= w/2-10 )
dx = -dx ;
if ( y >= h/2-10 )
dy = -dy ;
glutPostRedisplay() ;
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(300,300);
glutInitWindowPosition(50,50);
glutCreateWindow("Une sphère se déplaçant toute seule");
myinit();
creationMenuBasique();
glutIdleFunc(idle);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}