[OPENGL] brique qui clignote

Salut, j’ai encore un problème et comme d’habitude je trouve pas la solution : mon problème c’est que j’ai une brique qui clignote anormalement : de temps en temps elle semble s’éteindre !!!

Voici la source :
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
#define PI 3.14159265

int theta=50;
void changePerspective();
void display();
void brique(void);
void calcTableCosSin();
void rotation();
float ang=0;
float inca=4;
int rotation_act=1;

float Sin[360],Cos[360];

/* Paramètres de lumière /
GLfloat L0pos[]={-4.0,4.0,3.0};
GLfloat L0dif[]={ 1.0,1.0,1.0};
GLfloat L1pos[]={ 1.7,4.5,2.0};
GLfloat L1dif[]={ 1.0,1.0,1.0};
GLfloat Mspec[]={ 0.7,0.7,0.7};
GLfloat Mshiny=5;
/
Fin paramètres de lumière */

int main(int argc,char **argv) {

// Initialisation d’OpenGL
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowPosition(200,200);
glutInitWindowSize(640,480);
glutCreateWindow(“essd”);

calcTableCosSin();
glClearColor(0.0,0.0,0.0,0.0);
glPointSize(1.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);

/* Paramétrage des lumières */
glShadeModel(GL_SMOOTH);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glLightfv(GL_LIGHT0,GL_DIFFUSE,L0dif);
glLightfv(GL_LIGHT0,GL_SPECULAR,L0dif);
glLightfv(GL_LIGHT1,GL_DIFFUSE,L1dif);
glLightfv(GL_LIGHT1,GL_SPECULAR,L1dif);

/* Paramétrage du matériau */
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,Mspec);
glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,Mshiny);

changePerspective();
glMatrixMode(GL_MODELVIEW);

// Fonctions de rappel
glutDisplayFunc(display);

// Entrée dans la boucle principale
glutMainLoop();
return 0;
}

void changePerspective()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(theta,1.0,0.1,40.0);
glMatrixMode(GL_MODELVIEW);
}

void display()
{
/* effacement de l’image avec la couleur de fond */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

/*Application des transfos de visualisation */

/CAMERA/
glTranslatef(-0.5,-0.75,-4.0);
glRotated(20.0,0.60,-1.0,-0.06);
/*CAMERA FIN */

/LUMIERES/
glLightfv(GL_LIGHT0,GL_POSITION,L0pos);
glLightfv(GL_LIGHT1,GL_POSITION,L1pos);
/LUMIERES FIN/

glPushMatrix();

if(rotation_act==1)
glutTimerFunc(30,rotation,0);
/* Dessin de la brique tournante */
glLoadIdentity();
glPopMatrix();
glPushMatrix();
glRotatef(ang,0.0,1.0,0.0);
brique();

glFlush();

/* On echange les buffers */
glutSwapBuffers();
}

void brique(void) {
// Fonction permettant de dessiner une brique
float tl2=25/100+.2;

glBegin(GL_POLYGON);
glColor3f(1.0,1.0,1.0); glVertex3f(-tl2, 0.2, tl2);
glColor3f(1.0,1.0,1.0); glVertex3f(-tl2, 0.0, tl2);
glColor3f(1.0,1.0,1.0); glVertex3f( tl2, 0.0, tl2);
glColor3f(1.0,1.0,1.0); glVertex3f( tl2, 0.2, tl2);
glEnd();

glBegin(GL_POLYGON);
glColor3f(1.0,1.0,1.0); glVertex3f( tl2,0.2, tl2);
glColor3f(1.0,1.0,1.0); glVertex3f( tl2,0.0, tl2);
glColor3f(1.0,1.0,1.0); glVertex3f( tl2,0.0,-tl2);
glColor3f(1.0,1.0,1.0); glVertex3f( tl2,0.2,-tl2);
glEnd();

glBegin(GL_POLYGON);
glColor3f(1.0,1.0,1.0); glVertex3f( tl2,0.2,-tl2);
glColor3f(1.0,1.0,1.0); glVertex3f( tl2,0.0,-tl2);
glColor3f(1.0,1.0,1.0); glVertex3f(-tl2,0.0,-tl2);
glColor3f(1.0,1.0,1.0); glVertex3f(-tl2,0.2 ,-tl2);
glEnd();

glBegin(GL_POLYGON);
glColor3f(1.0,1.0,1.0); glVertex3f(-tl2,0.2 ,-tl2);
glColor3f(1.0,1.0,1.0); glVertex3f(-tl2,0.0,-tl2);
glColor3f(1.0,1.0,1.0); glVertex3f(-tl2,0.0, tl2);
glColor3f(1.0,1.0,1.0); glVertex3f(-tl2,0.2 , tl2);
glEnd();

glBegin(GL_POLYGON);
glColor3f(1.0,1.0,1.0); glVertex3f(-tl2, 0.2 ,-tl2);
glColor3f(1.0,1.0,1.0); glVertex3f(-tl2, 0.2 , tl2);
glColor3f(1.0,1.0,1.0); glVertex3f( tl2, 0.2 , tl2);
glColor3f(1.0,1.0,1.0); glVertex3f( tl2, 0.2 ,-tl2);
glEnd();

glBegin(GL_POLYGON);
glColor3f(1.0,1.0,1.0); glVertex3f(-tl2,0,-tl2);
glColor3f(1.0,1.0,1.0); glVertex3f(-tl2,0, tl2);
glColor3f(1.0,1.0,1.0); glVertex3f( tl2,0, tl2);
glColor3f(1.0,1.0,1.0); glVertex3f( tl2,0,-tl2);
glEnd();

}

void calcTableCosSin()
{
/* calcul du tableau des sinus et cosinus /
int i;
for (i=0;i<360;i++) {
Cos[i]=cos(((float)i)/180.0
PI);
Sin[i]=sin(((float)i)/180.0*PI);
}
}

void rotation()
{
ang=ang+inca;
if (ang>360)
ang=ang-360;
glutPostRedisplay();
}

Voila, merci de me dire où ca ne va pas et aussi dites moi si mon utilisation de gluttimerfunc est correcte

Je n’ai pas tout lu, mais je te conseillerai de regarder les push & pop.

Et d’indenter :

glPushMatrix();
{
  
}
glPopMatrix();

En prenant l’habitude d’ouvrir un bloc à chaque fois tu sera sur d’avoir bien fait tes pops.

J’ai revu mes push et mes pop mais en les modifiant ca n’a rien donné :frowning: