Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TutorialShaperenderer extends ApplicationAdapter {
- Vector2 centerTwo, centerOne;
- FloatArray verticesTwo, verticesOne;
- Texture texture;
- PolygonSprite polySprite;
- PolygonSpriteBatch polyBatch;
- ShapeRenderer sr;
- @Override
- public void create() {
- // 1
- sr = new ShapeRenderer();
- // 2
- polyBatch = new PolygonSpriteBatch();
- Pixmap pix = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
- pix.setColor(1, 0, 0, 1);
- pix.fill();
- texture = new Texture(pix);
- TextureRegion textureRegion = new TextureRegion(texture);
- // 1
- centerOne = new Vector2(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
- verticesOne = new FloatArray(
- new float[] { centerOne.x, centerOne.y + 50, centerOne.x + 100, centerOne.y, centerOne.x + 50,
- centerOne.y - 50, centerOne.x - 50, centerOne.y - 50, centerOne.x - 100, centerOne.y });
- // 2
- centerTwo = new Vector2(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2 - 100);
- verticesTwo = new FloatArray(
- new float[] { centerTwo.x, centerTwo.y + 50, centerTwo.x + 100, centerTwo.y, centerTwo.x + 50,
- centerTwo.y - 50, centerTwo.x - 50, centerTwo.y - 50, centerTwo.x - 100, centerTwo.y });
- EarClippingTriangulator triangulator = new EarClippingTriangulator();
- ShortArray triangleIndices = triangulator.computeTriangles(verticesTwo);
- PolygonRegion polyReg = new PolygonRegion(textureRegion, verticesTwo.toArray(), triangleIndices.toArray());
- polySprite = new PolygonSprite(polyReg);
- }
- @Override
- public void render() {
- Gdx.gl.glClearColor(0, 0, 0, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- // 2
- polyBatch.begin();
- polySprite.draw(polyBatch);
- polyBatch.end();
- // 1
- sr.begin(ShapeType.Line);
- sr.setColor(0, 1, 0, 1);
- sr.polygon(verticesOne.toArray());
- sr.end();
- }
- @Override
- public void resize(int width, int height) {
- super.resize(width, height);
- }
- @Override
- public void dispose() {
- polyBatch.dispose();
- texture.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement