A countdown timer in OpenGL [closed] - c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I wish to creat a countdown timer in OpenGL. So I am just looking for a function that will be called every second based on the system clock which will decrease a set variable. I tried fiddling with glutTimerfunc but itcalls back only once. I need a similar setup but one that calls back multiple times.

Timers and timer functions are neither defined by C++ nor by OpenGL but rather by the operating system you are using.
However, since GLUT seems to define one, and you are using it, here we go:
In your timer function passed to glutTimerFunc, just call glutTimerFunc with the same parameters again. That way you will end up creating an infinite loop of timer callbacks.
Use some global variable or the int value passed to the timer function to determine when to break the loop.

Related

Calling 2 functions in an alternating manner in display function [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have a function that simply constructs a stick figure in 1 position
I have another function that builds a stick figure in another position.
I now want to call these functions alternatively so that the figure will appear to walk.
I'm not sure if I have to push and pop matrices.
For such rudimentary animation, will a boolean flag not do? (OpenGL doesn't even come into it here, it's merely logic)
I.e. in your draw method:
animate = !animate; // flip flag for 2 possible frames (boolean member variable)
if (animate) {
// draw position 1
} else {
// draw position 2
}
However, bear in mind this is just some quick sample code to get the idea across - it would result in every frame having the animation occur, which would likely occur so fast to be nauseating. You will have to apply time logic to it as well to make the simple animation not just appear as a blur.

Real time programming in robotics with c++ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am working on a robotics project with C++ and OpenCV. In this step, I have faced a problem which consists of:
I have two methods moveRight() and moveLeft() that I called successively in my code, but the problem is that the second one does not run, because the first one needs time (the time of robot movement), but when I put Sleep(5000) between them (I guessed that five seconds are enough for the movement), all is OK.
What is a programming solution that avoid the use of Sleep (because it makes some other problems)?
You can try to add a layer of indirection. Add a queue of actions to perform, enqueue actions to moveLeft and moveRight, and somewhere else (different thread) execute actions from the queue correctly by waiting for previous action to complete before you do next action. Ideally you need a way to check if action is finished, so you can code it in a event based fashion.
You should never "guess" in robotics. You should KNOW, MEASURE how long your movement takes and use that in your code. For instance call moveRight() often and have it check how long it has been running. Make it return true when it's running and use that as a condition to call moveLeft()
You can use a timer and when performing MoveRight() set the timer on 5 seconds, and after timer ends, perform Moveleft().

How does one make something real time? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
This might be a really stupid question, but I can't find any info on this, and I can't find out what to search for.
How do you make something real time? For example, say we have a game, how does it run continuously without us calling a tick() method at different parts of the program?
If you are developing the program to run at a time in particular the best way I know of is to develop it to run at a particular loop rate using timed delays.
IE:
while(forever) {
do something
test how long it took
take up the remainder amount of time for the loop to run at a rate (ie 100Hz)
}
If you are desperate for real time applications you can develop and use QNX:
http://www.qnx.com/
But this certainly wouldn't be a good environment for programming games.

C : printf changes course of program [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I've got a program that simulates collisions (circles) using openGL, GLUT, GLUI. Everything worked fine but when I changed my code a bit it began to do weird things.
I have 2 buttons, "play" and "step", "play" simulates the collisions updated with a timer, "step" also simulates but you've got to click it in order to go further.
Originally it did that but now the "play" button acts the same as "step". If I add a printf in my timer callback it all works perfectly...
What can I do ?
In my timer_cb I only have got :
// printf("something\n");
glutPostRedisplay();
glutTimerFunc(getDeltaT(), timer_cb, 0);
The I/O routines, like printf, introduce a sensible delay by calling them. To answer with a certain degree of correctness you show us the User Interface code, but I think I can guess...
Are you using threads? Maybe it can be a concurrency bug because the execution of the button event handler is not synchronized with the update logic?

Run "While loop" in background [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have a Credential Provider dll application in C++. Inside this dll i create a process that will write some data in a file. I need somehow to read that data from file till the value is > -1. I can not use a while loop because my dll will stop loading till the while loop will end. Can i use a separate thread to do this and to get a notification to run a function from my dll when the while loop end? How can i do this? Is there a simple way to do this?
Thank you.
The only really practical way to achieve concurrency is using threads. Take a look at boost threads.
If your compiler implements C++0x thread, then you can make use of it.
Read this extensive tutorial on C++0x multi-threading : Multithreading in C++0x part 1: Starting Threads