Example usage for com.badlogic.gdx Application getGraphics

List of usage examples for com.badlogic.gdx Application getGraphics

Introduction

In this page you can find the example usage for com.badlogic.gdx Application getGraphics.

Prototype

public Graphics getGraphics();

Source Link

Usage

From source file:com.davidykay.shootout.Renderer.java

License:Apache License

public void render(Application app, Simulation simulation) {
    GL10 gl = app.getGraphics().getGL10();
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glViewport(0, 0, app.getGraphics().getWidth(), app.getGraphics().getHeight());

    renderBackground(gl);//  www  . j a va 2  s .c  om
    renderEarth(gl);

    gl.glDisable(GL10.GL_DITHER);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glEnable(GL10.GL_CULL_FACE);

    //setProjectionAndCamera(app.getGraphics(), simulation.ship, app);
    setProjectionAndCameraAugmentedReality(app.getGraphics(), simulation, app);

    setLighting(gl);

    gl.glEnable(GL10.GL_TEXTURE_2D);

    renderMoon(gl, simulation.ship);
    renderShip(gl, simulation.ship, app);
    renderAliens(gl, simulation.aliens);

    gl.glDisable(GL10.GL_TEXTURE_2D);
    renderBlocks(gl, simulation.blocks);

    gl.glDisable(GL10.GL_LIGHTING);

    //renderShots(gl, simulation.shots);
    //renderRays(gl, simulation.mRays, true);
    renderAlienRays(gl, simulation.mAlienRays);
    renderPlayerRays(gl, simulation.mShipRays);

    gl.glEnable(GL10.GL_TEXTURE_2D);
    renderExplosions(gl, simulation.explosions);
    renderBombExplosions(gl, simulation.bombExplosions);

    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_DEPTH_TEST);

    spriteBatch.setProjectionMatrix(viewMatrix);
    spriteBatch.setTransformMatrix(transformMatrix);
    spriteBatch.begin();
    if (simulation.ship.lives != lastLives || simulation.score != lastScore || simulation.wave != lastWave) {
        status = "lives: " + simulation.ship.lives + " wave: " + simulation.wave + " score: "
                + simulation.score;
        lastLives = simulation.ship.lives;
        lastScore = simulation.score;
        lastWave = simulation.wave;
    }
    spriteBatch.enableBlending();
    spriteBatch.setBlendFunction(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
    font.draw(spriteBatch, status, 0, 320);
    spriteBatch.end();

    alienAngle += app.getGraphics().getDeltaTime() * 90;
    if (alienAngle > 360)
        alienAngle -= 360;
}

From source file:com.davidykay.shootout.screens.GameLoop.java

License:Apache License

@Override
public void render(Application app) {
    app.getGraphics().getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    renderer.render(app, simulation);/*from ww  w .java  2  s. co m*/
}

From source file:com.davidykay.shootout.screens.GameLoop.java

License:Apache License

@Override
public void update(Application app) {
    simulation.update(app.getGraphics().getDeltaTime());

    Input input = app.getInput();/*  w  ww .  j a v a 2 s  .  c o m*/
    final boolean ACCELEROMETER_STEERING = false;
    if (ACCELEROMETER_STEERING) {
        if (input.getAccelerometerY() < 0)
            simulation.moveShipLeft(app.getGraphics().getDeltaTime(), Math.abs(input.getAccelerometerY()) / 10);
        else
            simulation.moveShipRight(app.getGraphics().getDeltaTime(),
                    Math.abs(input.getAccelerometerY()) / 10);
    }

    if (input.isKeyPressed(Keys.DPAD_LEFT))
        simulation.moveShipLeft(app.getGraphics().getDeltaTime(), 0.5f);
    if (input.isKeyPressed(Keys.DPAD_RIGHT))
        simulation.moveShipRight(app.getGraphics().getDeltaTime(), 0.5f);

    if (input.justTouched()) {
        final float x = input.getX();
        final float y = input.getY();
        Vector3 nearVector = new Vector3(x, y, 0);
        Vector3 farVector = new Vector3(x, y, 1);

        renderer.unproject(nearVector);
        renderer.unproject(farVector);

        /** Vector tracing between the near plane and the far plane **/
        Vector3 inVector = new Vector3(nearVector);

        final Plane gamePlane = new Plane(new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1));

        Ray pickRay = renderer.getCamera().getPickRay(x, y);

        Vector3 intersection = new Vector3();
        Vector3 finalVector;

        if (FLAT_MODE) {
            // Flat Mode
            if (Intersector.intersectRayPlane(pickRay, gamePlane, intersection)) {
                finalVector = new Vector3(intersection);
                if (finalVector.equals(nearVector)) {
                    Gdx.app.log(TAG, String.format("Near Vector! finalVector:(%s)", finalVector.toString()));
                } else {
                    Gdx.app.log(TAG, String.format("INTERSECTION! finalVector:(%s)", finalVector.toString()));
                }
            } else {
                Gdx.app.log(TAG, String.format("NO INTERSECTION. nearVector:(%s)", nearVector.toString()));
                finalVector = new Vector3(nearVector);
            }
        } else {
            // 3D Mode

            finalVector = new Vector3(nearVector);

            //for (Alien alien : aliens) {
            //  if (
            //      Intersector.intersectRayPlane(
            //          pickRay,
            //          gamePlane,
            //          intersection
            //          )
            //     ) {

            //  }
            //}
        }

        //simulation.tapShot(nearVector);
        //simulation.tapShot(finalVector);
        simulation.tapRay(pickRay);
    } else {
        // If we haven't been touched, let's look at the orientation. This in an attempt to lower
        // impulse from user's finger.
        float azimuth = input.getAzimuth();
        float pitch = input.getPitch();
        float roll = input.getRoll();

        simulation.updateOrientation(azimuth, pitch, roll);
    }
}

