Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Graphic issue with vertical / horizontal lines  (Read 6638 times)

0 Members and 1 Guest are viewing this topic.

Joki

  • Newbie
  • *
  • Posts: 15
    • View Profile
Graphic issue with vertical / horizontal lines
« on: July 08, 2014, 07:29:53 pm »
Hello everyone. I am currently on working a small game using the SFML .NET V2.1 bindings and i am encountering some kind of graphic glitch on some machines.

This is what the game currently looks on my desktop:



I have sent someone a copy to try it out on another machine, this is what the game looks for him:







Edit: Added this shot. Vertical line right beside the player sprite and horizontal line above the whole image.



Old Version:



Notice the vertical lines.

I tried rounding down object coordinates to int of my tiles before drawing, various graphic settings including anti-aliasing (makes it a LOT worse), texture filtering (i love the current pixelated look), vsync and what not.

I encountered a similiar issue when creating the initial version of this game, using the slick library for java, before i moved to start over using .NET. Last time i fixed it, by using only floats during all calculations and finally truncating all images to int's immediatly when drawing them.

Does anyone have a suggestion, that i could try?
« Last Edit: July 08, 2014, 07:39:34 pm by Joki »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Joki

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Graphic issue with vertical / horizontal lines
« Reply #2 on: July 08, 2014, 09:48:47 pm »
Hello Nexus. Thanks for your fast reply.

After reading throu about 8 or 9 topics regarding this issue, i found the most promising suggestion to

1.
Keep using floats for all object positions and before drawing anything, round it, then add +0.375f to its position

2.
Another popular solution seemed to be, to instead of using IntRects for the texture location, use the FloatRect with GL texture coordinates 0.0 - 1.0 and substract 0.5 / subrect size from bottom right corner. e.g. if i am using a texture atlas containing 8x8 artwork, it was suggested to use 1.0 - 0.0625 = 0.9375 at the bottom right corner of the texture float rect

Unfortunately using the 1st suggestion does not seem to help.
I tried "round positions" and "round view, add 0.375, 0.375" to the view, no difference, and then
"round positions, add 0.375, 0.375" to all positions and the view, still no change.

Trying the 2nd approach i tried instead using a different texture rect. Unfortunately using the .NET version of SFML does not seem to provide an ctor overload to use FloatRect for the Texture coordinates. In another post from you (see here) i have read that you use gl translate just on all the drawables (but not on the view?). Unless i additionally use Tao or OpenTk there seems to be no way to directly use OpenGL.

Or translating the Drawable by 0.375, 0.375 already done in the external c lib, so i am doing it twice now actually?

Hmm.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Graphic issue with vertical / horizontal lines
« Reply #3 on: July 08, 2014, 10:22:56 pm »
Quote
Unfortunately using the .NET version of SFML does not seem to provide an ctor overload to use FloatRect for the Texture coordinates

Neither does the core SFML.
http://sfml-dev.org/documentation/2.1/classsf_1_1Sprite.php#a3fefec419a4e6a90c0fd54c793d82ec2

Quote
Or translating the Drawable by 0.375, 0.375 already done in the external c lib, so i am doing it twice now actually?

This is not done by SFML, either in CSFML or the core SFML.

Quote
Unless i additionally use Tao or OpenTk there seems to be no way to directly use OpenGL.

If you want to use OpenGL this is how it is done. Its about as direct as you can get.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Joki

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Graphic issue with vertical / horizontal lines
« Reply #4 on: July 09, 2014, 08:44:12 pm »
Hi zsbzsb. Thanks for your reply.

I think i tried almost all tricks now, been on this for ages. Now i am doing the following before drawing:

- Position of the player is rounded. (I should remove this, since the position of the camera, that is centered around the player, is also rounded before drawing)
- Center of the view is set rounded(player position + half its size).
- Positions of all entities (mobs, tiles) are rounded, then vec2f (0.375, 0.375) is added to their position.
  Since those are drawn relative to the camera, they should have 0.375 offset.

This is pixel perfect, as long as i don't zoom in/out.

For zooming, i dont like use Zoom() as this zooms in/out relative to the currenct zoom level. E.g., if i zoom using Zoom(0.96f) i'd have to undo it setting Zoom(1/0.96f) which can not be represented as float (with finite mantisse :)) without introducing rounding error.

Instead of zooming from the default view, i am just setting the Size of the View. I am using a tweening lib for a smooth QuadInOut effect, and - again - rounding the Size vec. So all the entity boundaries should hit x.375, y.375 relative to the camera.

