Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Problem with glutMainLoop()

  1. #1
    Junior Member Regular Contributor
    Join Date
    Mar 2010
    Posts
    209

    Problem with glutMainLoop()

    Hello.

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

    The problem is this:

    Code :
    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.

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2010
    Posts
    493

    Re: Problem with glutMainLoop()

    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.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Mar 2010
    Posts
    209

    Re: Problem with glutMainLoop()

    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?

  4. #4
    Member Regular Contributor
    Join Date
    Apr 2010
    Posts
    493

    Re: Problem with glutMainLoop()

    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.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Mar 2010
    Posts
    209

    Re: Problem with glutMainLoop()

    Quote Originally Posted by carsten neumann
    For large applications it is probably better to just drop GLUT and use a different framework.
    Any suggestions for another framework?

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    1

    Re: Problem with glutMainLoop()

    hi mukund
    I couldn't understand the modification,Can you please post the modified code?
    please reply asap.




    Quote Originally Posted by Mukund
    Hello.

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

    The problem is this:

    Code :
    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.

  7. #7
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Problem with glutMainLoop()

    Use GLFW instead of Glut. GLFW is not event driven, and you keep control of the events handling loop.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •