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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#include <GL/glut.h>
////// Ta grille doit être définit quelque part, elle se nommera grille
using namespace std;
static int win_x = 60; //taille de ta fenetre horizontale
static int win_y = 60; //taille verticale
float booltofloat(bool b)
{
if(b)
return 1.0f;
else
return 0.0f;
}
static void dessineGrille ()
{
int i, j;
float x, y, d00, d01, d10, d11;
float N = 6.0f; //taille du tableau hor
float M = 6.0f; //vert
float hx = 1.0f/6.0f;
float hy = 1.0f/6.0f;
//on commence le dessin
//il y a peut être d'autre moyen que d'utiliser GL_QUADS, mais je ne connais pas énormement
glBegin ( GL_QUADS );
for ( i=0 ; i<6 ; i++ ) {
x = (i-0.5f)*hx;
for ( j=0 ; j<6 ; j++ ) {
y = (j-0.5f)*hy;
d00 = booltofloat(grille[i][j].couleur);//pour avoir quelque chose d'uniforme
d01 = booltofloat(grille[i][j].couleur);
d10 = booltofloat(grille[i][j].couleur);
d11 = booltofloat(grille[i][j].couleur);
glColor3f ( d00, d00, d00 );
glVertex2f ( x, y );
glColor3f ( d10, d10, d10 );
glVertex2f ( x+hx, y );
glColor3f ( d11, d11, d11 );
glVertex2f ( x+hx, y+hy );
glColor3f ( d01/2, d01/2, d01 );
glVertex2f ( x, y+hy );
}
}
glEnd ();
}
static void getMouvement ()
{
}
static void affichageCommence ( void )
{
glViewport ( 0, 0, win_x, win_y );
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ();
gluOrtho2D ( 0.0, 1.0, 0.0, 1.0 );
glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
glClear ( GL_COLOR_BUFFER_BIT );
}
static void affichageTermine ( void )
{
glutSwapBuffers ();
}
static void floglutClavier (unsigned char key, int x, int y )
{
switch ( key )
{
case 'q':
case 'Q':
exit ( 0 );
break;
}
}
static void floglutMouse ( int button, int state, int x, int y )
{
omx = mx = x;
omx = my = y;
mouse_down[button] = state == GLUT_DOWN;
}
static void floglutMouvementSouris ( int x, int y )
{
mx = x;
my = y;
}
static void floglutRedimensionnement ( int width, int height )
{
glutSetWindow ( win_id );
glutReshapeWindow ( width, height );
win_x = width;
win_y = height;
}
static void floglutPrincipal ()
{
getMouvement ();
glutSetWindow ( win_id );
glutPostRedisplay ();
}
static void floglutAffiche ()
{
affichageCommence();
dessineGrille();
affichageTermine ();
}
void fonctionalancer ()
{
glutInitDisplayMode ( GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowPosition ( 0, 0 );
glutInitWindowSize ( win_x, win_y );
win_id = glutCreateWindow ( "millie" );
glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
glClear ( GL_COLOR_BUFFER_BIT );
glutSwapBuffers ();
glClear ( GL_COLOR_BUFFER_BIT );
glutSwapBuffers ();
glutKeyboardFunc ( floglutClavier );
glutMouseFunc ( floglutMouse );
glutMotionFunc ( floglutMouvementSouris );
glutReshapeFunc ( floglutRedimensionnement );
glutIdleFunc ( floglutPrincipal );
glutDisplayFunc ( floglutAffiche );
} |
Partager