Still the issue consists.

Where do i go wrong with the zooming?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Graphic issue with vertical / horizontal lines
« Reply #5 on: July 09, 2014, 10:08:02 pm »
I thought the offset required was (0.5, 0.5)...  ???

As for the zooming, have you tried it without your "tweening" library?

Does it work with the zoom function? Even though this isn't the method you don't want to use, it might be useful to know if it also causes the problems.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Graphic issue with vertical / horizontal lines
« Reply #6 on: July 09, 2014, 10:29:39 pm »
First, this 0.375 offset was an OpenGL-related fix that concerned a very old SFML version. That post was from 2009, which is half a decade ago. Don't expect any positive effects if you apply it today, SFML should handle those cases fine...

Second, have you read the link to my commit in the other post? You need to make sure that not only position, but also origin (not center!), scale and rotation are set correctly if you want pixel-perfect rendering.

Third, you should come up with a minimal complete example to reproduce the problem. It is very likely that somewhere in the depths of your code, you overlook a transform. On the other hand, if it's really SFML's fault, we need a minimal code anyway.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Joki

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Graphic issue with vertical / horizontal lines
« Reply #7 on: July 10, 2014, 10:05:03 pm »
Quote
First, this 0.375 offset was an OpenGL-related fix that concerned a very old SFML version. That post was from 2009, which is half a decade ago.

It doesn't automatically mean, it is fixed now, does it? :)

Thanks for the additional link to the link to that commit. I have removed the +0.375, +0.375 offset and are now just truncating everything.

EDIT: I forgot to mention: The problem still consists!  :D

public void DrawState()
{
        if (window.IsOpen())
        {
                window.DispatchEvents();
                window.Clear(clearColor);

                // draw map + player
                zoomableView.Center = new Vector2f(
                        (int)(player.Position.X + (Config.PlayerSize.X >> 1)),
                        (int)(player.Position.Y + (Config.PlayerSize.Y >> 1)));

                GfxUtils.CheckValid(zoomableView);
                window.SetView(zoomableView);
                EntityManager.Instance.Draw(window, rs);
                window.SetView(window.DefaultView);

                window.Display();
        }
}

// called before drawing every entity (mob, player, tile)
public static void CheckValid(Transformable t)
{
        bool isValid = t.Position.X == (int)t.Position.X;
        isValid &= t.Position.Y == (int)t.Position.Y;
        isValid &= t.Origin.X == (int)t.Origin.X;
        isValid &= t.Origin.Y == (int)t.Origin.Y;
        isValid &= t.Scale.X == (int)t.Scale.X;
        isValid &= t.Scale.Y == (int)t.Scale.Y;
        isValid &= t.Rotation == (int)t.Rotation;
        isValid &= (int)t.Rotation % 90 == 0;
        if (!isValid)
        {
                Program.Logger.Error(new InvalidOperationException(t.ToString()));
                System.Diagnostics.Debugger.Break();
        }
}

// called before drawing any view
public static void CheckValid(View v)
{
        bool isValid = v.Center.X == (int)v.Center.X;
        isValid &= v.Center.Y == (int)v.Center.Y;
        isValid &= v.Rotation == (int)v.Rotation;
        isValid &= v.Rotation % 90f == 0;
        isValid &= v.Size.X == (int)v.Size.X;
        isValid &= v.Viewport.TopLeft.X == (int)v.Viewport.TopLeft.X;
        isValid &= v.Viewport.TopLeft.Y == (int)v.Viewport.TopLeft.Y;
        isValid &= v.Viewport.TopRight.X == (int)v.Viewport.TopRight.X;
        isValid &= v.Viewport.TopRight.Y == (int)v.Viewport.TopRight.Y;
        isValid &= v.Viewport.BottomLeft.X == (int)v.Viewport.BottomLeft.X;
        isValid &= v.Viewport.BottomLeft.Y == (int)v.Viewport.BottomLeft.Y;
        isValid &= v.Viewport.BottomRight.X == (int)v.Viewport.BottomRight.X;
        isValid &= v.Viewport.BottomRight.Y == (int)v.Viewport.BottomRight.Y;
        if (!isValid)
        {
                Program.Logger.Error(new InvalidOperationException(v.ToString()));
                System.Diagnostics.Debugger.Break();
        }
}
 
« Last Edit: July 12, 2014, 10:39:20 am by Joki »