From source file:com.davidykay.shootout.screens.GameOver.java

License:Apache License

@Override
public void render(Application app) {
    app.getGraphics().getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT);

    viewMatrix.setToOrtho2D(0, 0, 480, 320);
    spriteBatch.setProjectionMatrix(viewMatrix);
    spriteBatch.setTransformMatrix(transformMatrix);
    spriteBatch.begin();//from   ww  w .  jav a  2  s.  co m
    spriteBatch.disableBlending();
    spriteBatch.setColor(Color.WHITE);
    spriteBatch.draw(background, 0, 0, 480, 320, 0, 0, 512, 512, false, false);
    spriteBatch.enableBlending();
    spriteBatch.draw(logo, 0, 320 - 128, 480, 128, 0, 256, 512, 256, false, false);
    String text = "You have failed Earth.\nTouch to continue.";
    TextBounds bounds = font.getMultiLineBounds(text);
    spriteBatch.setBlendFunction(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
    font.drawMultiLine(spriteBatch, text, 0, 160 + bounds.height / 2, 480, HAlignment.CENTER);
    spriteBatch.end();
}

From source file:com.davidykay.shootout.screens.MainMenu.java

License:Apache License

@Override
public void render(Application app) {
    app.getGraphics().getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT);

    viewMatrix.setToOrtho2D(0, 0, 480, 320);
    spriteBatch.setProjectionMatrix(viewMatrix);
    spriteBatch.setTransformMatrix(transformMatrix);
    spriteBatch.begin();/*from  w ww.j  a  v a  2s  . c om*/
    spriteBatch.disableBlending();
    spriteBatch.setColor(Color.WHITE);
    spriteBatch.draw(background, 0, 0, 480, 320, 0, 0, 512, 512, false, false);
    spriteBatch.enableBlending();
    spriteBatch.draw(logo, 0, 320 - 128, 480, 128, 0, 0, 512, 256, false, false);
    spriteBatch.setBlendFunction(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
    String text = "Touch to start!";
    float width = font.getBounds(text).width;
    font.draw(spriteBatch, text, 240 - width / 2, 128);
    spriteBatch.end();
}

From source file:com.digitale.mygdxgame.Renderer.java

License:Open Source License

private void renderSolarSystem(Application app, Simulation simulation) {
    GL10 gl = app.getGraphics().getGL10();
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glViewport(0, 0, app.getGraphics().getWidth(), app.getGraphics().getHeight());

    // renderBackground(gl);

    gl.glDisable(GL10.GL_DITHER);// w w  w  . j  a  v  a 2  s  .c  o m
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glEnable(GL10.GL_CULL_FACE);

    setProjectionAndCamera(app.getGraphics(), Simulation.ship, app, gl);
    setLighting(gl);

    gl.glEnable(GL10.GL_TEXTURE_2D);
    // renderRoids(gl);
    // camera.unproject(GameLoop.touchPoint.set(Gdx.input.getX(),
    // Gdx.input.getY(), 0));

    // render earth
    // renderPlanet(gl, "earth", true, 63780f, 200000, 0, 50000);
    // render mars
    renderPlanet(gl, "sun", true, 33970, 0, 0, 50000);
    // render sun
    renderSun(gl, 69550f, 0, 0, -500000, app);
    // render jupiter
    // renderPlanet(gl, "earth", false, 714920f, -4000000, 0, 50000);
    // render moon
    // renderMoon(gl, 17370f, 100000, 0, -50000);

    // renderDrones(gl, simulation.drones, app, Simulation.ship);
    renderSky(gl, Simulation.ship, app);
    renderActors(gl);

    // do alpha models after this

    // render station
    renderStation(gl, "station01", true, 1000f, 0, 0, 0);
    // render myship
    renderShip(gl, Simulation.ship, Stardust3d.myCharacter.getShipname());
    renderDusts(gl, Simulation.dusts);
    renderShots(gl, simulation.shots);
    renderMissiles(gl, simulation.missiles);
    // renderTrails(gl, simulation.trails);
    gl.glDisable(GL10.GL_TEXTURE_2D);
    // renderBlocks(gl, simulation.blocks);

    // gl.glDisable(GL10.GL_LIGHTING);

    gl.glEnable(GL10.GL_TEXTURE_2D);
    renderExplosions(gl, Simulation.explosions);

    renderHud(simulation, gl);
    stationAngle += app.getGraphics().getDeltaTime() * 1;
    if (stationAngle > 360)
        stationAngle -= 360;

    invaderAngle += app.getGraphics().getDeltaTime() * 10;
    if (invaderAngle > 360)
        invaderAngle -= 360;
}

From source file:com.digitale.mygdxgame.Renderer.java

License:Open Source License

private void renderInsideStation(Application app, Simulation simulation) {
    GL10 gl = app.getGraphics().getGL10();
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glViewport(0, 0, app.getGraphics().getWidth(), app.getGraphics().getHeight());
    gl.glDisable(GL10.GL_DITHER);//w w  w.  j ava2 s  . c o m
    gl.glEnable(GL10.GL_DEPTH_TEST);
    setStaticProjectionAndCamera(app.getGraphics(), app, gl);
    setLighting(gl);
    gl.glEnable(GL10.GL_TEXTURE_2D);
    renderStaticShip(gl, Simulation.ship, app, Stardust3d.myCharacter.getShipname());
    // renderDrones(gl, simulation.drones, app, Simulation.ship);
    gl.glDisable(GL10.GL_DITHER);

    gl.glEnable(GL10.GL_TEXTURE_2D);
    // do alpha models after this

    renderHangar(gl, Simulation.ship, app);
    gl.glDisable(GL10.GL_TEXTURE_2D);
    renderHud(simulation, gl);

}

From source file:com.digitale.mygdxgame.SplashRenderer.java

License:Open Source License

private void renderInsideStation(Application app) {
    GL10 gl = app.getGraphics().getGL10();
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glViewport(0, 0, app.getGraphics().getWidth(), app.getGraphics().getHeight());
    gl.glEnable(GL10.GL_BLEND);//www  . j  av  a 2  s .c om
    gl.glDisable(GL10.GL_DITHER);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glEnable(GL10.GL_CULL_FACE);
    setStaticProjectionAndCamera(app.getGraphics(), app, gl);
    setLighting(gl);
    gl.glEnable(GL10.GL_TEXTURE_2D);
    renderSky(gl);
    renderPlanet(gl, "sun", true, 1737f, Splash.planetmove - 150, 0, -2500, app);
    renderSky(gl);
    gl.glDisable(GL10.GL_DITHER);
    gl.glDisable(GL10.GL_CULL_FACE);
    //do alpha models after this
    renderStaticShip(gl, app);
    renderSun(gl, 70000f, -1600, 0, -4500, app);
    gl.glDisable(GL10.GL_TEXTURE_2D);
    renderHud(gl);
}

From source file:org.illarion.engine.backend.gdx.GdxEngine.java

License:Open Source License

/**
 * Create a new instance of the engine along with the reference to the libGDX application that is used.
 *
 * @param gdxApplication the active libGDX application
 * @param container      the game container that shows the application
 *///  w  w w.j a v a2 s  . c  om
GdxEngine(@Nonnull final Application gdxApplication, @Nonnull final GameContainer container) {
    if (!gdxApplication.getGraphics().isGL20Available()) {
        Sys.alert("Graphic device failure.", "You graphic device does not seem to support the client.");
        System.exit(-1);
    }
    assets = new GdxAssets(gdxApplication, container);
    sounds = new GdxSounds();
    graphics = new GdxGraphics(this, gdxApplication.getGraphics());
    input = new GdxInput(gdxApplication.getInput());
}