I have 2 problems with PolygonSpriteBatch on libGDX.
1) I try to render a simple polygon (in this case a rectangle) and I only see a triangle when drawn.
Picture: http://i.snag.gy/kHV3N.jpg
texture=new TextureRegion(new Texture("texture.png"));
texture.getTexture().setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
polygonRegion=new PolygonRegion(texture,createVertices(),createIndices(createVertices()));
The polygon that i want to draw is this one
private float[] createVertices() {
float[] verts = new float[5 * 2];
int i = 0;
verts[i++] = 2;
verts[i++] = 2;
verts[i++] = 2;
verts[i++] = 3;
verts[i++] = 3;
verts[i++] = 3;
verts[i++] = 3;
verts[i++] = 2;
verts[i++] = verts[0];
verts[i++] = verts[1];
return verts;
}
private short[] createIndices(float[] vertices){
short[] indices=new short[vertices.length/2];
for(short i=0; i<vertices.length/2; i++){
indices[i]=i;
}
return indices;
}
And when I draw it
shapeRenderer.setProjectionMatrix(camera.combined);
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.polygon(createVertices());
shapeRenderer.end();
polygonSpriteBatch.setProjectionMatrix(camera.combined);
polygonSpriteBatch.begin();
polygonSpriteBatch.draw(polygonRegion, 0, 0);
polygonSpriteBatch.end();
I also draw the plain texture to see how it looks like
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(texture, 4f, 2.4f, 1f, 1f);
batch.end();
As you can see, the polygon is drawn with the shaperenderer correctly, but not well textured with the polygonspritebatch.
The second problem: Instead of the problem above, polygonspritebatch works perfectly when using a normal camera size, like 800x480. When I use a camera that is 8 x 4.8 (for box2d world) the texture is zoomed a lot ..like in the picture out there.
Any solutions?