Correct. I already typed this up (and was double checking) while you were posting. Here it is anyway. You're also right about the bit misleading exit_func().
I assume the programmer of the triangle.c simply wasn't willing to use a 'while(1)'. Either out of principle or habit. It's just an infinite loop.
The while loop in triangle2.c would probably have made (a little bit) more sense if the 'if (b) break;' was replaced with 'if (b) terminate=1;'. At least then the question wouldn't have been asked
The simplest way to break neatly out of the loop in triangle.c would be to introduce a counter:
Code: Select all
int terminate = 0;
int counter = 0;
if (counter > 300) terminate = 1;
This way, only 300 frames will be drawn. Then the program will quit automatically after 5 seconds (the time it takes to draw the 300 frames at 60 FPS). The exit_func() will also be called then.