Timing Graphics

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Timing Graphics

Post 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?
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Timing Graphics

Post by dandymcgee »

Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
lalacomun
VS Setup Wizard
VS Setup Wizard
Posts: 114
Joined: Wed Dec 28, 2011 10:18 pm
Favorite Gaming Platforms: psx, nintendo ds, gameboy advance, xbox 360, ps2
Programming Language of Choice: C++
Location: Argentina
Contact:

Re: Timing Graphics

Post by lalacomun »

Thats, the real deal !
Image
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Timing Graphics

Post by Benjamin100 »

Thanks.
User avatar
superLED
Chaos Rift Junior
Chaos Rift Junior
Posts: 303
Joined: Sun Nov 21, 2010 10:56 am
Current Project: Engine
Favorite Gaming Platforms: N64
Programming Language of Choice: C++, PHP
Location: Norway

Re: Timing Graphics

Post 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"
User avatar
THe Floating Brain
Chaos Rift Junior
Chaos Rift Junior
Posts: 284
Joined: Tue Dec 28, 2010 7:22 pm
Current Project: RTS possible Third Person shooter engine.
Favorite Gaming Platforms: PC, Wii, Xbox 360, GAME CUBE!!!!!!!!!!!!!!!!!!!!!!
Programming Language of Choice: C/C++, Python 3, C#
Location: U.S

Re: Timing Graphics

Post by THe Floating Brain »

superLED wrote: "Fuck your expensive hardware, I'll cap the game at 60 fps"
:lol:
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself

ImageImage
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Timing Graphics

Post 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
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Timing Graphics

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Timing Graphics

Post 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
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Timing Graphics

Post 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.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
superLED
Chaos Rift Junior
Chaos Rift Junior
Posts: 303
Joined: Sun Nov 21, 2010 10:56 am
Current Project: Engine
Favorite Gaming Platforms: N64
Programming Language of Choice: C++, PHP
Location: Norway

Re: Timing Graphics

Post 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);
User avatar
lalacomun
VS Setup Wizard
VS Setup Wizard
Posts: 114
Joined: Wed Dec 28, 2011 10:18 pm
Favorite Gaming Platforms: psx, nintendo ds, gameboy advance, xbox 360, ps2
Programming Language of Choice: C++
Location: Argentina
Contact:

Re: Timing Graphics

Post 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-)
Image
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Timing Graphics

Post 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
Post Reply