I have a 3d world created and there is an object, say a ball, I want to move by pressing a button on the keyboard. The problem I keep running into and I can’t seem to understand is, when I press ‘r’ to draw the object at a new position it will only be displayed after I reshape my window. The same applies to my camera movement. When I press the right arrow to rotate around the origin i have to resize my display window for it to take effect. I’m not sure if I’m calling proper functions in the correct place or if my setup is even correct, but I wonder if this is also why my textures disappear when I resize my window. Here’s my code: http://sourcepost.sytes.net/sourcepost/sourceview.aspx?source_id=2720
Resizing the window forces a redraw. If you are using glut, you have to do whatever the glut redraw function is. If you are using windows without glut, you need to call InvalidateRect(your window’s HWND, NULL, FALSE). If you are using a mac or unix or some other machine, you’ll have to do the equivalent thing for that specific hardware.
so i would need to call glutDisplayFunc( display ); after each instance I want to move an object ?
doesn’t glMainLoop( ); keep looping so the function called inside main( ) will continuously be called upon? I have my glutDisplayFunc( display ); inside main( ) and it should keep redrawing? When I press ‘r’ the coordinates are changed inside display( ), so the ojbect should be automatically redrawn. I even called glutDisplayFun( ) as that should register the redraw function…
to force a screen refresh in glut do
glutPostRedisplay() (or something like that check the help)
also u can make your glut idle callback call the display function