1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include<GLUT/glut.h>
#include<GL/glut.h>
#include<stdlib.h>
void affichage(void) {
/* initialisation des pixels */
glClear(GL_COLOR_BUFFER_BIT);
/* dessin d'un polygone (rectongle) avec les sommets en (0.25, 0.25, 0.0) et
(0.75, 0.75, 0.0) */
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0); glVertex2f(-0.5, -0.5);
glColor3f(0.0, 1.0, 0.0); glVertex2f(0.5, -0.5);
glColor3f(1.0, 0.0, 1.0); glVertex2f(0.5, 0.5);
glColor3f(1.0, 1.0, 1.0); glVertex2f(-0.5, 0.5);
glEnd();
/* On force l'affichage du résultat */
glFlush();
}
void clavier(unsigned char touche, int x, int y) {
switch(touche) {
case 'p': /* affichage du carre plein */
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glutPostRedisplay();
break;
case 'f': /* affichage en mode fil de fer */
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glutPostRedisplay();
break;
case 's': /* affichage en mode sommets seuls */
glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
glutPostRedisplay();
break;
case 'q': /* la touche 'q' pour quitter le programme */
exit(0);
}
}
int main(int argc, char** argv) {
/* initialisation de glut et création de la fenêtre */
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowPosition(200, 200);
glutInitWindowSize(250, 250);
glutCreateWindow("Exemple1");
/* initialisation d'OpenGL */
glClearColor(0.0, 0.0, 0.0, 0.0);
/* On passe à 2 pixels pour des raisons de clarté */
glPointSize(2.0);
/* enregistrement des fonctions de rappel */
glutDisplayFunc(affichage);
glutKeyboardFunc(clavier);
/* entrée dans la boucle principale de glut */
glutMainLoop();
return 0;
} |
Partager