Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to smooth graphics

This thread is locked; no one can reply to it. rss feed Print
 1   2   3   4 
How to smooth graphics
Paul whoknows
Member #5,081
September 2004
avatar

Quote:

somebody mentioned delta time, so I think I'll play around with that and start using a high resolution timer, maybe that will help?

Yes, or you can also try Richard Phipps's high resolution timer, is easier and it works well(I am using it in my project).

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Albin Engström
Member #8,110
December 2006
avatar

i spent almost an hour answering.. just to press backspace and go "back".. i'm to pissed of right now, i may answer when i've cooled down. - -

GullRaDriel
Member #3,861
September 2003
avatar

Albin:
Your profile says : "Finished projects: NONE (i'm young so i expect you to understand ^^)."

Please listen to others. Some people were here before your born. Some of the people who have answered you are also allegro developer / maintainer. THEY are right (here and most of the time).

It is while forging that one becomes blacksmith. ( Et c'est en sciant que Léornard De Vinci ;-p )

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Kauhiz
Member #4,798
July 2004

I'd like to hear your reply, Albin. :)

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

Albin Engström
Member #8,110
December 2006
avatar

As i'm too tired to answer as detailed as i did(would have..) i'll make it short:

Kauhiz said:

This is what I was saying -- others don't have this problem. Do you honestly think that if there was an issue like this in allegro, you'd be the first to notice it? (Yes, you could notice bugs, but if it's in everything made with the lib it would be noticed quite quickly).

How would i know? the only thing i know is that when i run applicitions made with allegro i can see a thing that's bothering me, i don't know if anyone else sees this too, but it's there. i've tried to capture it on video but i doesn't show, and when i say video i don't mean a camera, i mean a program that records the screen. this thing is very small and almost invisible at first, it took me 3 week before i actually saw it.. (although i didn't have much of a screen in the beginning...). i'm not trying to be offensive by questioning whenever or not allegro is perfect or something, the reason i asked about this problem was because i had no clues left of what might be the problem..
i'm not really good at English so i guess i can get missunderstood alot.. :-/.
I have a rule that i should never settle with truth.. if you're wondering why i'm so persistent..

Evert said:

Ah, ok. So I take it your code works fine then?

Yes, it does work, it works great, but that little thing is really annoying.

Evert said:

How do you expect to solve a problem if you don't know where the problem is to begin with?

Is it a problem if you know what the problem is? who knows what's the cause of the problem, if you find out, it's not a problem anymore..
I can see the problem, but i don't know the cause nor do i know how to describe it, i guess i could live with it, but i'd rather not. but you say that there's no other choice right?

GullRaDriel said:

Please listen to others. Some people were here before your born. Some of the people who have answered you are also allegro developer / maintainer. THEY are right (here and most of the time).

I do listen to others, even if it seems like i don't, that's why i ask.

I'm a newbie so i guess you would get kinda angry when i question allegros functionality. but i still don't think i did wrong asking those questions...
Questioning everything is important. atleast that's what i think.

well, i replied to a small part aleast, the most important parts. AND i used quote tags :), i'm a quick learner...

ImLeftFooted
Member #3,935
October 2003
avatar

Haven't read the whole thread, so someone might have answered already.

This code:

volatile int speed;

should be:

volatile int speed = 0;

That should solve a lot of your problems.

Also I would remove the vsync call entirely.

Evert
Member #794
November 2000
avatar

Quote:

How would i know?

That's why you start by assuming that you screwed up before suggesting someone else did. ;)

Quote:

i'm not trying to be offensive by questioning whenever or not allegro is perfect or something,

It most definately isn't.

Quote:

the reason i asked about this problem was because i had no clues left of what might be the problem..

Post some of your code that clearly shows the problem. You can say it shows up with the Allegro examples, but as others (and I) have said, they don't see a problem there and as I said there are several things you should be doing differently anyway.

Quote:

i'm not really good at English so i guess i can get missunderstood alot..

Your English is fine. At least I haven't had a problem with it.

Quote:

Is it a problem if you know what the problem is? who knows what's the cause of the problem, if you find out, it's not a problem anymore..

Don't be silly. If a program segfaults if you do X, is that nota problem because you know it will, or should you fix it because a program isn't supposed to crash?

Quote:

but you say that there's no other choice right?

I didn't.
But: if your logic does not update at (an integer multiple of) the screen refresh rate, you will see (quasi)periodic jitters in the output because graphics and game state update at a different frequency (it's basically the same effect as when you hear two freqeuncies that are close but not equal). That cannot be avoided unless you use something like a "delta time" method to synchronise your game, fix the gamespeed depending on the computer it runs on (not normally a good idea) or run your logic rate at an integer multiple of any common refresh rate (35700 Hz should cover 60, 70 and 85 Hz monitors) which is problematic because you need an insanely high timer frequency.

Quote:

I'm a newbie so i guess you would get kinda angry when i question allegros functionality.

That's not exactly the problem. The problem is the "newbie with attitude," who thinks they know what they're talking about because they've just written "Hello World!" ;)
You're not in that category, but assuming there is a problem with a third-party library before your own code is simply wrong. I've been programming for about fifteen years and I can tell you from experience that when a program of mine screws up, it's usually because of something I did, not because of what others did.

Quote:

Questioning everything is important.

Not accepting everything at face value and being critical are important qualities. Questioning everything is just annoying.

Kauhiz
Member #4,798
July 2004

Quote:

I do listen to others, even if it seems like i don't, that's why i ask.

I'm a newbie so i guess you would get kinda angry when i question allegros functionality. but i still don't think i did wrong asking those questions...
Questioning everything is important. atleast that's what i think.

No one's angry at you for asking questions or questioning allegro's functionality (or for anything else for that matter). The point being that most people posting here are speaking from experience. So if you say there's a problem with allegro and you're told that there isn't, it's not that we're guessing there isn't - it's experience. If the issue really was with allegro, no one would deny it, of course, and it would be looked into.

Quote:

AND i used quote tags :), i'm a quick learner...

Well, I don't know, you have been here for something like two months... ;)

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

Richard Phipps
Member #1,632
November 2001
avatar

Quote:

or run your logic rate at an integer multiple of any common refresh rate (35700 Hz should cover 60, 70 and 85 Hz monitors) which is problematic because you need an insanely high timer frequency.

I run my logic at 240 or 250 times a second. While not perfect it works better with a fixed logic rate than lower values. You could try this too if you don't want to start using delta time.

Albin Engström
Member #8,110
December 2006
avatar

Evert said:

Post some of your code that clearly shows the problem. You can say it shows up with the Allegro examples, but as others (and I) have said, they don't see a problem there and as I said there are several things you should be doing differently anyway.

well, i guess there's something wrong with my computer then.. although this problem only shows up when playing allegro related programs. and as for those things i should be doing differently i already do them differently :/.

Evert said:

Your English is fine. At least I haven't had a problem with it.

Thank you :).

Evert said:

Don't be silly. If a program segfaults if you do X, is that nota problem because you know it will, or should you fix it because a program isn't supposed to crash?

hm, i meant that if you know how to fix a problem, it's basibasically a problem any more :/.

Evert said:

But: if your logic does not update at (an integer multiple of) the screen refresh rate, you will see (quasi)periodic jitters in the output because graphics and game state update at a different frequency (it's basically the same effect as when you hear two freqeuncies that are close but not equal). That cannot be avoided unless you use something like a "delta time" method to synchronise your game, fix the gamespeed depending on the computer it runs on (not normally a good idea) or run your logic rate at an integer multiple of any common refresh rate (35700 Hz should cover 60, 70 and 85 Hz monitors) which is problematic because you need an insanely high timer frequency.

Interesting... i use a fixed logic refresh rate of a 1000 loops per second(i've been told this is too much but i have no problem with it on my computer or less capable computers), i use triplebuffering and the screen refresh rate is 85. would it cause this effect?
if i used doublebuffering and sett the screen refresh rate to 100, would it not cause this effect?, but how does the display react if i use the same refresh rate for logic and graphics but calculate for example a ships posipositionlthough i don't think i could write a game this way, without making it the way i don't want it). i'd love to hear more about it.

Evert said:

That's not exactly the problem. The problem is the "newbie with attitude," who thinks they know what they're talking about because they've just written "Hello World!" You're not in that category, but assuming there is a problem with a third-party library before your own code is simply wrong. I've been programming for about fifteen years and I can tell you from experience that when a program of mine screws up, it's usually because of something I did, not because of what others did.

Hehe ^^, well, i guess it's wrong to assume that there's a problem with a "third-party library" before my own code(and absoabsolutelyn i'm as inexperienced as i am), but i thougth the examples where made by someone who developed allegro and because they had this "problem" i thought(no i didn't, it was more like a very distant ...thing(i can't find the word - -).) that it had something to do with allegro, and i'm not sure it was meant like a problem, more like a thing, yes, a "thing" is a good word for it..

Evert said:

Not accepting everything at face value and being critical are important qualities

^^' that's how i wanted it to be read..

Kauhiz said:

No one's angry at you for asking questions or questioning allegro's functionality (or for anything else for that matter). The point being that most people posting here are speaking from experience. So if you say there's a problem with allegro and you're told that there isn't, it's not that we're guessing there isn't - it's experience. If the issue really was with allegro, no one would deny it, of course, and it would be looked into.

Great :), i felt like someone was angry at me.:'(. They may be speaking from exerexperiencet a simple answer dosedoesn'tesatisfyeven if it's true, i have to hear a detailed explanation before i leave it alone.. the problem is that no one seems to know anything about the "problem" i have, and by seeing how the allegro examples doesn't do it better that my code i had no real thing to go for other than allegro.. and my computer which i actually think is the cause with about a 99% chance... i really don't know what to believe.. i should take a small program and test it on other computers to see if this effect will turn up.

Kauhiz said:

Well, I don't know, you have been here for something like two months...

Hehe ^^', well, when i think about it, i acctactuallyrned how to use quote tags upon request a while ago, but it's seams like i forgot about it..
2 months? time goes fast..

Richard Phipps said:

I run my logic at 240 or 250 times a second. While not perfect it works better with a fixed logic rate than lower values. You could try this too if you don't want to start using delta time.

Hmm. delta time.. sounds like something from hell..

:)

Kauhiz
Member #4,798
July 2004

Quote:

delta time.. sounds like something from hell..

Not at all. Delta timing basically means that in your logic you multiply values by the change in time (delta means change or difference in physics) since the last loop.

//This:
player.x++;
//changes to this:
player.x += deltaTime * speed;
//where speed is the speed you want you player to move at

I like delta timing, because it has a more "physical" feel to it, if you get what I mean. Anyway, when you do this you just let your logic run freely, without limiting it, and your game will run smoothly on all systems. The only thing you have to do is figure out the delta time. If you want the easy way (IMO), try OpenLayer. It gives you a bunch of other cool stuff as well ;)

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

Evert
Member #794
November 2000
avatar

Quote:

i use a fixed logic refresh rate of a 1000 loops per second(i've been told this is too much but i have no problem with it on my computer or less capable computers), i use triplebuffering and the screen refresh rate is 85. would it cause this effect?

Yes, since 85 does not divide 1000.

About delta-time, there is one thing to consider. This is not nescessarily a problem, but if you're varying the timestep, you're affecting the outcome of numerical integration, which means results can be slightly different. I suspect the problem is insignificant for most games and if you have to, there are ways around it and/or better ways to integrate than the fairly standard direct Euler integration. It is something you may want to remember for later on though.

HardTranceFan
Member #7,317
June 2006
avatar

Is there a way to get the screen refresh rate using C or C++?

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Kauhiz
Member #4,798
July 2004

I'm not sure, but I there isrequest_refresh_rate

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

HardTranceFan
Member #7,317
June 2006
avatar

Cheers Kauhiz. I followed the link and found get_refresh_rate. I'll check this out later on.

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Kauhiz
Member #4,798
July 2004

D'oh, why didn't I post that ::)

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

Albin Engström
Member #8,110
December 2006
avatar

[..i thought i answered this already!? :'(]

Kauhiz said:

Not at all. Delta timing basically means that in your logic you multiply values by the change in time (delta means change or difference in physics) since the last loop.//This:
player.x++;
//changes to this:
player.x += deltaTime * speed;
//where speed is the speed you want you player to move atI like delta timing, because it has a more "physical" feel to it, if you get what I mean. Anyway, when you do this you just let your logic run freely, without limiting it, and your game will run smoothly on all systems. The only thing you have to do is figure out the delta time. If you want the easy way (IMO), try OpenLayer. It gives you a bunch of other cool stuff as well

I know what delta means :).. altough i didn't know i could mean change aswell. Well if you mean that i should use the same logic rate as screen refreshrate and use delta time: the reason i don't want to use this delta time thing is that if the program would go down to lets say like 10fps a lot of things wouldn't work right? unless i would have to add a lot of code making it work,, and i can't imagine that code in my head(not that i have sit down and thought about it). i like using a logic loop of 1000. it makes me think clearly, and i have no problem running it on my computer or a less capable one. :), hehe, i've been thinking about OpenLayer, but i've been having some problems compiling it :P.

