Example usage for com.badlogic.gdx.graphics.glutils ShapeRenderer ShapeRenderer

List of usage examples for com.badlogic.gdx.graphics.glutils ShapeRenderer ShapeRenderer

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.glutils ShapeRenderer ShapeRenderer.

Prototype

public ShapeRenderer() 

Source Link

Usage

From source file:org.ah.gcc.rover.desktop.DesktopGCCRoverController.java

License:Open Source License

@Override
public void create() {
    // platformSpecific.init();

    String fontName = "fonts/din-alternate-bold-64.fnt";
    if (Gdx.graphics.getWidth() <= 320) {
        fontName = "fonts/din-alternate-bold-15.fnt";
    }//from   w w  w. j a v a 2s . co  m

    font = new BitmapFont(Gdx.files.internal(fontName), true);
    glyphLayout = new GlyphLayout();

    font.setColor(Color.BLACK);
    batch = new SpriteBatch();
    img = new Texture("badlogic.jpg");

    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    cellSize = Gdx.graphics.getWidth() / 20;

    shapeRenderer = new ShapeRenderer();

    leftjoystick = new JoyStick((int) cellSize * 8, (int) cellSize * 4, (int) cellSize * 4);
    rightjoystick = new JoyStick((int) cellSize * 8, (int) cellSize * 16, (int) cellSize * 4);

    leftExpo = new ExpoGraph((int) cellSize * 5, (int) cellSize * 2, (int) cellSize * 2, (int) cellSize * 2);
    rightExpo = new ExpoGraph((int) cellSize * 13, (int) cellSize * 2, (int) cellSize * 2, (int) cellSize * 2);

    leftExpo.setPercentage(0.75f);
    rightExpo.setPercentage(0.90f);

    roverSelectButton = new Button((int) cellSize * 6, 0, (int) cellSize * 8, (int) (cellSize * 1.5),
            new Button.ButtonCallback() {
                @Override
                public void invoke(boolean state) {
                    if (state) {
                        int selectedRover = roverDriver.getSelectedRover().getValue() + 1;
                        if (selectedRover >= RoverHandler.ROVERS.length) {
                            selectedRover = 0;
                        }
                        roverDriver.getSelectedRover().setValue(selectedRover);
                    }
                }
            });

    pov = new POV((int) cellSize * 9, (int) cellSize * 4, (int) cellSize * 2);

    button1 = new RoundButton((int) cellSize * 6, (int) cellSize * 11, (int) cellSize / 2);

    switchLT = new SquareButton((int) cellSize * 0, (int) (cellSize * 0), (int) cellSize * 4,
            (int) cellSize * 2);
    switchLT.setState(false);
    switchLB = new Switch((int) cellSize * 0, (int) (cellSize * 2), (int) cellSize * 2, Orientation.HORIZONTAL);
    switchLB.setState(false);

    switchRT = new SquareButton((int) cellSize * 16, (int) (cellSize * 0), (int) cellSize * 4,
            (int) cellSize * 2);
    switchRT.setState(false);
    switchRB = new Switch((int) cellSize * 16, (int) (cellSize * 2), (int) cellSize * 2,
            Orientation.HORIZONTAL);
    switchRB.setState(false);

    inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.addProcessor(this);
    inputMultiplexer.addProcessor(new GestureDetector(this));
    Gdx.input.setInputProcessor(inputMultiplexer);

    screenController = new ScreenController();
    realController = platformSpecific.getRealController();

    screenController.setLeftJotstick(leftjoystick);
    screenController.setRightJotstick(rightjoystick);
    screenController.setHat(pov);
    screenController.setButton(switchLB, ControllerState.ButtonType.ORBIT_BUTTON);
    screenController.setButton(switchRB, ControllerState.ButtonType.LOCK_AXIS_BUTTON);
    screenController.setButton(switchLT, ControllerState.ButtonType.BOOST_BUTTON);
    screenController.setButton(switchRT, ControllerState.ButtonType.KICK_BUTTON);
    screenController.setButton(roverSelectButton, ControllerState.ButtonType.SELECT_BUTTON);

    if (realController != null) {
        comboController = new ComboController(screenController, realController);
        roverDriver = new RoverDriver(roverHandler, comboController);
    } else {
        roverDriver = new RoverDriver(roverHandler, screenController);
    }

    roverDriver.getLeftJoystick().addListener(new JoystickComponentListener() {
        @Override
        public void changed(JoystickState state) {
            leftjoystick.setValues(state.getX(), state.getY());
        }
    });

    roverDriver.getRightJoystick().addListener(new JoystickComponentListener() {
        @Override
        public void changed(JoystickState state) {
            rightjoystick.setValues(state.getX(), state.getY());
        }
    });

    roverDriver.getRoverSpeedValue().addListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            roverSpeed = evt.getNewValue().toString();
        }
    });

    roverDriver.getReadDistanceValue().addListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            roverTurningDistance = evt.getNewValue().toString();
        }
    });

    logoDrawer = new LogoDrawer(batch, camera);

    Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888);
    //Cursor customCursor = Gdx.graphics.newCursor(pixmap, 0, 0);
    //Gdx.graphics.setCursor(customCursor);
}

