PDA

View Full Version : my program display a black window !



airseb
12-31-2002, 02:46 PM
i have ever tried in the beginner forum but nobody manage to found the error.
i have a black window when i execute the program which read in a .ase file.
this program is supposed to display the object which is in the file.
i have tested the function "lecture" (which read in the .ase file) and it works.

this is the code :

#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <GL/glut.h>

#define nb_vertices 697

char tmp [100] ;
int temp [nb_vertices] ;
char chaine [100] ;
float tab_vertices [nb_vertices][3] ;
int i, j ;
char nom_fichier[] = "cool.ase" ;



void lecture ()
{

FILE *cool ; //pointeur sur le fichier cool

if ((cool = fopen(nom_fichier, "r")) == NULL)
return ;

strcpy (chaine , "*MESH_VERTEX") ;

do
{

fscanf(cool, "%s", tmp) ;
}
while (strcmp (chaine, tmp) != 0) ;


for (i = 0; i < nb_vertices ;i++)//rempli le tableau avec des coordonnées de vertices
{
fscanf (cool, "%d%f%f%f%s", &(temp[0]) , &(tab_vertices[i][0]), &(tab_vertices[i][1]), &(tab_vertices[i][2]), tmp) ;
//cout << tab_vertices[i][0]<<" "<< tab_vertices[i][1]<<" "<< tab_vertices[i][2]<<endl ;

}

fclose (cool) ;


}
void reshape (int w, int h)
{
glViewport (0, 0, w, h) ;
glMatrixMode (GL_PROJECTION) ;
glLoadIdentity () ;
glFrustum(-100.0 , 100.0, -100.0, 100.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 (0.0, 0.0, 100.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
}
void display ()
{
glEnableClientState (GL_VERTEX_ARRAY);
glVertexPointer (3, GL_FLOAT, 0, &tab_vertices[0][0]);

glPolygonMode (GL_FRONT_AND_BACK, GL_LINE) ;

glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT ) ;

for (j = 0 ; j <nb_vertices; j++)
{
glBegin (GL_TRIANGLES);
glArrayElement (j);
glEnd () ;
}

glutSwapBuffers() ;

}

void main (int argc, char** argv)

{

lecture () ;
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 12-31-2002).]

dorbie
01-01-2003, 02:26 AM
Looks OK, perhaps the issue is the data in the file? Have you looked at the bounds of that data to see if your viewing is set appropriately?

Maybe you should start with a simple triangle to see if that works. Or a glut teapot.

I may have missed something of course. Explicit verts may be worth trying here between the begin end calls before getting array elements to work.

You may want to make sure backface culling is off during initial testing too.

airseb
01-01-2003, 05:08 AM
i have change the values of glFrustum and gluLookAt and it don't work.
the program which read in the ase file work when i delete the '//' before the cout.
please help me i don't manage to find the errors :-(

#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <GL/glut.h>

#define nb_vertices 697

char tmp [100] ;
int temp [nb_vertices] ;
char chaine [100] ;
float tab_vertices [nb_vertices][3] ;
int i, j ;
char nom_fichier[] = "cool.ase" ;



void lecture ()
{

FILE *cool ; //pointeur sur le fichier cool

if ((cool = fopen(nom_fichier, "r")) == NULL)
{
cout<<"fichier non ouvert" ;
return ;
}

strcpy (chaine , "*MESH_VERTEX") ;

do
{

fscanf(cool, "%s", tmp) ;
}
while (strcmp (chaine, tmp) != 0) ;


for (i = 0; i < nb_vertices ;i++)//rempli le tableau avec des coordonnées de vertices
{
fscanf (cool, "%d%f%f%f%s", &(temp[0]) , &(tab_vertices[i][0]), &(tab_vertices[i][1]), &(tab_vertices[i][2]), tmp) ;
//cout << tab_vertices[i][0]<<" "<< tab_vertices[i][1]<<" "<< tab_vertices[i][2]<<endl ;

}

fclose (cool) ;


}
void reshape (int w, int h)
{
glViewport (0, 0, w, h) ;
glMatrixMode (GL_PROJECTION) ;
glLoadIdentity () ;
glFrustum(-200.0 , 200.0, -200.0, 200.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 (0.0, 0.0, 200.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
}
void display ()
{

glEnableClientState (GL_VERTEX_ARRAY);
glVertexPointer (3, GL_FLOAT, 0, &tab_vertices[0][0]);

glPolygonMode (GL_FRONT_AND_BACK, GL_LINE) ;

glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT ) ;

for (j = 0 ; j <nb_vertices; j++)
{
glBegin (GL_TRIANGLES);
glArrayElement (j);
glEnd () ;
}
glFlush () ;

glutSwapBuffers() ;

}

void main (int argc, char** argv)

{

lecture () ;
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 01-01-2003).]

Ysaneya
01-01-2003, 06:06 AM
What the hell is that: ?




for (j = 0 ; j <nb_vertices; j++)
{
glBegin (GL_TRIANGLES);
glArrayElement (j);
glEnd () ;
}


A triangle is made of 3 vertices, not one!

Y.

airseb
01-01-2003, 06:50 AM
Originally posted by Ysaneya:
What the hell is that: ?




for (j = 0 ; j <nb_vertices; j++)
{
glBegin (GL_TRIANGLES);
glArrayElement (j);
glEnd () ;
}


A triangle is made of 3 vertices, not one!

Y.

i don't understand, can you explain more please ?

Ysaneya
01-01-2003, 07:03 AM
glArrayElement specifies a single vertex through its index. You need three to define a triangle.

In other words, you need a multiple of 3 glArrayElement calls inside your glBegin/glEnd pair.

Y.