welford
Posts: 18
Joined: Fri Jun 29, 2012 12:05 am

hello_triangle.c sample

Mon Jul 16, 2012 1:46 pm

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.

User avatar
RaTTuS
Posts: 9489
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: hello_triangle.c sample

Mon Jul 16, 2012 2:01 pm

from memory
a mouse click
or ctrl-c
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

welford
Posts: 18
Joined: Fri Jun 29, 2012 12:05 am

Re: hello_triangle.c sample

Tue Jul 17, 2012 12:37 am

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.

mnajera
Posts: 10
Joined: Tue Jul 24, 2012 6:45 pm

Re: hello_triangle.c sample

Tue Jul 24, 2012 6:49 pm

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?

mnajera
Posts: 10
Joined: Tue Jul 24, 2012 6:45 pm

Re: hello_triangle.c sample

Tue Jul 24, 2012 7:44 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.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: hello_triangle.c sample

Tue Jul 24, 2012 8:13 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:

Code: Select all

int terminate = 0;
int counter = 0;
while (!terminate)
{
  update_model(state);
  redraw_scene(state);
  if (counter > 300) terminate = 1;
  counter++;
}
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.

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 6 guests