Originally posted by Deiussum:
[b]It’s used just like any other glut callback
[quote]
void MyTimerFunc(int value);
void main()
{
// Usual stuff
// 1000 is the time in milliseconds
// 0 is the value that will be passed to the value param
glutTimerFunc(1000, MyTimerFunc, 0);
glutMainLoop();
}
void MyTimerFunc(int value)
{
if (value == 0) // passed in in main
{
glutDisplayFunc(Display0);
// Change to a new display function in 2 seconds
glutTimerFunc(2000, MyTimerFunc, 1);
}
else if (value == 1)
{
glutDisplayFunc(Display1);
//etc. Stop calling glutTimerFunc when no longer need the timer
}
}
[/b][/QUOTE]
Hi Deiusum,
thanks for this i am using it in similar fashion.
the problem is i want my program to keep on switching displays until nobody touches the keyboard.
once a predefined key is pressed then it should not switch between displays.
u can have a look at my code.
void
keyboard (unsigned char key, int x, int y)
{
switch (key)
{
case 'a':
case 'A':
glutSetWindow (cw);
glutDisplayFunc (cdisplay);
glutSetWindow (sw);
glutShowWindow ();
break;
case 'h':
case 'H':
glutSetWindow (sw);
glutHideWindow ();
glutSetWindow (cw);
glutDisplayFunc (hsidisplay);
break;
case 'e':
case 'E':
glutSetWindow (sw);
glutHideWindow ();
glutSetWindow (cw);
glutDisplayFunc (enginedisplay);
break;
case 'n':
case 'N':
glutSetWindow (cw);
glutDisplayFunc (navigdisplay);
glutSetWindow (sw);
glutShowWindow ();
break;
case 'f':
case 'F':
glutSetWindow (sw);
glutHideWindow ();
glutSetWindow (cw);
glutDisplayFunc (Fueldisplay);
break;
case 'd':
case 'D':
glutSetWindow (sw);
glutHideWindow ();
glutSetWindow (cw);
glutDisplayFunc (Electricaldisplay);
break;
case 27:
exit (0);
break;
default:
break;
}
glutPostRedisplay ();
}
void Timer ( int id)
{
switch (id) {
case 1 :
glutSetWindow (sw);
glutHideWindow ();
glutSetWindow (cw);
glutDisplayFunc(hsidisplay);
if(kbhit())
{printf("
i got thekey ");
glutTimerFunc(5000,Timer,0);}
else
glutTimerFunc(5000,Timer,2);
break;
case 2 :
glutSetWindow (sw);
glutShowWindow();
glutSetWindow (cw);
glutDisplayFunc (navigdisplay);
if(kbhit())
glutTimerFunc(5000,Timer,0);
else
glutTimerFunc(5000,Timer,3);
break;
case 3 :
glutSetWindow(sw);
glutHideWindow ();
glutSetWindow (cw);
glutDisplayFunc (Fueldisplay);
if(kbhit())
glutTimerFunc(5000,Timer,0);
else
glutTimerFunc(5000,Timer,4);
break;
case 4 :
glutSetWindow(sw);
glutHideWindow ();
glutSetWindow (cw);
glutDisplayFunc (enginedisplay);
if(kbhit())
glutTimerFunc(5000,Timer,0);
else
glutTimerFunc(5000,Timer,5);
break;
case 5 :
glutSetWindow(sw);
glutHideWindow ();
glutSetWindow (cw);
glutDisplayFunc (Electricaldisplay);
if(kbhit())
glutTimerFunc(5000,Timer,0);
else
glutTimerFunc(5000,Timer,6);
break;
case 6 :
glutSetWindow(sw);
glutShowWindow ();
glutSetWindow (cw);
glutDisplayFunc (cdisplay);
if(kbhit())
glutTimerFunc(5000,Timer,0);
else
glutTimerFunc(5000,Timer,1);
break;
case 0 : break;
default : break;
}
}
int
main (int argc, char **argv)
{
glutInit (&argc, argv);
glutInitWindowSize (800, 725);
glutInitWindowPosition (200, 80);
pw = glutCreateWindow (“Multi Function Display”);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
init ();
glutDisplayFunc (display);
glutKeyboardFunc (keyboard);
glutReshapeFunc (reshape);
glutMouseFunc (mouse);
// Default page - Attitude direction indicator
cw = glutCreateSubWindow (pw, 120, 110, 550, 510);
cinit ();
glutDisplayFunc (cdisplay);
glutReshapeFunc (reshape);
glutKeyboardFunc (keyboard);
glutMouseFunc (mouse);
glutIdleFunc (idle);
sw = glutCreateSubWindow (cw, 180, 40, 200, 60);
sinit ();
glutReshapeFunc (sreshape);
glutDisplayFunc (sdisplay);
glutTimerFunc(5000,Timer,1);
glutMainLoop ();
return 0;
}
But whenever there is key pressed instead of coming out from Timerfunc , it shifts to the particular display of the key pressed for a moment and again comes back to Timer func where in it keeps on switching between the cases(i mean all displays).
what exactly i want is ,
whenever the program is run , until any key is pressed it has to be in timer function switching between the displays.
once any key is pressed ( suppose A or H or E) then it should go to that particular display and stay there.
hope the problem is clear.
hey Nexusone , VC6OGL , Bob where are u people man?? help me out
thanks in advance