Example usage for com.badlogic.gdx.controllers.mappings Ouya runningOnOuya

List of usage examples for com.badlogic.gdx.controllers.mappings Ouya runningOnOuya

Introduction

In this page you can find the example usage for com.badlogic.gdx.controllers.mappings Ouya runningOnOuya.

Prototype

boolean runningOnOuya

To view the source code for com.badlogic.gdx.controllers.mappings Ouya runningOnOuya.

Click Source Link

Document

whether the app is running on a real Ouya device

Usage

From source file:ve.ucv.ciens.ccg.nxtar.MainActivity.java

License:Apache License

/**
 * <p>Initializes this activity</p>
 * /*from  ww  w  .  ja v a 2 s .co m*/
 * <p>This method handles the initialization of LibGDX and OpenCV. OpenCV is
 * loaded the asynchronous method if the devices is not an OUYA console.</p>
 * 
 * @param savedInstanceState The application state if it was saved in a previous run.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    cameraCalibrated = false;

    // Set screen orientation. Portrait on mobile devices, landscape on OUYA.
    if (!Ouya.runningOnOuya) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }

    // Set up the Android related variables.
    uiHandler = new Handler();
    uiContext = this;
    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    // Attempt to initialize OpenCV.
    if (!Ouya.runningOnOuya) {
        // If running on a moble device, use the asynchronous method aided
        // by the OpenCV Manager app.
        loaderCallback = new BaseLoaderCallback(this) {
            @Override
            public void onManagerConnected(int status) {
                switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                    // If successfully initialized then load the native method implementations and
                    // initialize the static matrices.
                    System.loadLibrary("cvproc");
                    ocvOn = true;
                    cameraMatrix = new Mat();
                    distortionCoeffs = new Mat();
                    break;

                default:
                    Toast.makeText(uiContext, R.string.ocv_failed, Toast.LENGTH_LONG).show();
                    ocvOn = false;
                    break;
                }
            }
        };

        // Launch the asynchronous initializer.
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_7, this, loaderCallback);

    } else {
        // If running on an OUYA device.
        if (ocvOn) {
            // If OpenCV loaded successfully then initialize the native matrices.
            cameraMatrix = new Mat();
            distortionCoeffs = new Mat();
        } else {
            Toast.makeText(uiContext, R.string.ocv_failed, Toast.LENGTH_LONG).show();
        }
    }

    // Configure LibGDX.
    AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
    cfg.useAccelerometer = true;
    cfg.useCompass = true;
    cfg.useWakelock = true;

    // Launch the LibGDX core game class.
    initialize(new NxtARCore(this), cfg);
}

From source file:ve.ucv.ciens.ccg.nxtar.NxtARCore.java

License:Apache License

/**
 * <p>Initialize the member fields and launch the networking threads. Also creates and
 * sets the application states.</p>
 *///w  ww.  j av  a 2s.  c  o m
public void create() {
    try {
        ScenarioGlobals.init(this);
    } catch (IllegalArgumentException e) {
        Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal argument initializing globals: ", e);
        System.exit(1);
        return;
    } catch (InstantiationException e) {
        Gdx.app.error(TAG, CLASS_NAME + ".create(): Instantiation exception initializing globals: ", e);
        System.exit(1);
        return;
    } catch (IllegalAccessException e) {
        Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal access exception initializing globals: ", e);
        System.exit(1);
        return;
    }

    // Set up rendering fields and settings.
    batch = new SpriteBatch();
    batch.enableBlending();
    batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    ShaderProgram.pedantic = false;

    // Create the state objects.
    states = new BaseState[game_states_t.getNumStates()];

    try {
        if (Ouya.runningOnOuya)
            states[game_states_t.MAIN_MENU.getValue()] = new OuyaMainMenuState(this);
        else
            states[game_states_t.MAIN_MENU.getValue()] = new TabletMainMenuState(this);

        try {
            states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
        } catch (IllegalStateException e) {
            Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in IN_GAME_STATE: ", e);
            System.exit(1);
            return;
        }

        states[game_states_t.CALIBRATION.getValue()] = new CameraCalibrationState(this);

        try {
            states[game_states_t.AUTOMATIC_ACTION.getValue()] = new AutomaticActionState(this);
        } catch (IllegalStateException e) {
            Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal state in AUTOMATIC_ACTION_STATE: ", e);
            System.exit(1);
            return;
        }

        states[game_states_t.AUTOMATIC_ACTION_SUMMARY.getValue()] = new AutomaticActionSummaryState(this);
        states[game_states_t.SCENARIO_END_SUMMARY.getValue()] = new ScenarioEndSummaryState(this);
        states[game_states_t.HINTS.getValue()] = new InstructionsState(this);

    } catch (IllegalArgumentException e) {
        Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal argument caught creating states: ", e);
        System.exit(1);
        return;
    }

    // Register controller listeners.
    for (BaseState state : states) {
        Controllers.addListener(state);
    }

    // Set up the overlay font.
    overlayX = -(Utils.getScreenWidthWithOverscan() / 2) + 10;
    overlayY = (Utils.getScreenHeightWithOverscan() / 2) - 10;

    font = new BitmapFont();
    font.setColor(1.0f, 1.0f, 0.0f, 1.0f);
    if (!Ouya.runningOnOuya) {
        font.setScale(1.0f);
    } else {
        font.setScale(2.5f);
    }

    // Start networking.
    actionResolver.enableMulticast();

    Gdx.app.debug(TAG, CLASS_NAME + ".create() :: Creating network threads");
    serviceDiscoveryThread = ServiceDiscoveryThread.getInstance();
    videoThread = VideoStreamingThread.getInstance();
    robotThread = RobotControlThread.getInstance();
    sensorThread = SensorReportThread.getInstance();

    // Launch networking threads.
    serviceDiscoveryThread.start();

    videoThread.start();
    videoThread.startStreaming();
    videoThread.addNetworkConnectionListener(this);

    robotThread.addNetworkConnectionListener(this);
    robotThread.start();

    sensorThread.addNetworkConnectionListener(this);
    sensorThread.start();

    // Set the current and next states.
    currState = game_states_t.MAIN_MENU;
    nextState = null;
    this.setScreen(states[currState.getValue()]);
    states[currState.getValue()].onStateSet();

    // Prepare the fading effect.
    Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA4444);
    pixmap.setColor(0, 0, 0, 1);
    pixmap.fill();
    fadeTexture = new Texture(pixmap);
    pixmap.dispose();

    alpha = new MutableFloat(0.0f);
    fadeOut = Tween.to(alpha, 0, 0.5f).target(1.0f).ease(TweenEquations.easeInQuint);
    fadeIn = Tween.to(alpha, 0, 0.5f).target(0.0f).ease(TweenEquations.easeInQuint);
    fading = false;

    // Set initial input handlers.
    Gdx.input.setInputProcessor(states[currState.getValue()]);
    Controllers.addListener(states[currState.getValue()]);

    // Set log level
    if (ProjectConstants.DEBUG) {
        Gdx.app.setLogLevel(Application.LOG_DEBUG);
    } else {
        Gdx.app.setLogLevel(Application.LOG_NONE);
    }
}

From source file:ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameAutomaticActionSummaryOverlay.java

License:Apache License

public BombGameAutomaticActionSummaryOverlay() {
    FreeTypeFontGenerator fontGenerator;
    FreeTypeFontParameter fontParameters;

    inclinationBombTexture = new Texture(Gdx.files.internal("data/gfx/bomb_game/incl_bomb.png"));
    combinationBombTexture = new Texture(Gdx.files.internal("data/gfx/bomb_game/comb_bomb.png"));
    wireBombTexture = new Texture(Gdx.files.internal("data/gfx/bomb_game/wire_bomb.png"));

    inclinationBomb = new Sprite(inclinationBombTexture);
    combinationBomb = new Sprite(combinationBombTexture);
    wireBomb = new Sprite(wireBombTexture);

    inclinationBomb.setSize(inclinationBomb.getWidth() * 0.5f, inclinationBomb.getHeight() * 0.5f);
    combinationBomb.setSize(combinationBomb.getWidth() * 0.5f, combinationBomb.getHeight() * 0.5f);
    wireBomb.setSize(wireBomb.getWidth() * 0.5f, wireBomb.getHeight() * 0.5f);

    combinationBomb.setPosition(-(Utils.getScreenWidthWithOverscan() / 4.0f) - combinationBomb.getWidth(),
            -(combinationBomb.getHeight() / 2.0f));
    inclinationBomb.setPosition(-(Utils.getScreenWidthWithOverscan() / 4.0f) - inclinationBomb.getWidth(),
            combinationBomb.getY() + combinationBomb.getHeight() + 10.0f);
    wireBomb.setPosition(-(Utils.getScreenWidthWithOverscan() / 4.0f) - wireBomb.getWidth(),
            combinationBomb.getY() - wireBomb.getHeight() - 10.0f);

    fontParameters = new FreeTypeFontParameter();
    fontParameters.characters = ProjectConstants.FONT_CHARS;
    if (!Ouya.runningOnOuya)
        fontParameters.size = (int) ((float) ProjectConstants.MENU_BUTTON_FONT_SIZE
                * ((float) Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
    else//from  ww  w. j  a v a 2 s  .  c  o  m
        fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
    fontParameters.flip = false;
    fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));

    font = fontGenerator.generateFont(fontParameters);
    font.setColor(Color.YELLOW);

    fontParameters.size = (int) (90.0f * ((float) Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
    titleFont = fontGenerator.generateFont(fontParameters);

    fontGenerator.dispose();

    inclinationX = inclinationBomb.getX() + inclinationBomb.getWidth() + 15.0f;
    combinationX = combinationBomb.getX() + combinationBomb.getWidth() + 15.0f;
    wireX = wireBomb.getX() + wireBomb.getWidth() + 15.0f;

    inclinationY = inclinationBomb.getY() + (inclinationBomb.getWidth() / 2.0f) - (font.getCapHeight() / 2.0f);
    combinationY = combinationBomb.getY() + (combinationBomb.getWidth() / 2.0f) - (font.getCapHeight() / 2.0f);
    wireY = wireBomb.getY() + (wireBomb.getWidth() / 2.0f) - (font.getCapHeight() / 2.0f);

    titleWidth = titleFont.getBounds("Summary").width;
    titleHeight = titleFont.getBounds("Summary").height;
}

From source file:ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameAutomaticActionSummaryOverlay.java

License:Apache License

@Override
public void render(SpriteBatch batch, SummaryBase summary) throws ClassCastException {
    BombGameAutomaticActionSummary bombGameSummary;

    if (!(summary instanceof BombGameAutomaticActionSummary))
        throw new ClassCastException("Summary is not a bomb game summary.");

    bombGameSummary = (BombGameAutomaticActionSummary) summary;

    inclinationBomb.draw(batch);/*from w  w  w .  j av  a  2  s. c  om*/
    combinationBomb.draw(batch);
    wireBomb.draw(batch);

    font.draw(batch, String.format("Inclination bombs: %d", bombGameSummary.getNumInclinationBombs()),
            inclinationX, inclinationY);
    font.draw(batch, String.format("Combination bombs: %d", bombGameSummary.getNumCombinationBombs()),
            combinationX, combinationY);
    font.draw(batch, String.format("Wire bombs: %d", bombGameSummary.getNumWireBombs()), wireX, wireY);

    font.draw(batch, "Bombs found: " + bombGameSummary.getBombsSeen(), wireX,
            inclinationY + inclinationBomb.getHeight() + font.getCapHeight() + 20.0f);
    font.draw(batch, "Bombs expected: " + BombGameEntityCreator.NUM_BOMBS, wireX,
            inclinationY + inclinationBomb.getHeight() + 10.0f);

    if (!Ouya.runningOnOuya)
        titleFont.draw(batch, "Summary", -(titleWidth / 2),
                (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
    else
        titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - 10);
}

From source file:ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameInstructionsOverlay.java

License:Apache License

public BombGameInstructionsOverlay() {
    FreeTypeFontGenerator fontGenerator;
    FreeTypeFontParameter fontParameters;

    inclinationBombTexture = new Texture(Gdx.files.internal("data/gfx/bomb_game/incl_bomb.png"));
    combinationBombTexture = new Texture(Gdx.files.internal("data/gfx/bomb_game/comb_bomb.png"));
    wireBombTexture = new Texture(Gdx.files.internal("data/gfx/bomb_game/wire_bomb.png"));

    inclinationBomb = new Sprite(inclinationBombTexture);
    combinationBomb = new Sprite(combinationBombTexture);
    wireBomb = new Sprite(wireBombTexture);

    inclinationBomb.setSize(inclinationBomb.getWidth() * 0.5f, inclinationBomb.getHeight() * 0.5f);
    combinationBomb.setSize(combinationBomb.getWidth() * 0.5f, combinationBomb.getHeight() * 0.5f);
    wireBomb.setSize(wireBomb.getWidth() * 0.5f, wireBomb.getHeight() * 0.5f);

    combinationBomb.setPosition(-(Utils.getScreenWidthWithOverscan() / 4.0f) - combinationBomb.getWidth(),
            -(combinationBomb.getHeight() / 2.0f));
    inclinationBomb.setPosition(-(Utils.getScreenWidthWithOverscan() / 4.0f) - inclinationBomb.getWidth(),
            combinationBomb.getY() + combinationBomb.getHeight() + 10.0f);
    wireBomb.setPosition(-(Utils.getScreenWidthWithOverscan() / 4.0f) - wireBomb.getWidth(),
            combinationBomb.getY() - wireBomb.getHeight() - 10.0f);

    fontParameters = new FreeTypeFontParameter();
    fontParameters.characters = ProjectConstants.FONT_CHARS;
    if (!Ouya.runningOnOuya)
        fontParameters.size = (int) ((float) ProjectConstants.MENU_BUTTON_FONT_SIZE
                * ((float) Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
    else/*from  www  . j ava  2 s  . c o m*/
        fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
    fontParameters.flip = false;
    fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));

    font = fontGenerator.generateFont(fontParameters);
    font.setColor(Color.YELLOW);

    fontParameters.size = (int) (90.0f * ((float) Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
    titleFont = fontGenerator.generateFont(fontParameters);

    fontGenerator.dispose();

    inclinationX = inclinationBomb.getX() + inclinationBomb.getWidth() + 15.0f;
    combinationX = combinationBomb.getX() + combinationBomb.getWidth() + 15.0f;
    wireX = wireBomb.getX() + wireBomb.getWidth() + 15.0f;

    inclinationY = inclinationBomb.getY() + (inclinationBomb.getWidth() / 2.0f) - (font.getCapHeight() / 2.0f);
    combinationY = combinationBomb.getY() + (combinationBomb.getWidth() / 2.0f) - (font.getCapHeight() / 2.0f);
    wireY = wireBomb.getY() + (wireBomb.getWidth() / 2.0f) - (font.getCapHeight() / 2.0f);

    titleWidth = titleFont.getBounds("Instructions").width;
    titleHeight = titleFont.getBounds("Instructions").height;
}

From source file:ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameInstructionsOverlay.java

License:Apache License

@Override
public void render(SpriteBatch batch) {
    String inclText = Utils.deviceHasOrientationSensors() ? "Balance your device" : "Always defuses.";

    inclinationBomb.draw(batch);//from w w  w . ja  va2  s .c  o m
    combinationBomb.draw(batch);
    wireBomb.draw(batch);

    font.draw(batch, inclText, inclinationX, inclinationY);
    font.draw(batch, "Blue, red, gray and green", combinationX, combinationY);
    font.draw(batch, "Cut the blue wire.", wireX, wireY);

    if (!Ouya.runningOnOuya)
        titleFont.draw(batch, "Instructions", -(titleWidth / 2),
                (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
    else
        titleFont.draw(batch, "Instructions", -(titleWidth / 2),
                (Utils.getScreenHeightWithOverscan() / 2) - 10);
}

From source file:ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameScenarioEndingOverlay.java

License:Apache License

public BombGameScenarioEndingOverlay() {
    FreeTypeFontGenerator fontGenerator;
    FreeTypeFontParameter fontParameters;

    fontParameters = new FreeTypeFontParameter();
    fontParameters.characters = ProjectConstants.FONT_CHARS;
    if (!Ouya.runningOnOuya)
        fontParameters.size = (int) (65.0f * ((float) Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
    else//w w  w  .  ja  v  a  2  s  .c  o  m
        fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
    fontParameters.flip = false;
    fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));

    font = fontGenerator.generateFont(fontParameters);
    font.setColor(Color.YELLOW);

    fontParameters.size = (int) (90.0f * ((float) Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
    titleFont = fontGenerator.generateFont(fontParameters);

    fontGenerator.dispose();

    textX = -(Utils.getScreenWidthWithOverscan() / 7.0f);
    baseTextY = -(font.getCapHeight() / 2.0f);
}

From source file:ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameScenarioEndingOverlay.java

License:Apache License

@Override
public void render(SpriteBatch batch, SummaryBase summary) throws ClassCastException {
    BombGamePlayerSummary bombGamePlayerSummary;
    String title;/*from   w  ww.j  a  va  2s.c om*/
    String text;

    // Get the player's summary.
    if (!(summary instanceof BombGamePlayerSummary))
        throw new ClassCastException("Summary is not a bomb game summary.");
    bombGamePlayerSummary = (BombGamePlayerSummary) summary;

    // Render the summary.
    text = String.format("Lives left: %d", bombGamePlayerSummary.livesLeft);
    textX = -(font.getBounds(text).width / 2);
    font.draw(batch, text, textX, baseTextY + font.getCapHeight() + 15);

    text = String.format("Bombs defused: %d", bombGamePlayerSummary.disabledBombs);
    textX = -(font.getBounds(text).width / 2);
    font.draw(batch, text, textX, baseTextY);

    text = String.format("Bombs detonated: %d", bombGamePlayerSummary.detonatedBombs);
    textX = -(font.getBounds(text).width / 2);
    font.draw(batch, text, textX, baseTextY - font.getCapHeight() - 15);

    // Render the title.
    if (bombGamePlayerSummary.victory)
        title = "Victory!";
    else
        title = "Game Over";
    titleBounds = titleFont.getBounds(title);

    if (!Ouya.runningOnOuya)
        titleFont.draw(batch, title, -(titleBounds.width / 2),
                (Utils.getScreenHeightWithOverscan() / 2) - titleBounds.height - 10);
    else
        titleFont.draw(batch, title, -(titleBounds.width / 2), (Utils.getScreenHeightWithOverscan() / 2) - 10);
}

From source file:ve.ucv.ciens.ccg.nxtar.states.AutomaticActionState.java

License:Apache License

@Override
public void render(float delta) {
    int w, h;// w ww  .j a  v  a 2 s .c  o m
    byte[] frame;
    MarkerData data;
    TextureRegion region;
    float focalPointX, focalPointY, cameraCenterX, cameraCenterY;

    // Clear the screen.
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // Render the background.
    core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
    core.batch.begin();
    {
        if (backgroundShader != null) {
            core.batch.setShader(backgroundShader);
            backgroundShader.setUniform2fv("u_scaling", uScaling, 0, 2);
        }
        background.draw(core.batch);
        if (backgroundShader != null)
            core.batch.setShader(null);
    }
    core.batch.end();

    // Fetch the current video frame.
    frame = frameMonitor.getCurrentFrame();
    w = frameMonitor.getFrameDimensions().getWidth();
    h = frameMonitor.getFrameDimensions().getHeight();

    // Create the 3D perspective camera and the frame buffer object if they don't exist.
    if (perspectiveCamera == null && frameBuffer == null) {
        frameBuffer = new FrameBuffer(Format.RGBA8888, w, h, true);
        frameBuffer.getColorBufferTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

        perspectiveCamera = new CustomPerspectiveCamera(67, w, h);
        perspectiveCamera.translate(0.0f, 0.0f, 0.0f);
        perspectiveCamera.near = NEAR;
        perspectiveCamera.far = FAR;
        perspectiveCamera.lookAt(0.0f, 0.0f, -1.0f);
        perspectiveCamera.update();
    }

    // Attempt to find the markers in the current video frame.
    data = core.cvProc.findMarkersInFrame(frame);

    // If a valid frame was fetched.
    if (data != null && data.outFrame != null) {
        if (automaticActionEnabled)
            performAutomaticAction(data);

        // Set the camera to the correct projection.
        focalPointX = core.cvProc.getFocalPointX();
        focalPointY = core.cvProc.getFocalPointY();
        cameraCenterX = core.cvProc.getCameraCenterX();
        cameraCenterY = core.cvProc.getCameraCenterY();
        perspectiveCamera.setCustomARProjectionMatrix(focalPointX, focalPointY, cameraCenterX, cameraCenterY,
                NEAR, FAR, w, h);
        perspectiveCamera.update(perspectiveCamera.projection);

        // Update the game state.
        gameWorld.setDelta(Gdx.graphics.getDeltaTime() * 1000);
        gameWorld.getSystem(MarkerPositioningSystem.class).setMarkerData(data);
        gameWorld.process();

        // Decode the video frame.
        videoFrame = new Pixmap(data.outFrame, 0, w * h);
        videoFrameTexture = new Texture(videoFrame);
        videoFrameTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        videoFrame.dispose();

        // Convert the decoded frame into a renderable texture.
        region = new TextureRegion(videoFrameTexture, 0, 0, w, h);
        if (renderableVideoFrame == null)
            renderableVideoFrame = new Sprite(region);
        else
            renderableVideoFrame.setRegion(region);
        renderableVideoFrame.setOrigin(renderableVideoFrame.getWidth() / 2,
                renderableVideoFrame.getHeight() / 2);
        renderableVideoFrame.setPosition(0, 0);

        // Set the 3D frame buffer for rendering.
        frameBuffer.begin();
        {
            // Set OpenGL state.
            Gdx.gl.glClearColor(0, 0, 0, 0);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
            Gdx.gl.glDisable(GL20.GL_TEXTURE_2D);

            // Call rendering systems.
            markerRenderingSystem.begin(perspectiveCamera);
            markerRenderingSystem.process();
            markerRenderingSystem.end();
        }
        frameBuffer.end();

        // Set the frame buffer object texture to a renderable sprite.
        region = new TextureRegion(frameBuffer.getColorBufferTexture(), 0, 0, frameBuffer.getWidth(),
                frameBuffer.getHeight());
        region.flip(false, true);
        if (frameBufferSprite == null)
            frameBufferSprite = new Sprite(region);
        else
            frameBufferSprite.setRegion(region);
        frameBufferSprite.setOrigin(frameBufferSprite.getWidth() / 2, frameBufferSprite.getHeight() / 2);
        frameBufferSprite.setPosition(0, 0);

        // Set the position and orientation of the renderable video frame and the frame buffer.
        if (!Ouya.runningOnOuya) {
            renderableVideoFrame.setSize(1.0f,
                    renderableVideoFrame.getHeight() / renderableVideoFrame.getWidth());
            renderableVideoFrame.rotate90(true);
            renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2,
                    0.5f - renderableVideoFrame.getHeight());

            frameBufferSprite.setSize(1.0f, frameBufferSprite.getHeight() / frameBufferSprite.getWidth());
            frameBufferSprite.rotate90(true);
            frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2,
                    0.5f - frameBufferSprite.getHeight());
        } else {
            float xSize = Gdx.graphics.getHeight() * (w / h);
            renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN,
                    Utils.getScreenHeightWithOverscan());
            renderableVideoFrame.rotate90(true);
            renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2,
                    -renderableVideoFrame.getHeight() / 2);

            frameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeightWithOverscan());
            frameBufferSprite.rotate90(true);
            frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, -frameBufferSprite.getHeight() / 2);
        }

        // Set the correct camera for the device.
        if (!Ouya.runningOnOuya) {
            core.batch.setProjectionMatrix(unitaryOrthographicCamera.combined);
        } else {
            core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
        }

        // Render the video frame and the frame buffer.
        core.batch.begin();
        {
            renderableVideoFrame.draw(core.batch);
            frameBufferSprite.draw(core.batch);
        }
        core.batch.end();

        // Clear the video frame from memory.
        videoFrameTexture.dispose();
    }

    core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
    core.batch.begin();
    {
        startButton.draw(core.batch, 1.0f);
        if (Ouya.runningOnOuya)
            ouyaOButton.draw(core.batch);
    }
    core.batch.end();

    data = null;
}

From source file:ve.ucv.ciens.ccg.nxtar.states.AutomaticActionState.java

License:Apache License

private void setUpButton() {
    TextButtonStyle textButtonStyle;/*from   w  ww. ja va2  s.co m*/
    FreeTypeFontGenerator fontGenerator;
    FreeTypeFontParameter fontParameters;

    // Create the start button background.
    startButtonEnabledTexture = new Texture(
            Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
    startButtonEnabled9p = new NinePatch(new TextureRegion(startButtonEnabledTexture, 0, 0,
            startButtonEnabledTexture.getWidth(), startButtonEnabledTexture.getHeight()), 49, 49, 45, 45);
    startButtonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
    startButtonDisabled9p = new NinePatch(new TextureRegion(startButtonDisabledTexture, 0, 0,
            startButtonDisabledTexture.getWidth(), startButtonDisabledTexture.getHeight()), 49, 49, 45, 45);
    startButtonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
    startButtonPressed9p = new NinePatch(new TextureRegion(startButtonPressedTexture, 0, 0,
            startButtonPressedTexture.getWidth(), startButtonPressedTexture.getHeight()), 49, 49, 45, 45);

    // Create the start button font.
    fontParameters = new FreeTypeFontParameter();
    fontParameters.characters = ProjectConstants.FONT_CHARS;
    fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
    fontParameters.flip = false;
    fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
    font = fontGenerator.generateFont(fontParameters);
    fontGenerator.dispose();

    // Create the start button.
    textButtonStyle = new TextButtonStyle();
    textButtonStyle.font = font;
    textButtonStyle.up = new NinePatchDrawable(startButtonEnabled9p);
    textButtonStyle.checked = new NinePatchDrawable(startButtonPressed9p);
    textButtonStyle.disabled = new NinePatchDrawable(startButtonDisabled9p);
    textButtonStyle.fontColor = new Color(Color.BLACK);
    textButtonStyle.downFontColor = new Color(Color.WHITE);
    textButtonStyle.disabledFontColor = new Color(Color.BLACK);

    startButton = new TextButton("Start automatic action", textButtonStyle);
    startButton.setText("Start automatic action");
    startButton.setDisabled(false);
    startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight());
    startButton.setPosition(-(startButton.getWidth() / 2), -(Gdx.graphics.getHeight() / 2) + 10);
    startButtonBBox.setPosition(startButton.getX(), startButton.getY());

    // Set OUYA's O button.
    if (Ouya.runningOnOuya) {
        ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
        ouyaOButton = new Sprite(ouyaOButtonTexture);
        ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
        oButtonPressed = false;
        ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20,
                startButton.getY() + (ouyaOButton.getHeight() / 2));
    } else {
        ouyaOButtonTexture = null;
    }
}