Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: my program display nothing !

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

    my program display nothing !

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

  2. #2
    Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    265

    Re: my program display nothing !

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

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

    Re: my program display nothing !

    thanks !
    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 ?

  4. #4
    Junior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    205

    Re: my program display nothing !

    well we dont have this file you are loading. so i dont think anybody is going to get anything but a black screen

  5. #5
    Junior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    205

    Re: my program display nothing !

    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

  6. #6
    Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    265

    Re: my program display nothing !

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

  7. #7
    Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    265

    Re: my program display nothing !

    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

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

    Re: my program display nothing !

    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.

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

    Re: my program display nothing !

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

  10. #10
    Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    265

    Re: my program display nothing !

    It might be your glFrustum, a needed gluPerspective or gluLookAt isn't set in the right coordinates.

    - VC6-OGL

Posting Permissions

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