glClear(GL_COLOR_BUFFER_BIT);
i have a problem with glClear(GL_COLOR_BUFFER_BIT);
the program crash when it arrives at glClear(GL_COLOR_BUFFER_BIT);
and when i change a little the function which compute normal it works
Strange. You''re not going into much detail - what do you change exactly?
Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
at what point in the program are calling "glClear"?
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
here is the display function
void display ( void )
{
glClear(GL_COLOR_BUFFER_BIT); // crash here
glLightfv ( GL_LIGHT0,GL_POSITION,light_pos );
glPushMatrix ( );
//glTranslatef ( -700.0, 800.0, -2500.0 ); //pour courbe
if (mode==1)
glTranslatef ( -700.0, 800.0, -2500.0 );
if (mode==2)
glTranslatef ( -700.0, 800.0, -2500.0 );
if (mode==3)
glTranslatef ( -100.0, 150.0, -300.0 );
if (mode==4)
glTranslatef ( -100.0, 150.0, -300.0 );
//glTranslatef ( -100.0, 150.0, -300.0 );
glRotatef ( angle2, 1.0, 0.0, 0.0 );
glRotatef ( angle, 0.0, 1.0, 0.0 );
if (mode==1)
dessin_3d_sans_moyenne ();
if (mode==2)
dessin_3d_avec_moyenne ();
if (mode==3)
dessin_3d_avec_pxyz1 ();
if (mode==4)
dessin_3d_avec_pxyz1_moyenne ();
//dessiner_courbe();
//dessin_3d_sans_moyenne ();
//dessin_3d_avec_moyenne ();
//dessin_3d_avec_pxyz1 ();
printf("coucou3 et mode=%d\n", mode);
glPopMatrix ( );
glutSwapBuffers ( );
}
here is the main function (it crashs when menu==4, but works when menu==1 2 or 3)
int main ( int argc, char** argv )
{
int menu;
initialise_tableau1 (); //pxyz et pxyz1 rempli
enleve_chiffre_apres_virgule ();
printf("\nEntrer \t1.pour dessin 3d\n\t2.pour courbes de niveaux\n");
scanf("%d", &menu);
if(menu==1)
{
printf("Entrer \t1.pour en entier\n\t2.pour en entier moyenne\n\t3.pour tous les chiffres\n\t4.pour tous les chiffres avec moyenne");
scanf("%d", &menu);
if (menu==1)
mode=1;
else
if (menu==2)
mode=2;
else
if (menu==3)
mode=3;
else
mode=4;
printf("mode=%d\n", mode);
}
if (mode==1)
calcul_normales_pxyz ();
if (mode==2)
{
moyenne_point_pxyz();
calcul_normales_moyenne ();
}
if(mode==3)
calcul_normales_pxyz1 ();
if (mode==4)
{
moyenne_point_pxyz1();
calcul_normales_moyenne ();
}
glutInit ( &argc, argv );
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize ( 640, 480 );
glutCreateWindow ( argv[0] );
init ( );
glutReshapeFunc ( reshape );
glutMouseFunc ( mouse );
glutMotionFunc ( motion );
glutKeyboardFunc ( keyboard );
glutSpecialFunc (vSpecial );
glutDisplayFunc ( display );
glutIdleFunc ( idle_func );
glutMainLoop ( );
return 0;
}
the only difference between what i do when menu==2 that when menu==4 is that i compute the z of each point of a matrix by the average of the points near it. but when menu==2, the points are integer and became double because of the average and when menu==4 the points are double and stay double.
and then i compute normal with this z.
i don''t see what can do this crash, there is almost no difference.
here is the 3 functions in information that i call when menu=2 and when menu=4
void calcul_normales_moyenne ()
{
long int i;
long int stop;
double normalisation;
if ((normale = (XYZ1 *)malloc((nv)*sizeof(XYZ1))) == NULL) { //changer long.... attention remettre comme avant?
fprintf(stderr,"TRIANGULATE - Unable to allocate enough memory\n");
return;
}
//les 4 bords.
i=0;
while(i {
normale.x= 0.0;
normale.y= 0.0;<br> normale.z= 1.0;<br> i++;<br> }<br><br> i=resolution*(resolution-1);<br> stop=(resolution*resolution);<br> while(i<stop) //bord inferieur<br> {<br> normale.x= 0.0;<br> normale.y= 0.0;<br> normale.z= 1.0;<br> i++;<br> }<br><br> i=resolution;<br> stop=(((resolution-1)*resolution));<br> while(i<stop) //bord gauche et droit en meme temps + pas repeter les 4 coins.<br> {<br> normale.x= 0.0;<br> normale.y= 0.0;<br> normale.z= 1.0;<br><br> if ((i%resolution)==(resolution-1))<br> i++;<br> else<br> i=i+resolution-1;<br> }<br><br> i=resolution+1;<br> stop=(((resolution-1)*resolution)-1);<br> while(i<stop) //l''interieur de la matrice<br> {<br> normalisation=sqrt(4*0.25+(moyenne[i-1].z-moyenne[i+1].z)*(moyenne[i-1].z-moyenne[i+1].z) +<br> (moyenne[i-512].z-moyenne[i+512].z)*(moyenne[i-512].z-moyenne[i+512].z));<br><br> normale.x= ((moyenne[i-1].z-moyenne[i+1].z)/normalisation);<br> normale.y= ((moyenne[i+512].z-moyenne[i-512].z)/normalisation);<br> normale.z= ((2*0.5)/normalisation);<br><br> if ((i%resolution)==(resolution-2))<br> i=i+3; //ligne suivante apres le bord<br> else<br> i++;<br> }<br>}<br><br><br>void moyenne_point_pxyz()<br>{<br> int i, stop, normalisation;<br> if ((moyenne = (XYZ1 *)malloc((nv)*sizeof(XYZ1))) == NULL) {<br> fprintf(stderr,"TRIANGULATE - Unable to allocate enough memory\n");<br> return;<br> }<br><br> //les 4 coins<br> moyenne[0].z=((pxyz[1].z+pxyz[512].z+pxyz[513].z+pxyz[0].z)/4);<br> moyenne[511].z=((pxyz[510].z+pxyz[1022].z+pxyz[1023].z+pxyz[511].z)/4);<br> moyenne[511*512].z=((pxyz[511*512+1].z+pxyz[(511*512)-512].z+pxyz[(511*512)-511].z+pxyz[511*512].z)/4);<br> moyenne[(512*512)-1].z=((pxyz[(512*512)-2].z+pxyz[(512*512)-513].z+pxyz[(512*512)-514].z+pxyz[(512*512)-1].z)/4);<br><br> //les 4 bords.<br> i=1;<br> while(i<resolution-1) //bord superieur<br> {<br> moyenne.z= ( ((double) (pxyz.z+pxyz[i-1].z+pxyz[i+1].z+pxyz[i+512].z+pxyz[i-1+512].z+pxyz[i+1+512].z)/6) );<br>i++;<br> }<br><br> i=(resolution*(resolution-1))+1;<br> stop=(resolution*resolution)-1;<br> while(i<stop) //bord inferieur<br> {<br> moyenne.z= ((pxyz.z+pxyz[i-1].z+pxyz[i+1].z+pxyz[i-512].z+pxyz[i-1-512].z+pxyz[i+1-512].z)/6);<br> i++;<br> }<br><br> i=resolution;<br> stop=((resolution-1)*resolution);<br> while(i<stop) //bord gauche<br> {<br> moyenne.z= ((pxyz.z+pxyz[i+1].z+pxyz[i-512].z+pxyz[i+512].z+pxyz[i+1+512].z+pxyz[i+1-512].z)/6);<br> i++;<br> }<br><br> i=resolution+resolution-1;<br> stop=(resolution*resolution)-1;<br> while(i<stop) //bord droit<br> {<br> moyenne.z= ((pxyz.z+pxyz[i-1].z+pxyz[i-512].z+pxyz[i+512].z+pxyz[i-1+512].z+pxyz[i-1-512].z)/6);<br> i++;<br> }<br><br> i=resolution+1;<br> stop=(((resolution-1)*resolution)-1);<br> while(i<stop) //l''interieur de la matrice<br> {<br> moyenne.z= ((pxyz.z+pxyz[i-1].z+pxyz[i+1].z+pxyz[i-512].z+pxyz[i+512].z+pxyz[i-512+1].z+pxyz[i-512-1].z+pxyz[i+512+1].z+pxyz[i-1+512].z)/9);<br><br> if ((i%resolution)==(resolution-2))<br> i=i+3; //ligne suivante apres le bord<br> else<br> i++;<br> }<br> <br><br>}<br><br><br><br>void moyenne_point_pxyz1()<br>{<br> int i, stop, normalisation;<br> if ((moyenne = (XYZ1 *)malloc((nv)*sizeof(XYZ1))) == NULL) {<br> fprintf(stderr,"TRIANGULATE - Unable to allocate enough memory\n");<br> return;<br> }<br><br> //les 4 coins<br> moyenne[0].z=((pxyz1[1].z+pxyz1[512].z+pxyz1[513].z+pxyz1[0].z)/4);<br> moyenne[511].z=((pxyz1[510].z+pxyz1[1022].z+pxyz1[1023].z+pxyz1[511].z)/4);<br> moyenne[511*512].z=((pxyz1[511*512+1].z+pxyz1[(511*512)-512].z+pxyz1[(511*512)-511].z+pxyz1[511*512].z)/4);<br> moyenne[(512*512)-1].z=((pxyz1[(512*512)-2].z+pxyz1[(512*512)-513].z+pxyz1[(512*512)-514].z+pxyz1[(512*512)-1].z)/4);<br><br> //les 4 bords.<br> i=1;<br> while(i<resolution-1) //bord superieur<br> {<br> moyenne.z= ( ((double) (pxyz1.z+pxyz1[i-1].z+pxyz1[i+1].z+pxyz1[i+512].z+pxyz1[i-1+512].z+pxyz1[i+1+512].z)/6) );<br> i++;<br> }<br><br> i=(resolution*(resolution-1))+1;<br> stop=(resolution*resolution)-1;<br> while(i<stop) //bord inferieur<br> {<br> moyenne.z= ((pxyz1.z+pxyz1[i-1].z+pxyz1[i+1].z+pxyz1[i-512].z+pxyz1[i-1-512].z+pxyz1[i+1-512].z)/6);<br> i++;<br> }<br><br> i=resolution;<br> stop=((resolution-1)*resolution);<br> while(i<stop) //bord gauche<br> {<br> moyenne.z= ((pxyz1.z+pxyz1[i+1].z+pxyz1[i-512].z+pxyz1[i+512].z+pxyz1[i+1+512].z+pxyz1[i+1-512].z)/6);<br> i++;<br> }<br><br> i=resolution+resolution-1;<br> stop=(resolution*resolution)-1;<br> while(i<stop) //bord droit<br> {<br> moyenne.z= ((pxyz1.z+pxyz1[i-1].z+pxyz1[i-512].z+pxyz1[i+512].z+pxyz1[i-1+512].z+pxyz1[i-1-512].z)/6);<br> i++;<br> }<br><br> i=resolution+1;<br> stop=(((resolution-1)*resolution)-1);<br> while(i<stop) //l''interieur de la matrice<br> {<br> moyenne.z= ((pxyz1.z+pxyz1[i-1].z+pxyz1[i+1].z+pxyz1[i-512].z+pxyz1[i+512].z+pxyz1[i-512+1].z+pxyz1[i-512-1].z+pxyz1[i+512+1].z+pxyz1[i-1+512].z)/9);<br><br> if ((i%resolution)==(resolution-2))<br> i=i+3; //ligne suivante apres le bord<br> else<br> i++;<br> }<br> }<br> </i>
void display ( void )
{
glClear(GL_COLOR_BUFFER_BIT); // crash here
glLightfv ( GL_LIGHT0,GL_POSITION,light_pos );
glPushMatrix ( );
//glTranslatef ( -700.0, 800.0, -2500.0 ); //pour courbe
if (mode==1)
glTranslatef ( -700.0, 800.0, -2500.0 );
if (mode==2)
glTranslatef ( -700.0, 800.0, -2500.0 );
if (mode==3)
glTranslatef ( -100.0, 150.0, -300.0 );
if (mode==4)
glTranslatef ( -100.0, 150.0, -300.0 );
//glTranslatef ( -100.0, 150.0, -300.0 );
glRotatef ( angle2, 1.0, 0.0, 0.0 );
glRotatef ( angle, 0.0, 1.0, 0.0 );
if (mode==1)
dessin_3d_sans_moyenne ();
if (mode==2)
dessin_3d_avec_moyenne ();
if (mode==3)
dessin_3d_avec_pxyz1 ();
if (mode==4)
dessin_3d_avec_pxyz1_moyenne ();
//dessiner_courbe();
//dessin_3d_sans_moyenne ();
//dessin_3d_avec_moyenne ();
//dessin_3d_avec_pxyz1 ();
printf("coucou3 et mode=%d\n", mode);
glPopMatrix ( );
glutSwapBuffers ( );
}
here is the main function (it crashs when menu==4, but works when menu==1 2 or 3)
int main ( int argc, char** argv )
{
int menu;
initialise_tableau1 (); //pxyz et pxyz1 rempli
enleve_chiffre_apres_virgule ();
printf("\nEntrer \t1.pour dessin 3d\n\t2.pour courbes de niveaux\n");
scanf("%d", &menu);
if(menu==1)
{
printf("Entrer \t1.pour en entier\n\t2.pour en entier moyenne\n\t3.pour tous les chiffres\n\t4.pour tous les chiffres avec moyenne");
scanf("%d", &menu);
if (menu==1)
mode=1;
else
if (menu==2)
mode=2;
else
if (menu==3)
mode=3;
else
mode=4;
printf("mode=%d\n", mode);
}
if (mode==1)
calcul_normales_pxyz ();
if (mode==2)
{
moyenne_point_pxyz();
calcul_normales_moyenne ();
}
if(mode==3)
calcul_normales_pxyz1 ();
if (mode==4)
{
moyenne_point_pxyz1();
calcul_normales_moyenne ();
}
glutInit ( &argc, argv );
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize ( 640, 480 );
glutCreateWindow ( argv[0] );
init ( );
glutReshapeFunc ( reshape );
glutMouseFunc ( mouse );
glutMotionFunc ( motion );
glutKeyboardFunc ( keyboard );
glutSpecialFunc (vSpecial );
glutDisplayFunc ( display );
glutIdleFunc ( idle_func );
glutMainLoop ( );
return 0;
}
the only difference between what i do when menu==2 that when menu==4 is that i compute the z of each point of a matrix by the average of the points near it. but when menu==2, the points are integer and became double because of the average and when menu==4 the points are double and stay double.
and then i compute normal with this z.
i don''t see what can do this crash, there is almost no difference.
here is the 3 functions in information that i call when menu=2 and when menu=4
void calcul_normales_moyenne ()
{
long int i;
long int stop;
double normalisation;
if ((normale = (XYZ1 *)malloc((nv)*sizeof(XYZ1))) == NULL) { //changer long.... attention remettre comme avant?
fprintf(stderr,"TRIANGULATE - Unable to allocate enough memory\n");
return;
}
//les 4 bords.
i=0;
while(i
normale.x= 0.0;
normale.y= 0.0;<br> normale.z= 1.0;<br> i++;<br> }<br><br> i=resolution*(resolution-1);<br> stop=(resolution*resolution);<br> while(i<stop) //bord inferieur<br> {<br> normale.x= 0.0;<br> normale.y= 0.0;<br> normale.z= 1.0;<br> i++;<br> }<br><br> i=resolution;<br> stop=(((resolution-1)*resolution));<br> while(i<stop) //bord gauche et droit en meme temps + pas repeter les 4 coins.<br> {<br> normale.x= 0.0;<br> normale.y= 0.0;<br> normale.z= 1.0;<br><br> if ((i%resolution)==(resolution-1))<br> i++;<br> else<br> i=i+resolution-1;<br> }<br><br> i=resolution+1;<br> stop=(((resolution-1)*resolution)-1);<br> while(i<stop) //l''interieur de la matrice<br> {<br> normalisation=sqrt(4*0.25+(moyenne[i-1].z-moyenne[i+1].z)*(moyenne[i-1].z-moyenne[i+1].z) +<br> (moyenne[i-512].z-moyenne[i+512].z)*(moyenne[i-512].z-moyenne[i+512].z));<br><br> normale.x= ((moyenne[i-1].z-moyenne[i+1].z)/normalisation);<br> normale.y= ((moyenne[i+512].z-moyenne[i-512].z)/normalisation);<br> normale.z= ((2*0.5)/normalisation);<br><br> if ((i%resolution)==(resolution-2))<br> i=i+3; //ligne suivante apres le bord<br> else<br> i++;<br> }<br>}<br><br><br>void moyenne_point_pxyz()<br>{<br> int i, stop, normalisation;<br> if ((moyenne = (XYZ1 *)malloc((nv)*sizeof(XYZ1))) == NULL) {<br> fprintf(stderr,"TRIANGULATE - Unable to allocate enough memory\n");<br> return;<br> }<br><br> //les 4 coins<br> moyenne[0].z=((pxyz[1].z+pxyz[512].z+pxyz[513].z+pxyz[0].z)/4);<br> moyenne[511].z=((pxyz[510].z+pxyz[1022].z+pxyz[1023].z+pxyz[511].z)/4);<br> moyenne[511*512].z=((pxyz[511*512+1].z+pxyz[(511*512)-512].z+pxyz[(511*512)-511].z+pxyz[511*512].z)/4);<br> moyenne[(512*512)-1].z=((pxyz[(512*512)-2].z+pxyz[(512*512)-513].z+pxyz[(512*512)-514].z+pxyz[(512*512)-1].z)/4);<br><br> //les 4 bords.<br> i=1;<br> while(i<resolution-1) //bord superieur<br> {<br> moyenne.z= ( ((double) (pxyz.z+pxyz[i-1].z+pxyz[i+1].z+pxyz[i+512].z+pxyz[i-1+512].z+pxyz[i+1+512].z)/6) );<br>i++;<br> }<br><br> i=(resolution*(resolution-1))+1;<br> stop=(resolution*resolution)-1;<br> while(i<stop) //bord inferieur<br> {<br> moyenne.z= ((pxyz.z+pxyz[i-1].z+pxyz[i+1].z+pxyz[i-512].z+pxyz[i-1-512].z+pxyz[i+1-512].z)/6);<br> i++;<br> }<br><br> i=resolution;<br> stop=((resolution-1)*resolution);<br> while(i<stop) //bord gauche<br> {<br> moyenne.z= ((pxyz.z+pxyz[i+1].z+pxyz[i-512].z+pxyz[i+512].z+pxyz[i+1+512].z+pxyz[i+1-512].z)/6);<br> i++;<br> }<br><br> i=resolution+resolution-1;<br> stop=(resolution*resolution)-1;<br> while(i<stop) //bord droit<br> {<br> moyenne.z= ((pxyz.z+pxyz[i-1].z+pxyz[i-512].z+pxyz[i+512].z+pxyz[i-1+512].z+pxyz[i-1-512].z)/6);<br> i++;<br> }<br><br> i=resolution+1;<br> stop=(((resolution-1)*resolution)-1);<br> while(i<stop) //l''interieur de la matrice<br> {<br> moyenne.z= ((pxyz.z+pxyz[i-1].z+pxyz[i+1].z+pxyz[i-512].z+pxyz[i+512].z+pxyz[i-512+1].z+pxyz[i-512-1].z+pxyz[i+512+1].z+pxyz[i-1+512].z)/9);<br><br> if ((i%resolution)==(resolution-2))<br> i=i+3; //ligne suivante apres le bord<br> else<br> i++;<br> }<br> <br><br>}<br><br><br><br>void moyenne_point_pxyz1()<br>{<br> int i, stop, normalisation;<br> if ((moyenne = (XYZ1 *)malloc((nv)*sizeof(XYZ1))) == NULL) {<br> fprintf(stderr,"TRIANGULATE - Unable to allocate enough memory\n");<br> return;<br> }<br><br> //les 4 coins<br> moyenne[0].z=((pxyz1[1].z+pxyz1[512].z+pxyz1[513].z+pxyz1[0].z)/4);<br> moyenne[511].z=((pxyz1[510].z+pxyz1[1022].z+pxyz1[1023].z+pxyz1[511].z)/4);<br> moyenne[511*512].z=((pxyz1[511*512+1].z+pxyz1[(511*512)-512].z+pxyz1[(511*512)-511].z+pxyz1[511*512].z)/4);<br> moyenne[(512*512)-1].z=((pxyz1[(512*512)-2].z+pxyz1[(512*512)-513].z+pxyz1[(512*512)-514].z+pxyz1[(512*512)-1].z)/4);<br><br> //les 4 bords.<br> i=1;<br> while(i<resolution-1) //bord superieur<br> {<br> moyenne.z= ( ((double) (pxyz1.z+pxyz1[i-1].z+pxyz1[i+1].z+pxyz1[i+512].z+pxyz1[i-1+512].z+pxyz1[i+1+512].z)/6) );<br> i++;<br> }<br><br> i=(resolution*(resolution-1))+1;<br> stop=(resolution*resolution)-1;<br> while(i<stop) //bord inferieur<br> {<br> moyenne.z= ((pxyz1.z+pxyz1[i-1].z+pxyz1[i+1].z+pxyz1[i-512].z+pxyz1[i-1-512].z+pxyz1[i+1-512].z)/6);<br> i++;<br> }<br><br> i=resolution;<br> stop=((resolution-1)*resolution);<br> while(i<stop) //bord gauche<br> {<br> moyenne.z= ((pxyz1.z+pxyz1[i+1].z+pxyz1[i-512].z+pxyz1[i+512].z+pxyz1[i+1+512].z+pxyz1[i+1-512].z)/6);<br> i++;<br> }<br><br> i=resolution+resolution-1;<br> stop=(resolution*resolution)-1;<br> while(i<stop) //bord droit<br> {<br> moyenne.z= ((pxyz1.z+pxyz1[i-1].z+pxyz1[i-512].z+pxyz1[i+512].z+pxyz1[i-1+512].z+pxyz1[i-1-512].z)/6);<br> i++;<br> }<br><br> i=resolution+1;<br> stop=(((resolution-1)*resolution)-1);<br> while(i<stop) //l''interieur de la matrice<br> {<br> moyenne.z= ((pxyz1.z+pxyz1[i-1].z+pxyz1[i+1].z+pxyz1[i-512].z+pxyz1[i+512].z+pxyz1[i-512+1].z+pxyz1[i-512-1].z+pxyz1[i+512+1].z+pxyz1[i-1+512].z)/9);<br><br> if ((i%resolution)==(resolution-2))<br> i=i+3; //ligne suivante apres le bord<br> else<br> i++;<br> }<br> }<br> </i>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement