Each of the two handlers must be defined with an int parameter that receives the id of its corresponding control element. As noted in the construction of the elements, we are not using this value in the respective handlers.
The purpose of our spinner handler is to transmit the spinner value to the class object cgWorld. Thus, we define in that object a method that receives the value. Next, we obtain the spinner value through its method
get_float_value()
Putting the two together, our spinner handler simply makes the call
cgWorld.setAlpha(spinner->get_float_val());
The push button is constructed in this example for closing the program. We use an exception named ProgramExit for this purpose. (Note that in C++ an empty class is used for naming an exception.) In turn, our handler throws the exception to break the normal flow of execution. Since handling the exception means terminating the program, we write the catch statement in the main function after the glutMainLoop call.