PDA

View Full Version : Screen display problems



12-30-2002, 08:52 AM
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
}
}

OldMan
01-02-2003, 01:45 PM
where is the viewport seting? You need to set the viewport..

01-03-2003, 11:17 AM
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.

Stack Overflow
01-03-2003, 11:20 AM
It doesn't look like you have a Reshape Function.

- VC6-OGL

Stack Overflow
01-03-2003, 11:29 AM
What exacltly is not working?

- VC6-OGL

01-03-2003, 01:18 PM
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 ???

Stack Overflow
01-03-2003, 01:58 PM
Try this:

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

- VC6-OGL

01-06-2003, 09:41 AM
It does not seem to work !
I don't understand ...

OldMan
01-10-2003, 05:12 AM
Be sure to read a full lesson before try to implement it. You must specify the viewport each time the window changes size.