PDA

View Full Version : Loosing Keyboard Control



gottijay
07-28-2011, 05:02 PM
hi, i am using opengl and glut...
i created two opengl windows, one to run animation and the other to just do normal stuff like rotate models and stuff

to start up the program the first window displays the models and buttons...a click of the runAnimation button(...buttoncallback8..)...creates the second window....and peforms the animation....exiting this second window takes me back to the first window...

the problem is when i am back to the first window i can no longer use the keyboard functions again

does anyone know what might be causing this problem...please i need your help.






static void TheButtonCallback8()
{



animate=true;
window2=0;
if(window2==0){
loadMast = true;
loadReflector = true;
loadReceiver = true;
loadConnector = true;
loadStand = true;

window2 = glutCreateWindow("animation");
glutDisplayFunc(display2);
glutReshapeFunc(animation_Reshape);
glutIdleFunc(OnIdle1);
glutSpecialFunc (keyboard_s);
glutKeyboardFunc(OnKeyAnimation);


//glutMouseFunc(Mouse);
//glutMotionFunc(Motion);
InitGL();
glutMainLoop();

}else{
glutDestroyWindow(window2);
window2=1;}

printf("Run Animation");
}



void main(int argc, char** argv) {
atexit(OnShutdown);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);

glutInitWindowSize(width, height);
//glutCreateWindow("SATELLITE DISH ASSEMBLY");

window1 = glutCreateWindow("Satellite Assembly");

glutDisplayFunc(OnRender);
glutReshapeFunc(OnReshape);
glutIdleFunc(OnIdle);
glutKeyboardFunc(OnKey);
glutSpecialFunc (keyboard_s);
glutMouseFunc(Mouse);
glutMotionFunc(Motion);
glutPassiveMotionFunc(MousePassiveMotion);
InitGL();

glutMainLoop();
}

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

if (key == 27){

glutDestroyWindow(window2);
animate=false;
loadMast= false;
loadReflector= false;
loadReceiver= false;
loadConnector= false;
loadStand= false;


//exit(0);
}
}



thank you

Alfonse Reinheart
07-28-2011, 07:13 PM
does anyone know what might be causing this problem...

It's probably the fact that your code is sitting in the TheButtonCallback8 function. That's what glutMainLoop does; it will not return until the window has been destroyed.

If you want both windows to work, then don't call glutMainLoop.

gottijay
07-28-2011, 11:53 PM
thanks Alfonse Reinheart..seems i have keyboard control..... did remove remove glutmainloop from the button call back like you asked...but it seems response to the keyboard is extremely slow....i have to wait over 20 seconds if i press x for one model to rotate..


any idea why this might be happening?

thanks for your help