PDA

View Full Version : my program display nothing !



airseb
12-31-2002, 08:58 AM
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 () ;

}


[This message has been edited by airseb (edited 12-31-2002).]

Stack Overflow
12-31-2002, 09:51 AM
Try enabling Depth_Test and glClear in your Display Function.

Ex: Take these functions and put them in your Display Function:
glClearColor (0.0, 0.0, 0.0, 0.0) ;
glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT ) ;
glEnable( GL_DEPTH_TEST );

Edit:
Change your glutInitDisplayMode Function to this.
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH );

- VC6-OGL

[This message has been edited by VC6-OGL (edited 12-31-2002).]

airseb
12-31-2002, 10:53 AM
thanks ! http://www.opengl.org/discussion_boards/ubb/biggrin.gif
but now i have a black windows without the object that i want to display.

i think that the error come from the values of glFrustum but i'm not sure and i don't know the values which i have to put. can you help me ?

mdog1234
12-31-2002, 11:44 AM
well we dont have this file you are loading. so i dont think anybody is going to get anything but a black screen

mdog1234
12-31-2002, 11:47 AM
when i tried your code i got a clear screen too. glClear and depth testing are fine. what you forgot is a glFlush(); in your display function. Now i get a black screen but i need that file or something to provide anymore help

Stack Overflow
12-31-2002, 12:03 PM
Are you sure you are loading the *.ase file in your program correctly? Have you seen the program work before? What is the program supposed to do or look like?

- VC6-OGL

[This message has been edited by VC6-OGL (edited 12-31-2002).]

Stack Overflow
12-31-2002, 12:08 PM
If you want to enable Double Buffering, do the following,

Change your glutInitDisplayMode to:
· glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );

And at the end of your Display Function, add:
· glFlush();
· glutSwapBuffers();

- VC6-OGL

airseb
12-31-2002, 12:38 PM
Originally posted by VC6-OGL:
Are you sure you are loading the *.ase file in your program correctly? Have you seen the program work before? What is the program supposed to do or look like?

- VC6-OGL

[This message has been edited by VC6-OGL (edited 12-31-2002).]

the program with the ase file work, i have tested it before by displaying the datas about meshes.

airseb
12-31-2002, 12:42 PM
don't you think that there is an error with glFrustum ?i have put the values a little randomly. Or is it glVertexPointer that just allow an array of one dimension instead of two ?

[his message has been edited by airseb (edited 12-31-2002).]

[This message has been edited by airseb (edited 12-31-2002).]

Stack Overflow
12-31-2002, 12:52 PM
It might be your glFrustum, a needed gluPerspective or gluLookAt isn't set in the right coordinates.

- VC6-OGL

airseb
12-31-2002, 01:03 PM
do you a method to find the right values, for glFrustum or gluLookAt ?

Stack Overflow
12-31-2002, 01:07 PM
No, but I tried using gluLookAt and gluPerspective and I had no success.

If you want to load an *.ase file, try: http://www.gametutorials.com/download/OpenGL/ASELoader_OGL.zip

- VC6-OGL

[This message has been edited by VC6-OGL (edited 12-31-2002).]

airseb
01-01-2003, 04:33 AM
the program that read in the ase file work, i have retested it by deleting the // before the cout in the function "lecture".

Mr Pink
01-05-2003, 02:30 PM
I'm far from being an expert in OpenGL but from what I know about black screen maybe I can help you.

When you're using glFrustum you must set the near and the far parameters(the last two params) to value greater than zeros fo it to work.

This as for effect that everything to be visible must either be at -$near or the camera must be at -$near. Otherwise the camera is outside the scene I think.

Try setting the z position of the camera at -5.0f with either gluLookAt or do a glTranslatef(0.0f,0.0f,-5.0f) before drawing the scene.

Maybe I'm completely wrong but I've had many black screen and this was often the cause of it.

Read The OpenGL Programming RedBook for more details about glOrtho and glFrustum you'll see how they differs in rendering the scene on other aspect than perpective. Look at gluPerspective it is often simpler to use than glFrustum and it is offers equivalents renderings.

Mr Pink http://www.opengl.org/discussion_boards/ubb/smile.gif