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 9 of 9

Thread: Screen display problems

  1. #1
    Guest

    Screen display problems

    Hello,

    I'am just starting openGL coding, and I already
    encounter a problem (first of lot I hope :-) ).
    In the attached program, when compiling with :

    gcc P1.c -o p1 -L/usr/X11R6/lib -lGL -lGLU -lglut -lX11 -lXmu -lXi -lm -lXext -lpthread -DDEBUG

    At execution time, a window is opened but do not print anything in it. It is just the background screen which is displayed. When I iconify it and after re-open it, it takes again the backgroung screen picture.

    Somebody can help me, please ?

    Thanks.

    Sources :

    /*
    Compile line :
    gcc P1.c -o p1 -L/usr/X11R6/lib -lGL -lGLU -lglut -lX11 -lXmu -lXi -lm -lpthread -DDEBUG
    */

    /***********************
    * INCLUDES
    ***********************/

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


    /***********************
    * DEFINES
    ***********************/

    /* Error codes */

    #define X_error 20


    /***********************
    * PROTOTYPES
    ***********************/

    void affichage(void);
    void clavier(unsigned char touche, int x, int y);
    void mouse(int button, int state, int x, int y);

    /***********************
    * BODIES
    ***********************/

    int main(int argc,char **argv){

    /* initialisation de glut et creation
    de la fenetre */
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB);
    glutInitWindowPosition(200,200);
    glutInitWindowSize(250,250);
    glutCreateWindow((char *)basename(argv[0]));

    /* Initialisation d'OpenGL */
    glClearColor(0.0,0.0,0.0,0.0);
    glColor3f(1.0,1.0,1.0);
    glPointSize(2.0);

    /* enregistrement des fonctions de rappel */
    glutDisplayFunc(affichage);
    glutKeyboardFunc(clavier);
    glutMouseFunc(mouse);

    /* Entree dans la boucle principale glut */
    glutMainLoop();
    return 0;
    }

    void affichage(){

    /* effacement de l'image avec la couleur de fond */
    glClear(GL_COLOR_BUFFER_BIT);

    /* Dessin du polygone */
    glBegin(GL_POLYGON);
    glColor3f(1.0,0.0,0.0);
    glVertex2f(-0.5,-0.5);
    glColor3f(0.0,1.0,0.0);
    glVertex2f(0.5,-0.5);
    glColor3f(0.0,0.0,1.0);
    glVertex2f(0.5,0.5);
    glColor3f(1.0,1.0,1.0);
    glVertex2f(-0.5,0.5);
    glEnd();

    /* on force l'affichage du resultat */
    glFlush();
    }

    void clavier(unsigned char touche,int x,int y){

    int window_number;

    switch (touche)
    {
    case 'p': /* affichage du carre plein */
    #ifdef DEBUG
    fprintf(stderr,"p : Full square\n");
    #endif
    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    glutPostRedisplay();
    break;

    case 'f': /* affichage en mode fil de fer */
    #ifdef DEBUG
    fprintf(stderr,"f : File de fer\n");
    #endif
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    glutPostRedisplay();
    break;

    case 's' : /* Affichage en mode sommets seuls */
    #ifdef DEBUG
    fprintf(stderr,"s : Sommet\n");
    #endif
    glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
    glutPostRedisplay();
    break;

    case 'A' : /*la touche 'A' pour full screen mode */
    #ifdef DEBUG
    fprintf(stderr,"A : Full screen !");
    #endif
    glutFullScreen();
    break;

    case 'a' : /*la touche 'a' pour enlever le full screen */
    #ifdef DEBUG
    fprintf(stderr,"a : screen normal size\n");
    #endif
    glutReshapeWindow(250,250);
    break;

    case 'q' : /*la touche 'q' permet de quitter le programme */
    #ifdef DEBUG
    fprintf(stderr,"q : Quit !\n");
    #endif
    exit(0);
    }
    }


    void mouse(int button, int state, int x, int y){

    switch(button){

    case GLUT_LEFT_BUTTON :
    #ifdef DEBUG
    fprintf(stderr,"click gauche\n");
    #endif
    glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
    glutPostRedisplay();
    break;

    case GLUT_MIDDLE_BUTTON :
    #ifdef DEBUG
    fprintf(stderr,"click milieu!\n");
    #endif
    glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
    glutPostRedisplay();
    break;

    case GLUT_RIGHT_BUTTON :
    #ifdef DEBUG
    fprintf(stderr,"click droit\n");
    #endif
    glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
    glutPostRedisplay();
    break;

    default :
    #ifdef DEBUG
    fprintf(stderr,"Unknown mouse event !\n");
    #endif
    }
    }

  2. #2
    Junior Member Regular Contributor
    Join Date
    Dec 2001
    Location
    Fpolis, SC, BRAZIL
    Posts
    155

    Re: Screen display problems

    where is the viewport seting? You need to set the viewport..
    If brute force doesn`t solve your problem,... you aren`t using enought!!

  3. #3
    Guest

    Re: Screen display problems

    Originally posted by OldMan:
    where is the viewport seting? You need to set the viewport..
    What is the viewport ?

    I never read anything about that in my tutorial

    Thanks for your reply.

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

    Re: Screen display problems

    It doesn't look like you have a Reshape Function.

    - VC6-OGL

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

    Re: Screen display problems

    What exacltly is not working?

    - VC6-OGL

  6. #6
    Guest

    Re: Screen display problems

    Originally posted by VC6-OGL:
    What exacltly is not working?

    - VC6-OGL
    Ok, my source code compile without any warning.
    Then I execute the generated binary, it opens
    a window which is transparent : I mean the background in the window is not black or white (I do not remember how I initialize it) but it is the background behind the window ...
    Then if I move the window, the background still remains, and if I reduce the window and then I resize it, it tooks the new screen background in its own background.

    I am not sure to be clear ???

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

    Re: Screen display problems

    Try this:

    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

    - VC6-OGL

  8. #8
    Guest

    Re: Screen display problems

    It does not seem to work !
    I don't understand ...

  9. #9
    Junior Member Regular Contributor
    Join Date
    Dec 2001
    Location
    Fpolis, SC, BRAZIL
    Posts
    155

    Re: Screen display problems

    Be sure to read a full lesson before try to implement it. You must specify the viewport each time the window changes size.
    If brute force doesn`t solve your problem,... you aren`t using enought!!

Posting Permissions

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