OpenGL (glut) & rafraichissement par rapport à un array

cs_BirD Messages postés 90 Date d'inscription samedi 23 novembre 2002 Statut Membre Dernière intervention 28 avril 2010 - 6 oct. 2009 à 22:14
cs_BirD Messages postés 90 Date d'inscription samedi 23 novembre 2002 Statut Membre Dernière intervention 28 avril 2010 - 7 oct. 2009 à 17:49
Hello tout le monde,

Je débute avec Glut et j'ai une petite question concernant le rafraichissement d'une animation.

J'ai fait un petit algo de percolation (le grand classique : une foret qui brule). Cet algo consiste en la mise à jour d'une matrice N * N (N = 700 dans mon cas). Chaque case de la matrice contient soit :
- 0 : pas d'arbre
- 1 : un arbre
- 2 : un arbre qui brule
- 3 : un arbre qui a brulé

Au fur et à mesure de l'algo, la matrice évolue, des arbres brulent, d'autre cessent, etc. Mon objectif est de représenter cette évolution avec openGL (via glut). 1 pixel = 1 arbre.

J'ai donc d'un coté mon algo et d'un autre un fichier que j'ai nommé draw.h qui s'occupera de la représentation graphique. J'aimerais faire en sorte que chaque fois que je parcours ma matrice (pour mettre à jour la progression du feu), alors l'image se mette à jour. J'appelle donc la fonction suivante à chaque boucle :
int draw(int argc, char **argv, int *vlat,const int &vlx, const int &vly)

ou
- *vlat est un pointeur sur ma matrice
- vlx vly N
Mais mon problème est que l'image générée est statique... aucune évolution.

Voici le code de draw.h (il y a encore quelque trucs moche car c'est un brouillon)

#include 
#include <cstdlib>
#include <GL/glut.h>
using namespace std;

// function prototypes
void disp(void);
int xmax, ymax, *lat;

// window identifier
static int win;

void Timer(int extra)
{
glutPostRedisplay();
glutTimerFunc(30,Timer,0);
}

int draw(int argc, char **argv, int *vlat,const int &vlx, const int &vly){

//Makes the variables global
xmax = vlx;
ymax = vly;
lat = vlat;


//////////
// INIT //
//////////

// initialize glut
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);

// define the size
glutInitWindowSize(700,700);

// the position where the window will appear
glutInitWindowPosition(100,100);

// create the window, set the title and keep the 
// window identifier.
win = glutCreateWindow("Percolation");

//////////////
// CALLBACK //
//////////////

glutDisplayFunc(disp);

////////////
// OPENGL //
////////////

// define the color we use to clearscreen 
glClearColor(0.0,0.0,0.0,0.0);
glutTimerFunc(0,Timer,0);



// enter the main loop
glutMainLoop();

return 0;
}


void disp(void){

glClear(GL_COLOR_BUFFER_BIT);
int r[5], g[5], b[5];

//Define the colours we will use
r[0]= 1; g[0]= 1; b[0]= 1; //white
r[1]= 0; g[1]= 1; b[1]= 0; //green
r[2]= 1; g[2]= 0; b[2]= 0; //red
r[3]= 0; g[3]= 0; b[3]= 0; //black

//Begin of drawing
glBegin(GL_POINTS);
for (int y=0; y<ymax; y++){
for (int x=0; x<xmax; x++){
glColor3f(r[lat[y*xmax + x]], g[lat[y*xmax + x]],b[lat[y*xmax + x]]);
glVertex2d(((double)x/xmax*1.8)-0.9,((double)y/ymax*1.8)-0.9);	
}
}		 
glEnd();
//glFlush();

glutSwapBuffers();

//glutPostRedisplay();



}


En gros, je sais pas comment faire. Si j'appelle draw(...) à chaque parcours de boucle, alors tout l'initialisation se refait (en théorie, car en pratique rien ne se passe). Si j'appelle la fonction disp, rien ne se passe non plus.

Il faudrait appeler draw(....) et que la fonction attendent chaque modification sur la matrice... enfin, j'en ai aucune idée et ca fait trois heures que je poirotte la dessus.

Merci d'avance les collègues

BirD
A voir également:

1 réponse

cs_BirD Messages postés 90 Date d'inscription samedi 23 novembre 2002 Statut Membre Dernière intervention 28 avril 2010
7 oct. 2009 à 17:49
Hello,

Alors premièrement, oups, je me suis trompé. J'ai posté dans OpenGL/C plutot que OpenGL/C++

Ensuite, j'ai réussi à trouver une solution à mon problème. J'ai finalement créer un objet global percolation que je fais évoluer depuis ma fonction Display, sachant que glutDisplayFunc(Display);

Voila, peut-etre que ca aidera un autre newbe.

++ tous.

BirD
0
Rejoignez-nous