• 13
• 18
• 19
• 27
• 10

# Display a picture with openGL

This topic is 3687 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everybody I have some probles with OpenGL !! The first one: I'd like to display, in my program, an image but then, I want that the program continu to run. I use this code (test is the stucture where there is all the info for the image (height, width, array of piixels ...): Main: /************************************* Initialization OpenGL ***************************************/ /* Initialize GLUT state - glut will take any command line arguments that pertain to it or X Windows */ glutInit(&argc, argv); /* Select type of Display mode: Single buffer, RGB color*/ glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); /***************************************************************************************************/ Load the image /******************* Display the image thanks to OpenGL *************************/ glutInitWindowSize(test.Largeur(), test.Hauteur()); /* the window starts at the upper left corner of the screen */ glutInitWindowPosition(0,0); /* Open a window */ window1 = glutCreateWindow(test.GetNom()); /* Initialize our window. */ InitGL(); /* Register the function to do all our OpenGL drawing. */ glutDisplayFunc(&DrawScene); /* Start Event Processing Engine */ glutMainLoop(); /***************************************************************************/ drawscene function: /* The main drawing function. */ void DrawScene(){ // Clear The Screen glClear(GL_COLOR_BUFFER_BIT); glDrawPixels( test.Hauteur(), test.Largeur(), GL_LUMINANCE, GL_UNSIGNED_BYTE, test.GetImage() ); /* don't wait! start processing buffered OpenGL routines */ glFlush (); } My problem is that the program stop when it executes glutMainLoop() instruction (Actually it doesn't stop but I can't do anything after, I can only quit). I think it's a norma behaviour, But if i put this instruction at the end, the image is displayed only at the end. And I want to display my image in the middle of the execution. Actually I have more than one picture to display, so the first one will be displayed, then the program modify the picture and then redisplay it in a new window. But with this code, the program display the first picture and then do nothing else. Do you know a way to do this ? I think it should exist a function to put the image in background or something like this ? My second problem is the pîcture displayed Here it is: http://osiris.ubishops.ca/~achollet/Affichage/Image_Deforme.JPG As you can see there is a problem. The original picture is Lena.pgm, in P2. I think i have a problem with this line: glDrawPixels( test.Hauteur(), test.Largeur(), GL_LUMINANCE, GL_UNSIGNED_BYTE, test.GetImage() ); Do you know how i can solve this ? Ths matrix of the picture is stored in a array of byte (byte*) thank you very much for your help !! [Edited by - nonolerobot77 on February 13, 2008 10:26:31 AM]

##### Share on other sites
Dans cette forum, on parle l'Anglais.

##### Share on other sites
english is the recognized language on the net......

##### Share on other sites
Oups I'm sorry !!
I correct this !!!!!!!!

##### Share on other sites
Hi again,

I continu to work on my program.
Nobody have a solution for my first problem ?? I think it's becausei use 'glutMainLoop', so the program enters in an infinite loop, so i can't use it after !! Does someone know how to aoid this ??

And for my other problem, I succeed to display a picture in P5 but not in P2 (I put an exempla with a P2 in my first post) !!
I use the same way to store the pixels !!
Does somebody know where it comes from ??

Thank you very much

##### Share on other sites
Quote:
 Original post by nonolerobot77Hi again,I continu to work on my program.Nobody have a solution for my first problem ?? I think it's becausei use 'glutMainLoop', so the program enters in an infinite loop, so i can't use it after !! Does someone know how to aoid this ??

The answer to this question is fairly simple. You can't exit the glutMainLoop function; however, you don't need to.

You already have declared a Display Function.

glutDisplayFunc(&DrawScene);

That function will get called whenever glut needs to redraw the screen. All you need is a function that is called repeatedly.

This is the idle function.

glutIdleFunc(IdleFunction); // Make an Idle Function:...GLvoid IdleFunction(GLvoid){ // do your stuff here glutPostRedisplay();   // Tell glut a call to display function is needed}

In other words, the Idle Function is essentially your section of the "game main loop" which is called by glutMainLoop among other OpenGL necessary things.

##### Share on other sites
Thank you very much !!!

And for the problem with the pgm file in P2 ??
I try to solve it but i can't i don't know whu it does this !!

Help plzzz