Timing Graphics
Moderator: Coders of Rage
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Timing Graphics
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?
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?
- dandymcgee
- 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
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- lalacomun
- 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
Thats, the real deal !dandymcgee wrote:http://lazyfoo.net/SDL_tutorials/lesson14/index.php
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Timing Graphics
Thanks.
- superLED
- 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
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"
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"
- THe Floating Brain
- 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
superLED wrote: "Fuck your expensive hardware, I'll cap the game at 60 fps"
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Timing Graphics
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
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
- dandymcgee
- 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
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.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"
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Timing Graphics
OK. Thanks.
OK. Now when I go from Triangle to Rectangle, things aren't working so well.
This seems to produce 5 vertices.
Any reason you would think for why that would happen?
-Benjamin
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();
Any reason you would think for why that would happen?
-Benjamin
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Timing Graphics
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.dandymcgee wrote: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.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"
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.
- superLED
- 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
Benjamin100 wrote:OK. Thanks.
OK. Now when I go from Triangle to Rectangle, things aren't working so well.
This seems to produce 5 vertices.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();
Any reason you would think for why that would happen?
-Benjamin
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);
- lalacomun
- 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
Ginto8 wrote: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.dandymcgee wrote: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.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"
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
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Timing Graphics
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
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