PDA

View Full Version : my program displays nothing, can you help me ?



airseb
04-27-2003, 05:20 AM
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", &amp;(temp) ,&amp;(tab_struct[B].tab_vertices[i][0]),
&amp;(tab_struct[B].tab_vertices[i][1]),&amp;(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", &amp;(tab_struct[B].tab_sommets[j][0]),tmp,
&amp;(tab_struct[B].tab_sommets[j][1]),tmp, &amp;(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, &amp;(lecteur->tab_struct[lecteur->m].tab_vertices[0][0]));
glDrawElements (GL_TRIANGLES, lecteur->nb_indices[lecteur->m],
GL_UNSIGNED_INT,&amp;(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 (&amp;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).]

airseb
04-28-2003, 08:07 AM
up !

starman
04-29-2003, 09:20 AM
Check out the "Troubleshooting Transformations" section in chapter 3 of the red book (http://fly.cc.fer.hr/~unreal/theredbook/chapter03.html). Here is part of that section:

<snip>
Make sure you're drawing your objects with a color that's different from the color with which you're clearing the screen. Make sure that whatever states you're using (such as lighting, texturing, alpha blending, logical operations, or antialiasing) are correctly turned on or off, as desired.

Remember that with the projection commands, the near and far coordinates measure distance from the viewpoint and that (by default) you're looking down the negative z axis. Thus, if the near value is 1.0 and the far 3.0, objects must have z coordinates between -1.0 and -3.0 in order to be visible. To ensure that you haven't clipped everything out of your scene, temporarily set the near and far clipping planes to some absurdly inclusive values, such as 0.001 and 1000000.0. This might negatively affect performance for such operations as depth-buffering and fog, but it might uncover inadvertently clipped objects.


Determine where the viewpoint is, in which direction you're looking, and where your objects are. It might help to create a real three-dimensional space - using your hands, for instance - to figure these things out.


Make sure you know where you're rotating about. You might be rotating about some arbitrary location unless you translated back to the origin first. It's OK to rotate about any point unless you're expecting to rotate about the origin.


Check your aim. Use gluLookAt() to aim the viewing volume at your objects. Or draw your objects at or near the origin, and use glTranslate*() as a viewing transformation to move the camera far enough in the z direction only, so that the objects fall within the viewing volume. Once you've managed to make your objects visible, try to incrementally change the viewing volume to achieve the exact result you want, as described below.
</snip>