switching between displays

Hi all,

i am back after many days. need ur help badly.
in my application i 've main page with buttons provided. whenever user selects the particular button with the mouse ,i create subwindow and call some display function.

user can switch between the buttons which provide info abt the various aspects of avionics systems. so when ever he selects any button that particular info is displayed in the subwindow.
i am able to do this all. now what i want is , automatically all the information should come one after the other without selecting any buttons.

that means display functions should be called one after the other with some time gap. tell me how i can do this.

if i’ve to use glutTimerfunc tell me how should i do it??

pls do reply soon

thanks in advance (VC6, nexusone,bob,)

bye bye

myredisplay()
{
clearbuffer
draw info 1
swap buffers/glutredisplay
wait
clearbuffer
draw info 2
swap buffers/glutredisplay

}

Hey,
this is not what i want. i am doing exactly the same. i want to switch between such myredisplays. But not within the myredisplay like u’ve told.

pls if anyone knows it, do reply back soon.

prashant

It sounds like you are using glut. You can change the display function to use another one simply by calling glutDisplayFunc again when you want to switch to a new display function.

Originally posted by Deiussum:
It sounds like you are using glut. You can change the display function to use another one simply by calling glutDisplayFunc again when you want to switch to a new display function.

Yes Decissum , i am using glut and i am able to call other displays whenevr i want to change.whenever i press certain predefined keys my display is changing accordingly.
now i want it to be automatic , that means some timer logic , so that after certain time the display should switch from one to another without touching any key.

pls do help early
bye
prashant

So put the change in your timer function. For glut, take a look at glutTimerFunc.

thanks Deiussum,
if anyone know still better pls let me know.
i actually wanted details on glutTimerFunc as to How it can be called??
what are the parameters and some nice example.

Why not just go to your favorite search engine and search for glutTimerFunc? I went to Google and got 1730 hits, and some of them have good examples.

Like this one:
http://ironbark.bendigo.latrobe.edu.au/~fran/int32gp/wk04/lctr08.html

It’s used just like any other glut callback

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

}
}

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

Hi prashantgp,

I am just posting so you know I’m here. I will look into your problem and see if I can give you an answer soon.

  • VC6-OGL

Hello prashantgp,

If you don’t mind, I might be able to help you if I can view your full source code. If you don’t wish to give away your source code, I will still try to fix the problem, but if you do want me to see your source and if it is to large to display on this forum, you can email me the file at vc6ogl@bluedev.net

  • VC6-OGL

[This message has been edited by VC6-OGL (edited 02-11-2003).]

Hey, quite simple. Create a global variable such as

BOOL switching = TRUE;

void keyboard (unsigned char key, int x, int y)
{

switch (key)
{
case ‘a’:
case ‘A’:
glutSetWindow (cw);
glutDisplayFunc (cdisplay);
glutSetWindow (sw);
glutShowWindow ();

//Add this to each keyboard character you want to stop the timer switch
switching = FALSE;

  break;

case ‘h’:
case ‘H’:

//Add some code to start the switching back up if you want!
case ???:
switching = TRUE;
glutTimerFunc(5000,Timer,1);//or instead of 1 if you know which number you were on go to next display number
}

void Timer ( int id)
{

if (switching)
{
switch (id)
{
case :

case:

}
}
else
return;

}

Or you could add the statements in your Timer function where you check for keyboard
if(kbhit())
switching = FALSE;
else
glutTimerFunc(5000,Timer,2);
but you should probably check it before switching.

[This message has been edited by shinpaughp (edited 02-11-2003).]

Hey Shinpaughp,
i tried doing samething , instead of BOOL value what i did was

if (!kbhit())
{
{ switch (id) { case : … case: … } } else return;

now i’ll use BOOL value and see if it works.

thanks for the reply.
bye bye

There are many ways you could do it. I did edit my previous post as to another possibility, but I’m sure you probably already have it working.

[This message has been edited by shinpaughp (edited 02-11-2003).]

Hello prashantgp,

I have looked at your code, and I wanted to say that I think I found the problem. The problem is that, you try to initialize your timer in your main function. To view my updated change, please view the “main” function below:

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);

glutMainLoop ();
return 0;
}

I hope this solves your problem, and if not, please let me know.

  • VC6-OGL

Originally posted by shinpaughp:
[b]There are many ways you could do it. I did edit my previous post as to another possibility, but I’m sure you probably already have it working.

[This message has been edited by shinpaughp (edited 02-11-2003).][/b]

HI Shinpaughp,
thanks for the help , i got it working already.if u could post ur anther edit u were talking about , i’ll just have a look on that.

Hi VC6-OGL , thanks a lot for the help.
but where i should call timer function in ur updated code.

bye bye
prashant

Hello prashantgp,

I found out that it doesn’t need the timer function to work, becuase when you have the timer function, it updates through out all of you scenes every five seconds, so you do not need the timer function, and then everything should run smoothly. Please try your program without the timer in you main function, and tell me if it stops cycling through all of your scenes.

  • VC6-OGL

[This message has been edited by VC6-OGL (edited 02-12-2003).]

[QUOTE]Originally posted by VC6-OGL:
[b]Hello prashantgp,

I found out that it doesn’t need the timer function to work, becuase when you have the timer function, it updates through out all of you scenes every five seconds, so you do not need the timer function, and then everything should run smoothly. Please try your program without the timer in you main function, and tell me if it stops cycling through all of your scenes.

  • VC6-OGL

Hi - VC6-OGL,
when i tried to comment timer function in my Main , it didn’t work.
i think there should be a call to that function then only it will work.
i am just intrested to know , how my display looks on ur screen.
if u had run it , why dont u send me the snapshots.
and any suggestons are welcome.

thanks
bye bye

Hello prashant,

I have just sent you the re-edited code of your program.

  • VC6-OGL