Page 1 of 1

Timing Graphics

Posted: Wed Feb 15, 2012 12:51 am
by Benjamin100
Hey, working with OpenGL again.
How do I time the graphics well?
I wanted things to move consistently, so I thought it would help to set up a timer to do something every so often.

I found that even though I was trying to change the variable for the distance at timed moments, it still seemed inconsistent when the screen was larger.
It seems like it doesn't always time out the same.
Is there a good way of timing the graphics?

Re: Timing Graphics

Posted: Wed Feb 15, 2012 9:26 am
by dandymcgee

Re: Timing Graphics

Posted: Wed Feb 15, 2012 10:36 am
by lalacomun
Thats, the real deal !

Re: Timing Graphics

Posted: Wed Feb 15, 2012 1:23 pm
by Benjamin100
Thanks.

Re: Timing Graphics

Posted: Wed Feb 15, 2012 5:26 pm
by superLED
Instead of capping it at 20 like in this tutorial, I would go for 60.

But if you want a frame independent system, which moves an object X pixels in Y seconds/milliseconds, go ahead and read this one: http://lazyfoo.net/SDL_tutorials/lesson32/index.php
That way, you can still play the game at 200 fps and 10 fps, and get the same timing.
Using this method, you won't say to a person with hardcore computer specs "Fuck your expensive hardware, I'll cap the game at 60 fps"

Re: Timing Graphics

Posted: Wed Feb 15, 2012 5:35 pm
by THe Floating Brain
superLED wrote: "Fuck your expensive hardware, I'll cap the game at 60 fps"
:lol:

Re: Timing Graphics

Posted: Wed Feb 15, 2012 5:47 pm
by Benjamin100
Interesting thoughts.

Once I looked at that tutorial I think I got it.
Before for some reason it didn't occur to me to put in a delay within the loop.
I didn't read through much of it because I got the idea once I saw the delay.
Seems to be testing at a consistent timing now, the delay being calculated from the time it takes to go through the function to the time I want it to take.

Thanks for the help,

-Benjamin

Re: Timing Graphics

Posted: Wed Feb 15, 2012 6:42 pm
by dandymcgee
superLED wrote:Instead of capping it at 20 like in this tutorial, I would go for 60.

But if you want a frame independent system, which moves an object X pixels in Y seconds/milliseconds, go ahead and read this one: http://lazyfoo.net/SDL_tutorials/lesson32/index.php
That way, you can still play the game at 200 fps and 10 fps, and get the same timing.
Using this method, you won't say to a person with hardcore computer specs "Fuck your expensive hardware, I'll cap the game at 60 fps"
Completely agree with this. I had forgotten lazyfoo has tutorials for both methods. This is definitely better than a simple framerate cap for anything you plan on distributing as a serious product.

Re: Timing Graphics

Posted: Wed Feb 15, 2012 7:24 pm
by Benjamin100
OK. Thanks.

OK. Now when I go from Triangle to Rectangle, things aren't working so well.

Code: Select all

 glBegin(GL_QUADS);
	   glColor3f(0.0, 0.0, 1.0);
	      glVertex3f(0.1, 0.5, 0.0);
		  glVertex3f(0.1, 0.1, 0.0);
		  glVertex3f(0.3, 0.5, 0.0);
		  glVertex3f(0.3, 0.1, 0.0);
    glEnd();
This seems to produce 5 vertices.
Any reason you would think for why that would happen?

-Benjamin

Re: Timing Graphics

Posted: Wed Feb 15, 2012 7:45 pm
by Ginto8
dandymcgee wrote:
superLED wrote:Instead of capping it at 20 like in this tutorial, I would go for 60.

But if you want a frame independent system, which moves an object X pixels in Y seconds/milliseconds, go ahead and read this one: http://lazyfoo.net/SDL_tutorials/lesson32/index.php
That way, you can still play the game at 200 fps and 10 fps, and get the same timing.
Using this method, you won't say to a person with hardcore computer specs "Fuck your expensive hardware, I'll cap the game at 60 fps"
Completely agree with this. I had forgotten lazyfoo has tutorials for both methods. This is definitely better than a simple framerate cap for anything you plan on distributing as a serious product.
I think that this is actually a bad idea, at least as lazyfoo does it. It may not be an issue for a very small game, but if there are any lag spikes, your logic is very likely to be messed up (read: possibly very large location jumps). I would recommend that you take this sort of method, but add lag protection: for example, you could limit the amount of time each logic loop can process. If you want your game to respond in a timely manner without major lag jumps, you could ensure that at least 20 iterations of the game logic occur each second by processing <=1/20 of a second each frame. It has the best of both worlds: the game responds consistently even during lag spikes, and it can still take advantage of faster hardware.

Re: Timing Graphics

Posted: Thu Feb 16, 2012 7:27 am
by superLED
Benjamin100 wrote:OK. Thanks.

OK. Now when I go from Triangle to Rectangle, things aren't working so well.

Code: Select all

 glBegin(GL_QUADS);
	   glColor3f(0.0, 0.0, 1.0);
	      glVertex3f(0.1, 0.5, 0.0);
		  glVertex3f(0.1, 0.1, 0.0);
		  glVertex3f(0.3, 0.5, 0.0);
		  glVertex3f(0.3, 0.1, 0.0);
    glEnd();
This seems to produce 5 vertices.
Any reason you would think for why that would happen?

-Benjamin
Image

This will draw a correct rectangle:

Code: Select all

	glVertex3f(0.1, 0.5, 0.0);
	glVertex3f(0.5, 0.5, 0.0);
	glVertex3f(0.5, 0.1, 0.0);
	glVertex3f(0.1, 0.1, 0.0);

Re: Timing Graphics

Posted: Thu Feb 16, 2012 11:42 am
by lalacomun
Ginto8 wrote:
dandymcgee wrote:
superLED wrote:Instead of capping it at 20 like in this tutorial, I would go for 60.

But if you want a frame independent system, which moves an object X pixels in Y seconds/milliseconds, go ahead and read this one: http://lazyfoo.net/SDL_tutorials/lesson32/index.php
That way, you can still play the game at 200 fps and 10 fps, and get the same timing.
Using this method, you won't say to a person with hardcore computer specs "Fuck your expensive hardware, I'll cap the game at 60 fps"
Completely agree with this. I had forgotten lazyfoo has tutorials for both methods. This is definitely better than a simple framerate cap for anything you plan on distributing as a serious product.
I think that this is actually a bad idea, at least as lazyfoo does it. It may not be an issue for a very small game, but if there are any lag spikes, your logic is very likely to be messed up (read: possibly very large location jumps). I would recommend that you take this sort of method, but add lag protection: for example, you could limit the amount of time each logic loop can process. If you want your game to respond in a timely manner without major lag jumps, you could ensure that at least 20 iterations of the game logic occur each second by processing <=1/20 of a second each frame. It has the best of both worlds: the game responds consistently even during lag spikes, and it can still take advantage of faster hardware.

I agree with ginto ,these way you can ensure your 20 frames but if having a better hardware you can run it at more
frames 8-)

Re: Timing Graphics

Posted: Thu Feb 16, 2012 1:37 pm
by Benjamin100
Thanks.
Thank you for the illustration, that helped.
I wasn't paying enough attention to the order, I just saw 4 points and thought it should make a 4 sided figure.

Thank you,

-Benjamin