-1

Such that program should run behind and when user wants to see the display of the current state window should popup. And again window should be in updated state on the next time user wants the display.

Because of glutMainLoop() code is stuck at 1st iteration after display. When its removed code works fine but no window is created for display.

solomyhansolo
  • 107
  • 2
  • 9

2 Answers2

1

OpenGL does not deal in windows. And glutMainLoop is not part of OpenGL but GLUT which is an 3rd party library that's not affiliated with OpenGL (it's for writing applications that use OpenGL, but neither is GLUT part of the OpenGL specification, nor is it maintained or specified by Khronos).


Because of glutMainLoop() code is stuck at 1st iteration after display.

glutMainLoop never returns. You can create GLUT windows just fine in the GLUT callbacks. Of course for user input to work you need at least one GLUT window; or you could try polling for input stdin in the GLUT idle callback, but recommend not doing that.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • ok..is there any solution for my problem. I am on learning phase and pardon my mistake. – solomyhansolo Feb 23 '15 at 10:16
  • Call `glutCreateWindow` from inside normal GLUT callback functions. If you want to create a window in reaction to a keypress you can do just that. You can reuse the same set of callbacks for every window. You will have to create an initial window to receive the input. Note that OpenGL is not a scene graph, so you have to snapshot the state of your application yourself, for the individual windows. – datenwolf Feb 23 '15 at 10:34
  • But, is it possible to display the window without using glutMainLoop. As i said i'm on learning phase so pardon my doubts. – solomyhansolo Feb 23 '15 at 10:52
  • @user3113901: No. You absolutele need `glutMainLoop` because without it no operating system event processing can take place. And for a window to become visible the events sent by the OS must be processed. `glutMainLoop` is not your enemy, it's your friend. Just use it. Whatever it is you want to do, do it in your event/idle callback functions. – datenwolf Feb 23 '15 at 11:15
  • I had no problem in using glutMainLoop,when my simulation was done and updated in each and every iteration by using timerFunc. But at present i am forced to do this in a way that simulation should be shown as per the interest of the user. So i used a simple "for loop" in which latter functions are called and when a condition satisfies display is invoked and there i got stuck with glutMainLoop. – solomyhansolo Feb 23 '15 at 11:31
  • @user3113901: Instead of a for loop or timerFunc register an idle callback function. Run one iteration of the simulation per calling of the idle function, and whenever the display should be **updated** use `glutPostRedisplay()` to ask GLUT to call the display function. To display a specific state in a new window, create a class or struct that holds that state, use an associative map (e.g. `std::map` in C++) that maps from GLUT window IDs to instances of that struct and register a display callback that will index into the map based on the GLUT window and and use the values for that to draw. – datenwolf Feb 23 '15 at 13:44
  • Mr. datenwolf can you help me on this error ? [link](http://stackoverflow.com/questions/31020257/visual-studio-when-changed-from-win32-to-x64-its-showing-linking-error) – solomyhansolo Jun 25 '15 at 05:35
1

Depending on which version of GLUT you are using there might be a function glutMainLoopEvent(), this will cause the rendering to render one frame and then continue from the point where it was called. I think this function might only exist in FreeGLUT though.

Daniel
  • 589
  • 4
  • 19