Libgdx book and texture gaps?

I started working through the book Learning Libgdx Game Development and I am wondering if anyone else is currently working or has already finished working through it.

Following the code in the book exactly and compiling the code downloaded that goes with the book, I get small 1-2 pixel gaps between left/right and middle rock graphics and sprites. The problem can be seen here: http://postimg.org/image/rfjdqzund/

This is the code for the rock rendering. I can make the pixel gaps go away by adjusting relX by -0.01f for the left side, 0.01f for the right side and instead of adding + dimension.x for the middle, add dimension.x - 0.01f. I’m not pleased with that solution. I prefer to not use magic numbers and know what’s really going on and how I can fix it.


    public void render(SpriteBatch batch)
    {
        TextureRegion reg = null;
        float relX = 0;
        float relY = 0;
        
        // draw left edge
        reg = regEdge;
        relX -= dimension.x / 4;
        batch.draw(reg.getTexture(),
                   position.x + relX, position.y + relY,
                   origin.x, origin.y,
                   dimension.x/4, dimension.y,
                   scale.x, scale.y,
                   rotation,
                   reg.getRegionX(), reg.getRegionY(),
                   reg.getRegionWidth(), reg.getRegionHeight(),
                   false, false);
        
        // draw middle
        relX = 0;
        reg = regMiddle;
        for (int i = 0; i < length; i++)
        {
            batch.draw(reg.getTexture(),
                       position.x + relX, position.y + relY,
                       origin.x, origin.y,
                       dimension.x, dimension.y,
                       scale.x, scale.y,
                       rotation,
                       reg.getRegionX(), reg.getRegionY(),
                       reg.getRegionWidth(), reg.getRegionHeight(),
                       false, false);
            
            relX += dimension.x;
        }
        
        // draw right side
        reg = regEdge; 
        batch.draw(reg.getTexture(),
                   position.x + relX, position.y + relY,
                   origin.x + dimension.x / 8, origin.y,
                   dimension.x/4, dimension.y,
                   scale.x, scale.y,
                   rotation,
                   reg.getRegionX(), reg.getRegionY(),
                   reg.getRegionWidth(), reg.getRegionHeight(),
                   true, false);
    }
    

Thanks!

How is Your camera setup, if at all?
What is dimension ? Viewport ?

I suspect it might be a floating point division error that manifests itself as a pixel cap.
However, I could also be very wrong.

Hi xsvenson and thanks for the help!

The only camera is this:


camera = new OrthographicCamera(5.0f, 5.0f);

View port is set/resized with:

camera.viewportWidth = (5.0f/height) * width;

Some questions:
Are you using a textureatlas?
If yes, which texturefilter are you using?
Are you using mipmapping?
Have your textures padding?

You could have a look at:
http://code.google.com/p/libgdx/issues/detail?id=1257

Thanks Phibedy,

Yes on the atlas, all of this is following the book. TexturePacker2 is the packer and the filtering applied is Linear, Linear. The default padding for the packer is 2 px on the x,y axes.

I’m checking out your links to see if I can make heads or tails of what’s going on.