Screen display problems

Hello,

I’am just starting openGL coding, and I already
encounter a problem (first of lot I hope :slight_smile: ).
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
}
}

where is the viewport seting? You need to set the viewport…

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.

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

  • VC6-OGL

What exacltly is not working?

  • VC6-OGL

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

  • VC6-OGL[/b]

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

Try this:

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

  • VC6-OGL

It does not seem to work !
I don’t understand …

Be sure to read a full lesson before try to implement it. You must specify the viewport each time the window changes size.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.