View Full Version : Working with glutMainLoop()

02-12-2007, 11:23 PM
Hello, I am very new to coding with OpenGL and have a question regarding real-time interaction with glutMainLoop in C++.

I have a fully functional code that takes motion from a haptic device (robot) and displays it graphically using OpenGL. What I need to do is taken the positions of the device, send them via UDP to a server and resend them back to the client. The UDP coding isn't a problem but I don't know the nature of how glutMainLoop works and how I can receive positions and transfer them while the program runs in its loop.

Thanks in advance for any help or tips.

02-13-2007, 12:00 AM
In glut, there is only the idle function. It is called whenever there is no other event to be processed. However, you must not block in this function.

It may be better to just make an extra thread for processing motion data.

02-13-2007, 12:11 AM
Originally posted by Overmind:
It may be better to just make an extra thread for processing motion data. Would this just be some code inserted into the source glutMainLoop function itself?

02-13-2007, 06:41 AM
The rendering loop with glutMainLoop() is continuously listening user events and rendering the scene when the system is idle.

You may need global variables to store the current states, such as the position of the device. So, the rendering loop with glutMainLoop and your updating codes (UDP parts) can share the same variables.