Evert said:

Yes, since 85 does not divide 1000.

It wasn't the dividing thing i was unsure of.. but it still answered my question :P

Evert said:

About delta-time, there is one thing to consider. This is not nescessarily a problem, but if you're varying the timestep, you're affecting the outcome of numerical integration, which means results can be slightly different. I suspect the problem is insignificant for most games and if you have to, there are ways around it and/or better ways to integrate than the fairly standard direct Euler integration. It is something you may want to remember for later on though.

Last time i wrote the replys i said "I'm having a problem following, i should get some rest and then try to understand again" well, it's seems like i don't understand even with after a good rest.. :(. there's so many difficult words like.. "numerical integration"?, "varying the timestep"- - and "Euler integration"!

is it possible to convert those word into some more understandable words for me? :P

Kauhiz
Member #4,798
July 2004

Quote:

Well if you mean that i should use the same logic rate as screen refreshrate and use delta time

No. When you use delta timing, you don't limit the logic rate at all. It can run 10 000 times on one machine and 100 times on another, but both will look the same.

Quote:

if the program would go down to lets say like 10fps a lot of things wouldn't work right?

I imagine there would be some problems in such cases, but probably nothing that can't be worked around. If you chose to use OpenLayer like I suggested, I'll be amazed if you manage to get the fps below 50 on any reasonable system rendering any reasonable effects ;).

