display doesnt update

Have sarted the NeHe tutorials and its all well and good untill i gwt to the 4th lesson.

Its the rotation one.

Whats meant to happen is the tirngles and square are meant to rotate around a point. But it doesnt for me.

It does when i have
glutPostRedisplay(); //in display
or
glutIdleFunc(display);//in main

But if i use these i als have to have a 50 million loop just to see the animations, as it goes so fast.

Is there a way i can get the display function to update it self? as i am lost and ideally dont want to have to use the above methods.

Cheers

I have not had any problems with any of the nehe tutors not working?
I take it you have downloaded the glut version of this tutor?

Note tutors are only examples not how you would handle somethings in a full blown game or application.

He just uses a basic loop to rotate the triangles and no account for CPU speed is taken, so of course on a fast machine you will have them spin very fast.

If you have glutPostRedisplay() at the end of your display routine, it is going to get to the end of the display and then recall its self and there is going to be no delay.

The same for using glutIdleFunc(display), it is called when glut is not doing anything and on a fast machine it also will be called fast.

To control speed you can use a timmer function and set how many times per second to update the display. glutTimerFunc(time in ms, function to call, id number);

example of one of my timer loops:

static void TimeEvent(int te)
{
int timent;
int i;

    rotate_y++;  // I update my rotation value here
           

glutPostRedisplay();  // update display with new rotation values.
glutTimerFunc( 10, TimeEvent, 1); // Timer is a one shot so must be reset after each call

}

The more nehe tutors you go through the better your understanding of how to program in openGL will grow.

Also check out my glut examples on my website: www.angelfire.com/linux/nexusone

Originally posted by nexusone:
[b] [quote]Originally posted by Andrew Davey:
[b]Have sarted the NeHe tutorials and its all well and good untill i gwt to the 4th lesson.

Its the rotation one.

Whats meant to happen is the tirngles and square are meant to rotate around a point. But it doesnt for me.

It does when i have
glutPostRedisplay(); //in display
or
glutIdleFunc(display);//in main

But if i use these i als have to have a 50 million loop just to see the animations, as it goes so fast.

Is there a way i can get the display function to update it self? as i am lost and ideally dont want to have to use the above methods.

Cheers[/b]
[/b][/QUOTE]Is there no reply because you dont underdstand my problem or that i have no problem?

If its that you dont understand well my program only displays one frame, unless i use the above methods, but when i do the animation is so fast i cant see what is happening so at the top of display i have to use this
for(n=0;n<50000000;n++){}

This will make the animation abit better.

I would rather not use the above method unless i have to.

Does that make it clearer?

sorry nexusone you had obviously editted your post.

I will have alook at your sight and also look into this timer. When you say “Timer is a one shot so must be reset after each call” what do you mean. Do you mean everytime i use it i have to do the above or what please?

Another option is to update as fast as you can, but do your animation based on real time. With this method, faster machines just make the animation smoother, not faster.

For instance, say your animation is just a rotating teapot. First, decide how fast you want it to rotate. Say for instance 10 degrees every second… Now, when you first start at a 0 degree rotation, get a millisecond value from something like Windows timeGetTime(). (There are ways to get timers of greater precision, but this one is nice and easy to use, so I’ll demonstrate using it.)

Now in your Display function, just do something like so:

const int ROTATE_SPEED_ANG_PER_SEC = 10;

void Display()
{
    static int dwTimestamp = 0;
    float fAngle = 0;

    if (dwTimestamp == 0)
    {
        dwTimestamp = timeGetTime();
    }
    else
    {
        int dwNewTimestamp = timeGetTime();
        int dwElapsedTime = dwNewTimestamp - dwTimestamp;
        fAngle = ROTATE_SPEED_ANG_PER_SEC * dwElapsedTime / 1000.0;
    }
 
    glPushMatrix();
    glRotatef(fAngle, 0.0, 1.0, 0.0);
    glutSolidTeapot(1.0);
    glPopMatrix();
}

What Nexusone meant about glutTimerFunc being a “one-shot timer” is that it calls the function you specify after the amount of time once. If you want it to be called again, you call glutTimerFunc again at the end of the timer function.

Also, I wanted to clarify one little thing that nexusone said about glutPostRedisplay. If you put it at the end of your Display function, it doesn’t directly cause Display to be called right away from that point. It actually puts a message in the queue saying the screen needs to be repainted again. Then glutMainLoop will see a new paint message and call it again. This is maybe a minor point, but it can be important to understand. Your display function WILL exit before it is called again.

If it didn’t work this way, and you tried to use glutPostRedisplay at the end of the Display function, your message handling thread would be held up, and you would never get any of the other messages such as mouse and keyboard events.

Well, if they are spining too fast, lower the amount you are rotating the objects, nehe usese about .15 degrees per call to the display function. It should not spin that fast as i have a considerable processor on my computer and they were not spining that fast. Either you have your rotation variable incrementing by too much or, im going to hack your gibson super computer.

One shot is a term use to state that until you restart the timer it will only be called once.

Sort of like a single shot gun, you must reload a new bullet each time you fire it!

At the end of my code timer routine I restart the timer by calling the glutTimerFunc, which creates a loop.

Originally posted by Andrew Davey:
[b]sorry nexusone you had obviously editted your post.

I will have alook at your sight and also look into this timer. When you say “Timer is a one shot so must be reset after each call” what do you mean. Do you mean everytime i use it i have to do the above or what please?[/b]

ah seen, ok, i understand, have looked at your code nexusone and understand what you do.

Also in respons to the rotate nehe statement, (2 posts up) i tried that but even at 0.01f and lower the animation was just to fast.

I think the main reason is not alot is happening so computational time is very small.

Have implemented the timerfunc and works as is expected, except i get flickering, i have already posted this as a probelm. As of yet i havent solved that problem, but i think it is because my timerfunc is inside the display and just calls the display, not sure. We shall see.

If anyone can help with the flicker it would be much appreciated.

Cheers.

p.s. just so you guys know for the future millions of posts, i have to do my final year project and have only started to learn openGl, have to get a good understanding to do what i would like, so there will be a few more “mundane” posts from me. I am thankful for all the help i have recieved so far, has helped me alot. Have even begun helping other people. So basicaly thanks and appologies for future small problems that i will post.