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
");
#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
");
#endif
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glutPostRedisplay();
break;
case 's' : /* Affichage en mode sommets seuls */
#ifdef DEBUG
fprintf(stderr,"s : Sommet
");
#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
");
#endif
glutReshapeWindow(250,250);
break;
case 'q' : /*la touche 'q' permet de quitter le programme */
#ifdef DEBUG
fprintf(stderr,"q : Quit !
");
#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
");
#endif
glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
glutPostRedisplay();
break;
case GLUT_MIDDLE_BUTTON :
#ifdef DEBUG
fprintf(stderr,"click milieu!
");
#endif
glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
glutPostRedisplay();
break;
case GLUT_RIGHT_BUTTON :
#ifdef DEBUG
fprintf(stderr,"click droit
");
#endif
glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
glutPostRedisplay();
break;
default :
#ifdef DEBUG
fprintf(stderr,"Unknown mouse event !
");
#endif
}
}