View Full Version : where to use glutpostredisplay?
05-13-2011, 12:12 AM
i have got some opengl programs written in vc++.some of them use glutpostredisplay().it is used in different functions.in some programs its used in the init() function and in some it is used in reshape function.i am getting confused on where to place this function.
05-13-2011, 12:16 AM
Normally, the display function is only called when the window needs repainting (if another window covers it and is removed). If you call glutPostRedisplay, GLUT will call the display function at GLUT's earliest convenience.
So, where to place it depends on what you want to do. There's no reason to put it in "init". It's a good idea to put it in "reshape". If the window was made bigger, then the display function will be called anyway. However, if the window was made smaller, the display function won't be called, since the new area of the window is smaller than the old one.
If you want things to animate, then you will either need to call glutPostRedisplay in your display function or use a timer and call it based on that timer.
05-13-2011, 12:49 AM
so glutpostredisplay is used when the window size reduces.
in some programs i see that reshapefunction is used whereas in some it is not used.what might be the reason?im studyin opengl from edward angel book.its sort of confusing.
there is a program in it to rotate a cube.and the function is:
colorcube(); //to draw the cube.
in the above program,three rotate functions are specified before the cube is drawn im not understanding why and im almost nuts. then the loadidentity function seems to be used randomly in programs.im not understanding when and where its to be used sos
05-13-2011, 02:01 AM
in some programs i see that reshapefunction is used whereas in some it is not used.what might be the reason?
Anything. Nothing. Maybe someone put it there to debug something and never removed it. Focus on understanding what the code actually does.
BTW, is the shift key on your keyboard broken? "glrotatef" is not a valid function; "glRotatef" is.
im studyin opengl from edward angel book.
Which book? I checked Amazon, and there's a 2011 edition of his Interactive Computer Graphics book that's ostensibly shader-based. But since that is supposed to be "shader-based", I wouldn't expect to see any glRotatef calls.
in the above program,three rotate functions are specified before the cube is drawn im not understanding why and im almost nuts.
To be honest, I don't know either. That code doesn't look like it's doing anything even remotely sensible. I would have at least expected to see theta, theta, and theta for the three angles; that would at least be legitimate Euler angles. It may just be a typo.
then the loadidentity function seems to be used randomly in programs.
Does the book not explain what glLoadIdentity does?
05-13-2011, 05:06 AM
the book im studying is opengl:a top down approach.
its called top down because,first we learn to write programs and then we learn the fundamentals behind the program.
it says that the glLoadIdentity() is used to load the current matrix with an identity matrix.
but what im not getting is when we need to load the identity matrix into the current matrix.
also it seems instead of glutPostRedisplay() display can be used and the programs fine.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.