Created
January 18, 2011 15:29
-
-
Save chtitux/784583 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <GL/glut.h> | |
#include <math.h> | |
#define WINDOW_WIDTH 300 | |
#define WINDOW_HEIGHT 300 | |
int obj = 0; | |
void Clavier(unsigned char touche, int x, int y) { | |
switch(touche) { | |
case 'p': | |
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); | |
break; | |
case 'f': | |
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); | |
break; | |
case 's': | |
glPolygonMode(GL_FRONT_AND_BACK,GL_POINT); | |
break; | |
case 'q': | |
exit(0); | |
case '1': | |
obj = 1; break; | |
case '2': | |
obj = 2; break; | |
case '3': | |
obj = 3; break; | |
case '4': | |
obj = 4; break; | |
case '5': | |
obj = 5; break; | |
case '6': | |
obj =6; break; | |
case '7': | |
obj = 7; break; | |
case '8': | |
obj = 8; break; | |
} | |
glutPostRedisplay(); | |
} | |
void timer(int extra) | |
{ | |
glutPostRedisplay(); | |
glutTimerFunc(10,timer,0); | |
} | |
void Display(void){ | |
float time = glutGet(GLUT_ELAPSED_TIME) / 500.0; | |
glClear(GL_COLOR_BUFFER_BIT); | |
glRotatef(1.0, 1.0, cos(time), sin(time)); | |
switch(obj) { | |
case 0: | |
glutWireSphere(0.7, 20, 20); | |
break; | |
case 1: | |
glutWireCube(0.7); | |
break; | |
case 2: | |
glutWireCone(0.3, 0.7, 20, 20); | |
break; | |
case 3: | |
glutWireTorus(0.2, 0.7, 20, 20); | |
break; | |
case 4: | |
glutWireTetrahedron(); | |
break; | |
case 5: | |
glutWireOctahedron(); | |
break; | |
case 6: | |
glutWireDodecahedron(); | |
break; | |
case 7: | |
glutWireIcosahedron(); | |
break; | |
case 8: | |
glutWireTeapot(0.7); | |
break; | |
} | |
glutSwapBuffers(); | |
//glFlush(); | |
} | |
void refenetrage(int w, int h) { | |
glViewport(0, 0, w, h); | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
if(h > w) | |
glOrtho(-1.0, 1.0, -1.0*h/w, 1.0*h/w, -1.0, 1.0); | |
else | |
glOrtho(-1.0*w/h, 1.0*w/h, -1.0, 1.0, -1.0, 1.0); | |
glMatrixMode(GL_MODELVIEW); | |
glLoadIdentity(); | |
} | |
int main(int argc, char* argv[]){ | |
glutInit(&argc, argv); | |
glutInitWindowSize( WINDOW_WIDTH, WINDOW_HEIGHT ); | |
glutInitWindowPosition( 100, 100 ); | |
glutCreateWindow("Test d'OpenGL et GLUT"); | |
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); | |
glOrtho(-1.0, 1.0 , -1.0, 1.0, -1.0, 1.0 ); | |
glClearColor(0.0, 0.0, 0.0, 0.0); | |
glutTimerFunc(0,timer,0); | |
glutReshapeFunc(refenetrage); | |
glutKeyboardFunc(Clavier); | |
glutDisplayFunc(&Display); | |
glutMainLoop(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment