i have a black window and i don’t manage to find the errors. At the beginning the function “lire_un_ase” worked.
It’s after to have translated in oriented object the program that i have a black window(with no errors at the compilation).
i think it comes from the display function because i haven’t touch at the function “lire_un_ase”. Can you help me ?
this is the code :
#include <iostream.h> #include <string.h> #include <conio.h> #include <stdlib.h> #include <GL/glut.h> #define nb_vertices 20000 #define nb_faces 20000 class lire_un_ase { public : struct donnees { float tab_vertices [nb_vertices][3] ; int tab_sommets [nb_faces][3] ; }; donnees tab_struct[50] ; int nb_indices[100] ; int i ; int j ; int m ; int b ; int a ; char tmp [100] ; char tmp2 [100] ; char tmp3 [100] ; int temp ; char passe_ligne [200] ; lire_un_ase () ; }; lire_un_ase *lecteur ; lire_un_ase::lire_un_ase () { char nom_fichier[] = "geosphere.ASE" ; FILE *pointeur ; //pointeur sur le fichier if ((pointeur = fopen(nom_fichier, "r")) == NULL) return ; do //compte le nombre d'objets { fscanf(pointeur, "%s", tmp) ; if(strcmp ("*MESH", tmp) == 0) { a++ ; } } while (!feof(pointeur)) ; fseek (pointeur, 0,SEEK_SET) ; //cout<< a ; for (b=0; b<a ;b++) { do { fscanf(pointeur, "%s", tmp) ; } while (strcmp ("*MESH_VERTEX", tmp) != 0) ; //passe toutes les chaines en revue jusqu'a qu'a ce que tmp soit égal à chaine ("*MESH_VERTEX")
do//rempli le tableau de structure avec des coordonnées de vertices { fscanf (pointeur, "%d%f%f%f%s", &(temp) ,&(tab_struct[b].tab_vertices[i][0]), &(tab_struct[b].tab_vertices[i][1]),&(tab_struct[b].tab_vertices[i][2]), tmp) ; //cout << tab_struct[b].tab_vertices[i][0]<<" "<<tab_struct[b].tab_vertices[i][1]<<" "<< tab_struct[b].tab_vertices[i][2]<<endl ; i++ ; } while (strcmp (tmp, "}")!=0) ; i=0 ; do { fscanf(pointeur, "%s", tmp2) ; } while (strcmp ("A:", tmp2) != 0) ; do //rempli le tableau de la structure avec le numero des sommets {
fscanf (pointeur, "%d%s%d%s%d", &(tab_struct[b].tab_sommets[j][0]),tmp, &(tab_struct[b].tab_sommets[j][1]),tmp, &(tab_struct[b].tab_sommets[j][2])) ; //cout << tab_struct[b].tab_sommets[j][0]<<" "<<tab_struct[b].tab_sommets[j][1]<<" "<<tab_struct[b].tab_sommets[j][2]<< endl ; fgets (passe_ligne, 200, pointeur) ; //saute une ligne dans le fichier où les données ne servent pas fscanf (pointeur, "%s%s%s", tmp3, tmp, tmp); j++ ; } while (strcmp(tmp3, "}")!=0) ; nb_indices[b] = j*3;//calcul le nombre d'indices //cout << nb_indices[b]<<endl ; j=0; } //cout<< "hello1"<<endl ; fclose (pointeur) ; }
void reshape (int w, int h)
{
glViewport (0, 0, w, h) ;
glMatrixMode (GL_PROJECTION) ;
glLoadIdentity () ;
glFrustum(-15.0 , 15.0, -15.0, 15.0, 5.0, 500.0); //perspective conique
glMatrixMode(GL_MODELVIEW); //la matrice active de modelisation/visualisation sera affectée
glLoadIdentity(); //charge la matrice identitégluLookAt (20.0, 0.0, 0.0, 0.0,0.0,0.0, 0.0, 1.0, 0.0) ; //caméra placée sur l’axe des Z et regardant vers l’origine
//pour “voiture” gluLookAt (0.0, 0.0, -50.0, 0.0,0.0,0.0, 0.0, 1.0, 0.0) ;
//pour “geosphere” gluLookAt (20.0, 0.0, 0.0, 0.0,0.0,0.0, 0.0, 1.0, 0.0) ;
}
void display ()
{
glEnableClientState (GL_VERTEX_ARRAY);
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE) ;
glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT ) ;
//glScalef (3.0, 3.0, 3.0) ;
for (lecteur->m=0 ; (lecteur->m)<=(lecteur->a) ; lecteur->m++)
{
glVertexPointer (3, GL_FLOAT, 0, &(lecteur->tab_struct[lecteur->m].tab_vertices[0][0]));
glDrawElements (GL_TRIANGLES, lecteur->nb_indices[lecteur->m],
GL_UNSIGNED_INT,&(lecteur->tab_struct[lecteur->m].tab_sommets[0][0])) ;
}glutSwapBuffers() ;
}
void main (int argc, char** argv)
{
lecteur = new lire_un_ase ;
//cout<<“hello”<<endl ;
glutInit (&argc, argv) ;
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) ;
glutInitWindowSize (640, 480) ;
glutInitWindowPosition (250,250) ;
glutCreateWindow (argv [0]) ;glEnable( GL_DEPTH_TEST ); glutReshapeFunc (reshape) ; glutDisplayFunc (display) ; glutMainLoop () ;
}
[This message has been edited by airseb (edited 04-27-2003).]
[This message has been edited by airseb (edited 04-27-2003).]
[This message has been edited by airseb (edited 04-28-2003).]
[This message has been edited by airseb (edited 04-28-2003).]