Skip to main content
gamedev.net
🔒 Locked

my program display nothing !

Started by airseb Dec 31, 2002 at 12:16 PM 2 replies 450+ views
Original Post
airseb
airseb
a window appears but there is nothing in, even not a black color ! can you help me please ! 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(-1.0 , 1.0, -1.0, 1.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, 50.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, GL_LINE) ;

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

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]) ;

glClearColor (0.0, 0.0, 0.0, 0.0) ;
glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT ) ;
glEnable( GL_DEPTH_TEST );

glutReshapeFunc (reshape) ;
glutDisplayFunc (display) ;
glutMainLoop () ;

}
    
[edited by - airseb on December 31, 2002 1:21:28 PM]
Brian Jones
Brian Jones
Heh. You need to glClear, and glFlush your buffers.

I don''t have a signature
I don't have a signature
airseb
airseb
i do it but it still don't work :-(
please help me !


    

#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 () ;

}


[edited by - airseb on January 1, 2003 9:21:38 AM]
Brian Jones
Brian Jones
For the black color, you need to set it to a black color with glClearColor(). Also, I don''t believe you call glArrayElements between a glBegin and glEnd pair.

I don''t have a signature
I don't have a signature

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.