PDA

View Full Version : Problem with glutMainLoop()



Mukund
10-22-2010, 10:03 AM
Hello.

Well, im trying to use a wiiremote in my application. im using the wiiuse library for this.

The problem is this:


int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(800,600);

glutInitWindowPosition(100,150);
glutCreateWindow("FIRST ONE");

glutDisplayFunc(display);
glutMainLoop();

while (1) {
/* The wiimote events are handled here */
}
}

Now, the problem is, if glutMainLoop() is befor the event handler infinite loop of the wii, i cant get till the infinite loop.
im not sure how i can handle both these events.

Any suggestions?

Thanks.

carsten neumann
10-22-2010, 11:11 AM
handle wiimote events in the display callback, and use glutIdleFunc() to set a function that just calls glutPostRedisplay().
That ensures that you continually render new images and each time your render your first update your application data based on the input events.
Of course don't use an infinite loop to process events, only handle those that have arrived since the last frame.

Mukund
10-22-2010, 01:12 PM
Thanks for the reply carsten neumann.

The method suggested by you was very good. But what if the application becomes huge and if i don't want the display callback being called all the time, what in that case, can i somehow do away with calling display over and over again?

Any other way to handle the wiimote events?

carsten neumann
10-22-2010, 02:50 PM
Does it make sense (or: is it important) for your application to handle input events without rendering a new image?
After processing input you could check the amount of time that has expired since you last rendered an image and if it is less than 1/60 of a second you just return from the display callback without drawing. Perhaps even add a way to force rendering independent of elapsed time (for example when the window size has changed)

For large applications it is probably better to just drop GLUT and use a different framework. I think of GLUT as being most useful for small, demo like programs or quick prototypes - it gets you started quickly, but it has a somewhat simple application model.

Mukund
10-23-2010, 02:21 AM
For large applications it is probably better to just drop GLUT and use a different framework.

Any suggestions for another framework?

Kamal Reddy
01-29-2011, 10:37 AM
hi mukund
I couldn't understand the modification,Can you please post the modified code?
please reply asap.





Hello.

Well, im trying to use a wiiremote in my application. im using the wiiuse library for this.

The problem is this:


int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(800,600);

glutInitWindowPosition(100,150);
glutCreateWindow("FIRST ONE");

glutDisplayFunc(display);
glutMainLoop();

while (1) {
/* The wiimote events are handled here */
}
}

Now, the problem is, if glutMainLoop() is befor the event handler infinite loop of the wii, i cant get till the infinite loop.
im not sure how i can handle both these events.

Any suggestions?

Thanks.

ZbuffeR
01-29-2011, 10:58 AM
Use GLFW instead of Glut. GLFW is not event driven, and you keep control of the events handling loop.