Quote:

is it possible to convert those word into some more understandable words for me?

Is it possible to use google or wikipedia or something? :P

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

kikabo
Member #3,679
July 2003
avatar

Quote:

if the program would go down to lets say like 10fps a lot of things wouldn't work right?

You could always add something like this :-

while(! Game::Over() )
{
   dt = Timing::get_dt();

   while(dt > MAX_DT)
   {
      Game::Logic(MAX_DT);
      dt -= MAX_DT;
   }

   Game::Logic(dt);
   Game::Draw();
}

Evert
Member #794
November 2000
avatar

Quote:

there's so many difficult words like.. "numerical integration"?, "varying the timestep"- - and "Euler integration"!

is it possible to convert those word into some more understandable words for me?

Not really. If you don't know what integration is, I'm not going to be able to explain it in a way that makes it clear in a few words. You'll need to read a mathematics text book for that.

As I said, don't concern yourself with that; if you do run into problems, then would be teh time to remember and look these things up.

Road Runner
Member #7,280
May 2006

Dustin Dettmer said:

Haven't read the whole thread, so someone might have answered already.

This code:

volatile int speed;

should be:

volatile int speed = 0;

That should solve a lot of your problems.

Also I would remove the vsync call entirely.
Dustin Dettmer

Tried both of those, and removing vsync(); just made the problem worse on my laptop.

I should have asked this in my first post (sorry), so here goes...If anyone has encountered the jitter problem before, what exactly did you use to fix the problem????

Paul whoknows
Member #5,081
September 2004
avatar

Quote:

I should have asked this in my first post (sorry), so here goes...If anyone has encountered the jitter problem before, what exactly did you use to fix the problem????

Just use a high resolution timer, like the one I suggested in my previous post.
Or do a search in these forums and you will find a lot of threads about high resolution timers.

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Albin Engström
Member #8,110
December 2006
avatar

Kauhiz said:

No. When you use delta timing, you don't limit the logic rate at all. It can run 10 000 times on one machine and 100 times on another, but both will look the same.

hmm.

Kauhiz said:

I'll be amazed if you manage to get the fps below 50 on any reasonable system rendering any reasonable effects .

hehe, i'd be suprised too :). but you never know what might happen..

Kauhiz said:

Is it possible to use google or wikipedia or something?

yes it is.. good idea. - -

kikabo said:

You could always add something like this :-

while(! Game::Over() )
{
   dt = Timing::get_dt();

   while(dt > MAX_DT)
   {
      Game::Logic(MAX_DT);
      dt -= MAX_DT;
   }

   Game::Logic(dt);
   Game::Draw();
}

Evert said:

Not really. If you don't know what integration is, I'm not going to be able to explain it in a way that makes it clear in a few words. You'll need to read a mathematics text book for that. As I said, don't concern yourself with that; if you do run into problems, then would be teh time to remember and look these things up.

ok. i'll do that.

thanks! :)

Audric
Member #907
January 2001

The one time I had jittery graphics, I finally realized it was because of a AC DC power suppy which was too close to the back of the monitor...

Kauhiz
Member #4,798
July 2004

Albin Engström said:

hmm.

I'll give you one more example. Suppose you're running your logic at 100 loops/s. This will mean that the delay between loops is roughly 0.01 s.

Now, when you do this with delta timing, you don't limit the logic. For clarity, let's say you're measuring delta time in seconds. If your logic runs 100 times per second, delta time would be 0.01 s. That means you multiply stuff by 0.01.

Then, on another machine, your logic runs 1000 loops/s. Now, the delta time will obviously be 0.001 s. So now you multiply by 0.001.

0.01 * 100 == 0.001 * 1000. So it doesn't matter how fast the game is running, it'll look the same.

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

 1   2   3   4 


Go to: