Search code examples
javaopenglgraphicslibgdxtextures

LibGdx weird texture behaviour


So I am trying to render a sprite with this texture:

How it is supposed to look

However, it renders like this:

How it actually looks

In the original texture, every line has a width of 1px. In the rendered texture,the top line seems to have dissapeared from the top and moved to the bottom effectively forming a 2px line. The texture is loaded from a single file, not a sheet.

I have disabled/enabled texture filtering, it did not help.

I have made sure the camera is not zoomed in or out.

I have made sure the texture is not scaled in any way.

I haven't specified any wrap for the texture.

Any ideas as to what may be causing this?


Solution

  • I figured it out!

    Seems that this occurs when trying to draw the texture at position with decimals (in my case it was x=580.5), to fix it I had to use Math.round() to ensure that it was a full number.

    I thought that LibGdx and/or opengl was capable of rendering with subpixel precision. Weird.