From source file:org.ah.gcc.rover.RoverController.java

License:Open Source License

@Override
public void create() {
    // platformSpecific.init();

    font = new BitmapFont(Gdx.files.internal("fonts/din-alternate-bold-64.fnt"), true);
    glyphLayout = new GlyphLayout();

    font.setColor(Color.BLACK);//from www . j a  v a 2s  .c om
    batch = new SpriteBatch();
    img = new Texture("badlogic.jpg");

    gccimg = new Texture("GCCLogo.png");
    creativesphereimg = new Texture("creative-sphere.png");
    bobimg = new Texture("bobclub.png");

    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    cellSize = Gdx.graphics.getWidth() / 20;

    shapeRenderer = new ShapeRenderer();

    leftjoystick = new JoyStick((int) cellSize * 8, (int) cellSize * 4, (int) cellSize * 4);
    rightjoystick = new JoyStick((int) cellSize * 8, (int) cellSize * 16, (int) cellSize * 4);

    leftExpo = new ExpoGraph((int) cellSize * 8, (int) cellSize * 2, (int) cellSize * 2, (int) cellSize * 2);
    rightExpo = new ExpoGraph((int) cellSize * 10, (int) cellSize * 2, (int) cellSize * 2, (int) cellSize * 2);

    leftExpo.setPercentage(0.75f);
    rightExpo.setPercentage(0.90f);

    roverSelectButton = new Button((int) cellSize * 6, 0, (int) cellSize * 8, (int) (cellSize * 1.5),
            new Button.ButtonCallback() {
                @Override
                public void invoke(boolean state) {
                    if (state) {
                        newSelectedRover = selectedRover + 1;
                        if (newSelectedRover >= ROVERS.length) {
                            newSelectedRover = 0;
                        }
                    }
                }
            });

    button1 = new RoundButton((int) cellSize * 6, (int) cellSize * 11, (int) cellSize / 2);

    switchLT = new Switch((int) cellSize * 0, (int) (cellSize * 1), (int) cellSize * 4, Orientation.HORIZONTAL);
    switchLT.setState(true);
    switchLB = new Switch((int) cellSize * 0, (int) (cellSize * 3), (int) cellSize * 4, Orientation.HORIZONTAL);
    switchLB.setState(true);
    switch2 = new Switch((int) cellSize * 13, (int) cellSize, (int) cellSize * 2, Orientation.VERTICAL);

    inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.addProcessor(this);
    inputMultiplexer.addProcessor(new GestureDetector(this));
    Gdx.input.setInputProcessor(inputMultiplexer);

    screenController = new ScreenController();
    screenController.setLeftJotstick(leftjoystick);
    screenController.setRightJotstick(rightjoystick);
}

From source file:org.ams.prettypaint.PrettyPolygonBatch.java

License:Open Source License

private void doAllDebugDrawing() {
    if (debugRendererArray.size == 0)
        return;/*from   w  w  w .j  ava 2 s . c  om*/

    if (shapeRenderer == null) {
        shapeRenderer = new ShapeRenderer();
        shapeRenderer.setAutoShapeType(true);
    }

    if (debugSpriteBatch == null) {
        debugSpriteBatch = new SpriteBatch();
    }

    if (debugFont == null) {
        debugFont = new BitmapFont();
    }

    if (debugCamera == null) {
        debugCamera = new OrthographicCamera();
    }

    shapeRenderer.begin();

    // draw the debug stuff
    shapeRenderer.setProjectionMatrix(worldView);
    long now = System.currentTimeMillis();
    for (int i = debugRendererArray.size - 1; i >= 0; i--) {
        DebugRenderer debugRenderer = debugRendererArray.items[i];

        debugRenderer.draw(shapeRenderer);

        // if it is more than one second since the last time
        // the owner of this debugRenderer did any normal drawing
        // then we stop the debug rendering of it

        if (debugRenderer.owner != null && debugRenderer.owner.getTimeOfLastDrawCall() + 1000 < now) {
            debugRendererArray.removeIndex(i);
        }
    }

    // draw short colored lines that will be beside some text explaining what the color of the line means
    debugCamera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    debugCamera.position.set(Gdx.graphics.getWidth() * 0.5f, Gdx.graphics.getHeight() * -0.5f + 10,
            debugCamera.position.z);

    debugCamera.update();
    shapeRenderer.setProjectionMatrix(debugCamera.combined);

    debugColorsTaken.clear();

    float verticalSpacing = 20;

    int n = 0;
    for (DebugRenderer debugRenderer : debugRendererArray) {
        Array<DebugRenderer.DebugColor> colors = debugRenderer.getDebugColors();

        for (DebugRenderer.DebugColor debugColor : colors) {
            if (debugColorsTaken.contains(debugColor.color, false))
                continue;
            debugColorsTaken.add(debugColor.color);

            float y = n++ * -verticalSpacing - 5;
            shapeRenderer.setColor(debugColor.color);
            shapeRenderer.line(10, y, 25, y);
        }
    }

    shapeRenderer.end();

    debugSpriteBatch.begin();
    debugSpriteBatch.setProjectionMatrix(debugCamera.combined);

    // draw explanatory text
    n = 0;
    for (DebugRenderer debugRenderer : debugRendererArray) {
        Array<DebugRenderer.DebugColor> colors = debugRenderer.getDebugColors();

        for (DebugRenderer.DebugColor debugColor : colors) {
            if (!debugColorsTaken.contains(debugColor.color, true))
                continue;

            drawText(debugColor.charSequence, 30, n++ * -verticalSpacing);
        }
    }

    debugSpriteBatch.end();

}

From source file:org.ams.testapps.paintandphysics.cardhouse.CardHouse.java

License:Open Source License

/**
 * Use this method to create a new card house from another {@link ApplicationAdapter}.
 *
 * @param inputMultiplexer {@link InputProcessor}'s will be added.
 *                         They are removed again when {@link #dispose()} is called.
 * @param tips             Use the same tips for several classes to avoid several appearing at the same time.
 * @param def              Settings and possibly some saved cards.
 *///from  w  w w . jav a 2  s .co m
public void create(InputMultiplexer inputMultiplexer, Tips tips, CardHouseDef def) {
    if (debug)
        debug("Creating application.");

    this.cardHouseDef = def;
    this.tips = tips;

    timer = new Timer();

    // setup camera
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera(10, 10 * (h / w));
    cameraNavigator = new CameraNavigator(camera);

    //
    polygonBatch = new PrettyPolygonBatch();
    shapeRenderer = new ShapeRenderer();
    shapeRenderer.setAutoShapeType(true);

    // create world
    world = new PPWorld();
    createJointAnchor();
    groundTexture = new TextureRegion(new Texture(cardHouseDef.groundTexture));
    addGround(groundTexture, def.groundWidth);

    //
    cardMover = createCardMover(def);

    // prepare refill card
    refillCard = createRefillCard();
    timer.runAfterNRender(new Runnable() {
        @Override
        public void run() {
            refillCard.setVisible(true);
        }
    }, 3);
    refillCardClickListener = createRefillCardClickListener(refillCard);

    // prepare input
    this.inputMultiplexer = inputMultiplexer;
    inputMultiplexer.addProcessor(refillCardClickListener);
    inputMultiplexer.addProcessor(cardMover);
    inputMultiplexer.addProcessor(cameraNavigator);

    // prepare colored cards updates
    CardMover.CardMoverListener cardMoverListener = new CardMover.CardMoverListener() {

        @Override
        public void removed(PPPolygon card) {
            coloredCards.removeValue(card, true);
        }

        @Override
        public void added(PPPolygon card) {
            coloredCards.add(card);
        }
    };
    cardMover.addCardListener(cardMoverListener);

    // possibly load some cards
    if (independentApplication) {
        for (int i = 0; i < 10; i++) {
            addCard(i / 3f, 0);
        }
    }
    if (def.asJson != null) {
        loadGame(def.asJson);
    }

    positionCamera();
}

From source file:org.ams.testapps.paintandphysics.cardhouse.CardHouse.java

License:Open Source License

/** Whether to draw the touches. For debugging. */
public void setDrawTouch(boolean drawTouch) {
    this.drawTouch = drawTouch;

    // remove old stuff
    inputMultiplexer.removeProcessor(touchListener);

    if (drawTouch) {
        if (shapeRenderer == null) {
            shapeRenderer = new ShapeRenderer();
            shapeRenderer.setAutoShapeType(true);
        }/*  w  w  w  .  j  a  v a2 s  .  c o  m*/

        // listener for moving the circle
        touchListener = new InputAdapter() {
            void updateSizeAndPos(int screenX, int screenY) {
                touchPos.set(CoordinateHelper.getWorldCoordinates(camera, screenX, screenY));

                touchRadius = Util.getTouchRadius(camera.zoom);

            }

            @Override
            public boolean touchDown(int screenX, int screenY, int pointer, int button) {
                updateSizeAndPos(screenX, screenY);
                return false;
            }

            @Override
            public boolean touchDragged(int screenX, int screenY, int pointer) {
                updateSizeAndPos(screenX, screenY);
                return false;
            }

        };

        inputMultiplexer.addProcessor(0, touchListener);
    }
}

From source file:org.ams.testapps.paintandphysics.physicspuzzle.PhysicsPuzzle.java

License:Open Source License

/**
 * Use this to run the puzzle from another {@link ApplicationAdapter}.
 * <p/>/*from w  w w  . j  ava  2 s  . c  om*/
 * Remember to dispose of the atlas when you no longer use it.
 *
 * @param inputMultiplexer InputProcessors will be added to the end of the multiplexer
 * @param textureRegion    The region to draw on the puzzle.
 * @param def              defines this particular game
 */
public void create(InputMultiplexer inputMultiplexer, TextureRegion textureRegion, PhysicsPuzzleDef def,
        Callback gameOverCallback) {
    if (textureRegion == null)
        throw new IllegalArgumentException("TextureRegion is null.");
    if (def == null)
        throw new IllegalArgumentException("PhysicsPuzzleDef is null.");

    this.gameOverCallback = gameOverCallback;

    // camera stuff
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera(10, 10 * (h / w));

    cameraNavigator = new CameraNavigator(camera);
    cameraNavigator.setActive(false);

    // physics
    world = new PPWorld();
    bodyMover = new BodyMover(world.boxWorld, camera);

    // batches for drawing
    polygonBatch = new PrettyPolygonBatch();
    shapeRenderer = new ShapeRenderer();
    shapeRenderer.setAutoShapeType(true);

    // input multiplexing
    if (inputMultiplexer == null) {
        inputMultiplexer = new InputMultiplexer();
        Gdx.input.setInputProcessor(inputMultiplexer);
    }
    this.inputMultiplexer = inputMultiplexer;
    inputMultiplexer.addProcessor(bodyMover);
    inputMultiplexer.addProcessor(cameraNavigator);

    initFromDefinition(textureRegion, def);

    lookAtPuzzle();

}

From source file:org.ams.testapps.prettypaint.TextureAlignmentTest2.java

License:Open Source License

@Override
public void create() {
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    // prepare camera and camera controls
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera(10, 10 * (h / w));
    cameraNavigator = new CameraNavigator(camera);
    Gdx.input.setInputProcessor(cameraNavigator);

    polygonBatch = new PrettyPolygonBatch();

    // load textures
    texture = new Texture("images/puzzles/stockvault-cow131648.jpg");
    textureAtlas = new TextureAtlas("images/packed/packed.atlas");
    testTextureRegions = new Array<TextureRegion>();
    testTextureRegions.add(new TextureRegion(texture));
    for (TextureRegion textureRegion : textureAtlas.getRegions()) {
        testTextureRegions.add(textureRegion);
    }//from  w  w w  . ja  v  a 2  s.c o  m

    // prepare TexturePolygons
    Array<Vector2> vertices = new Array<Vector2>();
    vertices.add(new Vector2(0, 0));
    vertices.add(new Vector2(2, 0));
    vertices.add(new Vector2(2, 2));
    vertices.add(new Vector2(0, 2));
    Util.translateSoCentroidIsAtOrigin(vertices);

    texturePolygon = new TexturePolygon();
    texturePolygon.setVertices(vertices);
    texturePolygon.setTextureRegion(new TextureRegion(texture));

    shapeRenderer = new ShapeRenderer();
    shapeRenderer.setAutoShapeType(true);

}

From source file:org.bladecoder.bladeengine.ui.SceneScreen.java

License:Apache License

private void retrieveAssets(TextureAtlas atlas) {
    renderer = new ShapeRenderer();
    pie.retrieveAssets(atlas);// www  .j ava 2 s .  c  o  m
    inventoryUI.retrieveAssets(atlas);
    textManagerUI.retrieveAssets(atlas);
}

From source file:org.catrobat.catroid.stage.StageListener.java

License:Open Source License

@Override
public void create() {
    font = new BitmapFont();
    font.setColor(1f, 0f, 0.05f, 1f);/*www  .  j a v a2  s.  c  o m*/
    font.getData().setScale(1.2f);
    deltaActionTimeDivisor = 10f;

    shapeRenderer = new ShapeRenderer();

    project = ProjectManager.getInstance().getCurrentProject();
    scene = ProjectManager.getInstance().getSceneToPlay();
    pathForSceneScreenshot = Utils.buildScenePath(project.getName(), scene.getName()) + "/";

    virtualWidth = project.getXmlHeader().virtualScreenWidth;
    virtualHeight = project.getXmlHeader().virtualScreenHeight;

    virtualWidthHalf = virtualWidth / 2;
    virtualHeightHalf = virtualHeight / 2;

    camera = new OrthographicCamera();
    viewPort = new ExtendViewport(virtualWidth, virtualHeight, camera);
    if (batch == null) {
        batch = new SpriteBatch();
    } else {
        batch = new SpriteBatch(1000, batch.getShader());
    }
    stage = new Stage(viewPort, batch);
    initScreenMode();
    initStageInputListener();

    physicsWorld = scene.resetPhysicsWorld();

    clonedSprites = new HashSet<>();
    sprites = new ArrayList<>(scene.getSpriteList());
    boolean addPenActor = true;
    for (Sprite sprite : sprites) {
        sprite.resetSprite();
        sprite.look.createBrightnessContrastHueShader();
        stage.addActor(sprite.look);
        if (addPenActor) {
            penActor = new PenActor();
            stage.addActor(penActor);
            addPenActor = false;
        }
    }
    passepartout = new Passepartout(ScreenValues.SCREEN_WIDTH, ScreenValues.SCREEN_HEIGHT,
            maximizeViewPortWidth, maximizeViewPortHeight, virtualWidth, virtualHeight);
    stage.addActor(passepartout);

    if (DEBUG) {
        OrthoCamController camController = new OrthoCamController(camera);
        InputMultiplexer multiplexer = new InputMultiplexer();
        multiplexer.addProcessor(camController);
        multiplexer.addProcessor(stage);
        Gdx.input.setInputProcessor(multiplexer);
        fpsLogger = new FPSLogger();
    } else {
        Gdx.input.setInputProcessor(stage);
    }
    axes = new Texture(Gdx.files.internal("stage/red_pixel.bmp"));
    skipFirstFrameForAutomaticScreenshot = true;
    if (checkIfAutomaticScreenshotShouldBeTaken) {
        makeAutomaticScreenshot = project.manualScreenshotExists(SCREENSHOT_MANUAL_FILE_NAME)
                || scene.screenshotExists(SCREENSHOT_AUTOMATIC_FILE_NAME)
                || scene.screenshotExists(SCREENSHOT_MANUAL_FILE_NAME);
    }
    if (drawDebugCollisionPolygons) {
        collisionPolygonDebugRenderer.setProjectionMatrix(camera.combined);
        collisionPolygonDebugRenderer.setAutoShapeType(true);
        collisionPolygonDebugRenderer.setColor(Color.MAGENTA);
    }
}

From source file:org.catrobat.catroid.stage.StageListener.java

License:Open Source License

private void initStageInputListener() {

    if (inputListener == null) {
        inputListener = new InputListener() {
            @Override/*w  ww .  ja  va2s . c o m*/
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                TouchUtil.touchDown(event.getStageX(), event.getStageY(), pointer);
                return true;
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                TouchUtil.touchUp(pointer);
            }

            @Override
            public void touchDragged(InputEvent event, float x, float y, int pointer) {
                TouchUtil.updatePosition(event.getStageX(), event.getStageY(), pointer);
            }
        };
    }
    stage.addListener(inputListener);
    collisionPolygonDebugRenderer = new ShapeRenderer();
}