I need to draw polygon filled with color, but i don't know how to create my texture right, for batch to draw it Here is my code
public class VisualComponent implements Component, Pool.Poolable {
public float[] vertices = new float[1];
public short[] triangles = new short[1];
@Override
public void reset() {
vertices = new float[1];
triangles = new short[1];
}
}
Here i am creating the entity which i want to be drawn
Entity source = engine.createEntity();
TransformComponent transformComponent = engine.createComponent(TransformComponent.class);
VisualComponent visualComponent = engine.createComponent(VisualComponent.class);
float redColorBits = Color.RED.toFloatBits();
visualComponent.vertices = new float[]{
0, 0, redColorBits,
10, 0, redColorBits,
10, 10, redColorBits,
0, 10, redColorBits
};
visualComponent.triangles = new short[]{
0, 1, 2,
0, 2, 3
};
source.add(transformComponent);
source.add(visualComponent);
engine.addEntity(source);
And here is the rendering system's processEntity method
@Override
protected void processEntity(Entity entity, float deltaTime) {
TransformComponent transformComponent = tcm.get(entity);
VisualComponent visualComponent = vcm.get(entity);
batch.draw(new Texture(1, 1, Pixmap.Format.RGBA8888),
visualComponent.vertices, 0, visualComponent.vertices.length,
visualComponent.triangles, 0, visualComponent.triangles.length);
}
Also I need a tip on how to correctly reuse my texture for not always recreating it. Thx