I'm new to linux and running OpenGL programs from the command line.
I have a question regarding the hello_triangle.c sample source (i believe it's in /opt/vc/source/hello_pi/hello_triangle)
It has variable: static volatile int terminate; on which terminating the program is decided. how is this variable set? once I have this sample running i can't figure out how to make it stop.
Thanks for any help.
hello_triangle.c sample
6 posts
- Posts: 7
- Joined: Fri Jun 29, 2012 12:05 am
from memory
a mouse click
or ctrl-c
a mouse click
or ctrl-c
1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX - Prosliver FTW
Ctrl-C seems to work ,thank you.
only Ctrl-C seems to work for hello_triangle.c, for hello_triangle2.c either Ctrl-C or a mouse click works.
only Ctrl-C seems to work for hello_triangle.c, for hello_triangle2.c either Ctrl-C or a mouse click works.
- Posts: 7
- Joined: Fri Jun 29, 2012 12:05 am
The question remains: how is the variable terminate being set? Similar code appears in hello_triangle2.c. In both programs, there is no other appearance of the terminate variable. Is it being set by some outside process?
- Posts: 10
- Joined: Tue Jul 24, 2012 6:45 pm
I think I know how the terminate variable is being used here: it isn't.
I was thrown by the fact that a mouse click ends the hello_triangle2 program, but I failed to see that a button press was being explicitly checked for, resulting in a break from the while loop. The "while (!terminate)" may as well be "while (1)", since the variable is never modified. Pressing CTRL- C just stops the hello_triangle and hello_triangle2 programs via a SIGINT.
This example code for hello_triangle is slightly misleading in this regard, since it clearly defines an exit_func() routine that never gets called.
Either way, my question is answered. I was just worried that there was some sort of convention that I was missing somewhere.
I was thrown by the fact that a mouse click ends the hello_triangle2 program, but I failed to see that a button press was being explicitly checked for, resulting in a break from the while loop. The "while (!terminate)" may as well be "while (1)", since the variable is never modified. Pressing CTRL- C just stops the hello_triangle and hello_triangle2 programs via a SIGINT.
This example code for hello_triangle is slightly misleading in this regard, since it clearly defines an exit_func() routine that never gets called.
Either way, my question is answered. I was just worried that there was some sort of convention that I was missing somewhere.
- Posts: 10
- Joined: Tue Jul 24, 2012 6:45 pm
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:
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;
while (!terminate)
{
update_model(state);
redraw_scene(state);
if (counter > 300) terminate = 1;
counter++;
}
- Posts: 175
- Joined: Fri Sep 23, 2011 12:29 pm
- Location: Netherlands