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
| void dessiner()
{
int NbLignes = 5;
int NbColones = 5;
int Matrice[NbColones][NbLignes];
srand(time(NULL));
for(int i=0; i<NbColones; i++)
{
for(int j=0; j<NbLignes; j++)
{
Matrice[i][j] = 0;
}
}
for(int i=0; i<NbColones; i++)
{
for(int j=0; j<NbLignes; j++)
{
Matrice[i][j]=rand()%2 ;
}
}
glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION );
glLoadIdentity( );
glBegin(GL_QUADS);
for(int i=0;i<NbColones;i++)
{
for(int j=0;j<NbLignes;j++)
{
if(Matrice[i][j] == 1)
{
glColor3d(0,0,0);
glVertex2d(i,j);
glVertex2d(i,j+0.1);
glVertex2d(i+0.1,j+0.1);
glVertex2d(i+0.1,j);
}
}
}
glEnd();
glFlush();
SDL_GL_SwapBuffers();
}
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("Hello world!",NULL);
SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
int continuer = 1;
SDL_Event event;
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
}
dessiner();
}
SDL_Quit();
return 0;
} |
Partager