The way your code is writen only when a window event, ie re-size, move, etc. will the window be updated.
Say you want the screen to update after a mouse move or keyboard. Use glutPostRedisplay, at the end of that routine.
example:
My_mouse_event(int button, int x, int y)
{
Check mouse position, move if needed.
glutPostRedisplay(); // Redraw screen with new mouse data.
}
For game timming and idle time, I like to use glutTimerEvent( time in ms, func * , int)
example:
Insert before glutMainLoop
glutTimerEvent( 10, My_timer_event, 1)
My_timer_event(int te)
{
update_objects /// code to update your objects
glutPostRedisplay(); // Redraw screen with new object data.
glutTimerEvent( 10, My_timer_event, 1)// timer is a one shoot must be reset after being called. By using a timed event, your application should run about the same speed on any machine.
}
You can use glutIdelFunc but it will not any idea of how fast the updates will be. So on a fast machine vs. a slow machine will get diffrent rates of updates. I prefer the gluttimerevent.
Originally posted by method5:
[b]ok as some of you know… im trying to make an pixel by pixel scrolling rpg engine… i just put the keyboard controls in and for some reason glutDisplayFunc is not updating… i have to minimize the opengl window and maximize again for it too change to reflect the characters position on the screen… why isnt is updating… once you call the mainloop function thing shouldnt it automatically be called every few miliseconds or so…?
my init code…
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutGameModeString(“512x384:32@120”);
glutEnterGameMode();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,512.0,384.0,0.0,0.0,10.0);
glEnable(GL_TEXTURE_2D);
glutSetCursor(GLUT_CURSOR_NONE);
glutDisplayFunc(drawscreen);
glutKeyboardFunc(inputevent);
glutSpecialFunc(sinputevent);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
FocusCamera(0);
load_gl_textures();
glutMainLoop();
so shouldnt the display code keep refreshing?? or am i missing something to get it autorefreshed…[/b]
[This message has been edited by nexusone (edited 03-25-2002).]