Soyez le premier à donner votre avis sur cette source.
Vue 9 604 fois - Téléchargée 479 fois
#include <gl/glut.h> #include <math.h> //////////////////////////////////////////////////////// //Fenêtre GLUT int Win; double a=0,b=0,z=5; //Fonction d'initialisation void InitGL(); //Fonction de redimensionnement void Reshape(int w,int h); //Fonction de dessin void Draw(); float MatSpec[4] = {1.f,1.f,1.f,1.f}; float MatDif[4] = {.8f,.8f,.5f,1.f}; float MatAmb[4] = {.8f,.8f,.5f,1.f}; int LightPos[4] = {0,0,2,0}; float LightDif[4] = {.6f,1.f,1.f,1.f}; float LightSpec[4] = {.6f,1.f,1.f,1.f}; float LightAmb[4] = {.0f,.0f,1.1f,1.f}; int type; bool rouge=false; #define RESO_X 640 #define RESO_Y 480 #define RESO_BIT 16 #define RESO_REF 60 #define WIDTH 640 #define HEIGHT 480 //////////////////////////////////////////////////////// //souris void Mouse(int button, int state, int x, int y) { if(state==GLUT_UP) { if(x<=100 && y<=100) { if(rouge==false) { glClearColor(1,1,0,1); rouge=true; } else { glClearColor(2,0,1,1); rouge=false; } } if(x>=600 && y>=400) { if(rouge==false) { glClearColor(0,0,1,1); rouge=true; } else { glClearColor(0,0,0,1); rouge=false; } } } } //clavier void Clavier(unsigned char key, int x, int y) { switch(key) { case 'm': z++; break; case 'p': z--; break; case 'w': type = 2; break; case 's': type = 1; break; case 'x': type = 3; break; case 'd': type = 4; break; case 'c': type = 5; break; case 'f': type = 6; break; case 'v': type = 7; break; case 'g': type = 8; break; case 'b': type = 9; break; case 'h': type = 10; break; case 'n': type = 11; break; case 'j': type = 12; break; case 27: exit (0); break; } } int main( int argc, char *argv[ ]) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH ); glutInitWindowSize(WIDTH,HEIGHT); glutInitWindowPosition(50,50); Win=glutCreateWindow("Figures, couleurs, lumières"); glutReshapeFunc(Reshape); glutDisplayFunc(Draw); InitGL(); glutKeyboardFunc(Clavier); glutMouseFunc(Mouse); glutMainLoop(); return 0; } ////////////////////////////initialisation void InitGL() { glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,MatSpec); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MatDif); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,MatAmb); glMateriali(GL_FRONT_AND_BACK,GL_SHININESS,50); glLightfv(GL_LIGHT0,GL_DIFFUSE,LightDif); glLightfv(GL_LIGHT0,GL_SPECULAR,LightSpec); glLightfv(GL_LIGHT0,GL_AMBIENT,LightAmb); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glMatrixMode(GL_MODELVIEW); glPointSize(3); } ////////////////////////////taille de la fenetre void Reshape(int w,int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.,float(w)/float(h),0.1,200); glMatrixMode(GL_MODELVIEW); } //////////////////////////// void Draw() { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //gestion de la lumière// glLoadIdentity(); glTranslated(0,0,-z); glRotated(-2*a,0,1,0); glRotated(-3*b,1,0,0); glLightiv(GL_LIGHT0,GL_POSITION,LightPos); //creation d'un point representant la position de la lumiere// glDisable(GL_LIGHTING); glBegin(GL_POINTS); glVertex3iv(LightPos); glEnd(); glEnable(GL_LIGHTING); //fin// //creation d'une figure "glut"// glLoadIdentity(); glTranslated(0,0,-z); glRotated(a,0,1,0); glRotated(b,0,1,1); switch(type) { case 2: glutWireTeapot(1); break; case 1: glutSolidTeapot(1); break; case 3: glutWireSphere(1,50,50); break; case 4: glutSolidSphere(1,50,50); break; case 5: glutWireCube(1); break; case 6: glutSolidCube(1); break; case 7: glutWireCone(0.2,2,50,50); break; case 8: glutSolidCone(0.2,2,50,50); break; case 9: glutWireDodecahedron(); break; case 10: glutSolidDodecahedron(); break; case 11: glutWireOctahedron(); break; case 12: glutSolidOctahedron(); break; } //fin// b+=2; a+=1; glutSwapBuffers(); glutPostRedisplay(); }
J' ai trop kiffé la teillére !
par contre ché pas si c'est moi mais les mouvements par rapport a la souris sont pas la ou peu cohérents
@+
ROOT_DIEU
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.