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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| #include <gl/glut.h>
#include <iostream>
#include <fstream>
using namespace std;
void affichage();
void clavier(unsigned char touche,int x,int y);
void reshape(int x,int y);
void idle();
void mouse(int bouton,int etat,int x,int y);
void Bresenham(int,int,int,int );
char presse;
int x,y,xold,yold;
int nbclik=0;
int tab[2][2];
int dx,dy,incX,incY,dp,xa,ya,xb,yb;
int main(int argc,char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("un carré");
glClearColor(0.0,0.0,0.0,0.0);
glColor3f(1.0,1.0,1.0);
glPointSize(2.0);
glutDisplayFunc(affichage);
glutKeyboardFunc(clavier);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}
void affichage(){
glClear(GL_COLOR_BUFFER_BIT);
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(0.0,0.0,1.0);
glVertex2f(0.5,0.5);
glColor3f(1.0,1.0,1.0);
glVertex2f(-0.5,0.5);
glEnd();
glFlush();
}
void clavier(unsigned char touche,int x,int y){
switch(touche){
case 'p':
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glutPostRedisplay();
break;
case 'f' :
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glutPostRedisplay();
break;
case 's':
glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
glutPostRedisplay();
break;
case 'd':
glEnable(GL_DEPTH_TEST);
glutPostRedisplay();
break;
case 'a' :
glBegin(GL_POINT);
glVertex2d(1,1);
glEnd();
glutPostRedisplay();
break;
case 'q':
exit(0);
}
}
void mouse(int bouton,int state,int x,int y){
if (bouton==GLUT_LEFT_BUTTON && state==GLUT_UP)
{
cout << "clik" << endl;
glBegin(GL_POINT);
glVertex2d(1,1);
glEnd();
glutPostRedisplay();
glFlush();
}
} |
Partager