Close window glut automatically and continue execution
IIRC glut was just created to allow easier creation of simple OpenGL demos having a single window for the lifetime of the program.
You are probably better off using a more modern library like GLFW, which gives you more options.
IIRC glut was just created to allow easier creation of simple OpenGL demos having a single window for the lifetime of the program.
You are probably better off using a more modern library like GLFW, which gives you more options.
YEP. Glut/FreeGlut aren't even maintained anymore.
Go GLFW. And, since you were using Glut, it's very likely you were using GLEW, too. Use Glad (https://github.com/Dav1dde/glad or http://glad.dav1d.de/), instead. GLEW is being dropped little by little.
Use glutMainLoopEvent instead. Put this in your own while loop and you get to control the lifespan of your program more directly. I.e when you leave your loop, the application can end.
Make sure to include <GL/freeglut.h> instead of <GL/glut.h> because this function is only available in the extended FreeGLUT feature set.
The last commit to FreeGLUT was in 2016-02-21 so is... stable lol. Hoever work has been done on it since then to port it to i.e Emscripten / WebGL. I like that the API is simple and provides a very diciplined set of features. On platforms providing their own random APIs such as Android, Marmalade, iOS etc, I always make a Glut-like wrapper so the core of my code is very portable. So I actually recommend keeping with Glut.
Also, for DirectX, check out DXUT (A clone of Glut for DirectX, used to be part of the DirectX SDK, now a separate project).
For more information on FreeGLUT, check out the API docs. http://freeglut.sourceforge.net/docs/api.php
Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.
Use glutMainLoopEvent instead. Put this in your own while loop and you get to control the lifespan of your program more directly. I.e when you leave your loop, the application can end.
The main loop implementation in Glut/FreeGlut is awful. The way it gather events, the way it work with timers.
The last commit to FreeGLUT was in 2016-02-21 so is... stable lol.
Dude, this was EONS ago. GLFW, SFML, SDL2 all have commits that date days ago.
Dude, this was EONS ago. GLFW, SFML, SDL2 all have commits that date days ago.
Yeah I know but it is simple. Sometimes simple is nice because if all else fails, I can fall back to it and maintain it myself if needed for a specific requirement / platform.
Also, being simple means it is first in line for a port. I.e to Emscripten it was pretty much released with the compiler. Whereas GLFW and SDL2 came almost a year late. SFML is still not supported either.
As for the main loop in Glut. Many platforms don't let you control the main loop directly (i.e again, Emscripten, Android etc...) or they become "unresponsive". Glut's janky C callback system actually works quite nice with this restriction.
For timers, I just don't use them. I generate a time delta and a frame limiter just like I do when using GLFW.
To be fair, these libraries are all pretty much the same. They just need to open a darn window without manually coding horrid WinAPI or X11/xcb C code ;)
Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.