Search code examples
openglglutglu

How to check window is open via openGL or Glut


I have seen a method in SFML called isOpen which checks if the window is open.

Is there any similar equivalent in openGL or GLUT which checks if the window is open?


Solution

  • OpenGL render to a framebuffer attached to an OpenGL rendering context. The rendering context may have been created from a window connecting the (default) framebuffer to the window, but this is out of scope for the OpenGL spec.

    As for GLUT you can use glutSetWindow to set the window id you want to check whether or not it exist, and then do glutGetWindow. If it returns the window id previously set the window exist. If not, glutSetWindow obviously failed because the window does not exist.

    Whether or not this is true seems implementation dependent, but I doubt anyone would be stupid enough to not implement error handling in such a trivial case.