Reputation: 95
I would like to draw a polygon with repeat texture (e.g brick). Here is my code:
textureBrick = new Texture(Gdx.files.internal("data/brick.png"));
textureBrick.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
TextureRegion texreg = new TextureRegion(textureBrick,0,0,1f,1f);
texreg.setTexture(textureBrick);
PolygonRegion po = new PolygonRegion(texreg, floatvertices);
and next i draw (render):
public void render(SpriteBatch spriteBatch, PolygonSpriteBatch polygonBatch) {
Gdx.gl.glEnable(GL10.GL_TEXTURE_2D);
polygonBatch.draw(po, 0,0, 512f, 256f);
}
Unfortunately, I always gets polygons filled by white colour. Why?
Upvotes: 1
Views: 2579
Reputation: 1419
You might be calling code in this order
spriteBatch.begin();
spriteBatch.draw(textureRegion, 0, 0, 480, 480);
polygonBatch.begin();
polygonBatch.draw(polygonRegion, 0,0, 400f, 400f);
polygonBatch.end();
spriteBatch.end();
Using spriteBatch,polygonBatch, shapeRenders etc together might lead to this type of problem you should use them seperately :
spriteBatch.begin();
spriteBatch.draw(textureRegion, 0, 0, 480, 480);
spriteBatch.end();
polygonBatch.begin();
polygonBatch.draw(polygonRegion, 0,0, 400f, 400f);
polygonBatch.end();
Before using begin of any other batch you should end the previous batch.
Upvotes: 3