Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: my program display a black window !

  1. #1
    Member Regular Contributor
    Join Date
    Mar 2002
    Location
    France
    Posts
    363

    my program display a black window !

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

  2. #2
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: my program display a black window !

    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.

  3. #3
    Member Regular Contributor
    Join Date
    Mar 2002
    Location
    France
    Posts
    363

    Re: my program display a black window !

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

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Posts
    748

    Re: my program display a black window !

    What the hell is that: ?

    Code :
    for (j = 0 ; j <nb_vertices; j++)
    {
    glBegin (GL_TRIANGLES);
    glArrayElement (j);
    glEnd () ;
    }
    A triangle is made of 3 vertices, not one!

    Y.

  5. #5
    Member Regular Contributor
    Join Date
    Mar 2002
    Location
    France
    Posts
    363

    Re: my program display a black window !

    Originally posted by Ysaneya:
    What the hell is that: ?

    Code :
    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 ?

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Posts
    748

    Re: my program display a black window !

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •