Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Any advice on flickering lines?

Author
Message
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Jun 2015 18:38
The code below is liable to cause an epileptic fit. It's just a few lines moving, but the flickering is unbearable. It's simply a few lines converted to sprites and moved around.

I have added SetSpriteSnap() and put all sprites on different layers. I have also added a lighter grey edge to the main white lines to suppress them a little. But it's still too bad to use.

Any ideas?



Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Jun 2015 19:44 Edited at: 13th Jun 2015 19:46
Another weird thing. I can only draw white lines even if I specify a colour like green. This line should draw green, but used in the code above it is still white.



[EDIT] My bad, this colour issue was my fault. But the flickering is still an issue.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 13th Jun 2015 20:59
Try this edit, works for me, I don't see any flashing.



Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 14th Jun 2015 12:05
Strange things are afoot!

I tried BatVinks code and couldn't see any flickering at all. Everything was very smooth. So I tried MoonDogs to see if the smooth looked smoother but Moondogs code does flicker on my machine.

I can only assume there is witchcraft involved and this code should be burned at the stake immediately!

AGK V2 user - Tier 1 (mostly)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 14th Jun 2015 14:55 Edited at: 14th Jun 2015 14:55
In BatVink's original code, adding:



before createBackImages() stops the flicker (on my machine at least - with Nividia GTX 460).

V2 T1 (Mostly)
Uzmadesign
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th Jun 2015 17:27 Edited at: 14th Jun 2015 17:28
Thanks, both replies fix my problem. I feared that this was an unsolvable problem with single-pixel lines.

The strange this is that it works the opposite way than described:

Quote: "nearest (0) tends to be sharper, but may flicker as it changes pixel choice."


---

Quote: "So I tried MoonDogs to see if the smooth looked smoother but Moondogs code does flicker on my machine."


Bizarre. Yours is doing what the documentation says it should do. I'm on 2.0.14, which version are you using?

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 14th Jun 2015 17:55
2.0.13

Perhaps Paul inadvertently switched a setting in the latest update?

AGK V2 user - Tier 1 (mostly)
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 14th Jun 2015 21:42
I'm pretty sure it's how AppGameKit or OpenGL renders the image. I've found through tests that by default, AGK/OGL tries to add a very bad AA effect to lower resolution images. So whenever I want something to look crisp and clean looking I'll disable the Mag Filter, which seems to always work. That was my first thought before I even looked at the code.

I've also discovered that if you don't disable the Mag filter, graphics tend to be drastically different across platforms. My phone renders graphics very well, they look better than when I created them! But when compared to running the same program on my pc, they look like butt. It's so weird.

I think the next thing you could try is making an image of a white pixel but slightly larger, something like 32x32, maybe add falloff edges and a transparent backdrop. Than once it's loaded you scale it down and get rid of the Mag Filter. That's what I would do.

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 15th Jun 2015 19:30
Be careful with trying to draw adjacent lines with DrawLine using +1 and -1, since those are in virtual resolution coordinates (1024,768) whilst the image is in pixel coordinates (1024x1024). So drawing a line at +1 in the Y direction may not put it on an adjacent pixel in the image.

Since 768/1024=0.75 drawing at +0.75 and -0.75 in virtual coordinates would put it on an adjacent pixel in the image resolution, the following seems to greatly reduce the flicker for me


And to eliminate it completely I would try reducing the image size so it is equal to or smaller than the virtual resolution (remembering to adjust the DrawLine coordinates appropriately)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 16th Jun 2015 10:47
Thanks Paul, that's a nice explanation, the help files confused me somewhat on this topic.

Quote: "I would try reducing the image size so it is equal to or smaller than the virtual resolution"

I can't do that in this case, because I also rotate the sprites and would get blank areas in the corners.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Login to post a reply

Server time is: 2024-04-30 13:42:17
Your offset time is: 2024-04-30 13:42:17