Example usage for com.badlogic.gdx.graphics Pixmap Pixmap

List of usage examples for com.badlogic.gdx.graphics Pixmap Pixmap

Introduction

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

Prototype

public Pixmap(byte[] encodedData, int offset, int len) 

Source Link

Document

Creates a new Pixmap instance from the given encoded image data.

Usage

From source file:com.googlecode.gdxquake2.installer.ImageConverter.java

License:Open Source License

static Pixmap makePalletizedImage(image_t source) {
    Pixmap image = new Pixmap(source.width, source.height, Pixmap.Format.RGBA8888);
    for (int y = 0; y < source.height; ++y) {
        for (int x = 0; x < source.width; ++x) {
            int ofs = source.pix[y * source.width + x];
            if (ofs < 0) {
                ofs += 256;//  w w  w.j a v a2  s  . c  om
            }
            int rgba = (ofs == 255) ? 0 : QuakeImage.PALETTE_RGBA[ofs];
            image.drawPixel(x, y, rgba);
        }
    }
    return image;
}

From source file:com.heaven7.fantastictank.test.ScreenUtils.java

License:Apache License

/** Returns a portion of the default framebuffer contents specified by x, y, width and height as a {@link TextureRegion} with
 * the same dimensions. The base {@link Texture} always has {@link MathUtils#nextPowerOfTwo} dimensions and RGBA8888
 * {@link Format}. It can be accessed via {@link TextureRegion#getTexture}. This texture is not managed and has to be reloaded
 * manually on a context loss. If the width and height specified are larger than the framebuffer dimensions, the Texture will
 * be padded accordingly. Pixels that fall outside of the current screen will have RGBA values of 0.
 * //from  w  w  w  .j av  a  2  s.c  om
 * @param x the x position of the framebuffer contents to capture
 * @param y the y position of the framebuffer contents to capture
 * @param w the width of the framebuffer contents to capture
 * @param h the height of the framebuffer contents to capture */
public static TextureRegion getFrameBufferTexture(int x, int y, int w, int h) {
    final int potW = MathUtils.nextPowerOfTwo(w);
    final int potH = MathUtils.nextPowerOfTwo(h);

    final Pixmap pixmap = getFrameBufferPixmap(x, y, w, h);
    final Pixmap potPixmap = new Pixmap(potW, potH, Format.RGBA8888);
    potPixmap.drawPixmap(pixmap, 0, 0);
    Texture texture = new Texture(potPixmap);
    TextureRegion textureRegion = new TextureRegion(texture, 0, h, w, -h);
    pixmap.dispose();

    return textureRegion;
}

From source file:com.heaven7.fantastictank.test.ScreenUtils.java

License:Apache License

public static Pixmap getFrameBufferPixmap(int x, int y, int w, int h) {
    Gdx.gl.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1);

    final Pixmap pixmap = new Pixmap(w, h, Format.RGBA8888);
    ByteBuffer pixels = pixmap.getPixels();
    Gdx.gl.glReadPixels(x, y, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels);

    return pixmap;
}

From source file:com.intrepid.nicge.utilz.graphics.TextureWorks.java

public static Texture createTexture(int sizex, int sizey, Color color) {
    // For all//w w w . j  a v a 2s.  c om
    Pixmap pixmap = new Pixmap(sizex, sizey, Format.RGBA8888);
    pixmap.setColor(color);
    pixmap.fill();
    return new Texture(pixmap);
}

From source file:com.intrepid.studio.animation.GroupTag.java

public void createPixmapBase(int PIXMAP_BASE_SIZE) {
    pixmap = new Pixmap(PIXMAP_BASE_SIZE, PIXMAP_BASE_SIZE, Format.RGBA8888);
}

From source file:com.ixeption.libgdx.transitions.impl.ColorFadeTransition.java

License:Apache License

/** @param color the {@link Color} to fade to
 * @param interpolation the {@link Interpolation} method */
public ColorFadeTransition(Color color, Interpolation interpolation) {
    this.color = new Color(Color.WHITE);
    this.interpolation = interpolation;

    texture = new Texture(1, 1, Format.RGBA8888);
    Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
    pixmap.setColor(color);//from  ww w.j  ava2s  .c o  m
    pixmap.fillRectangle(0, 0, 1, 1);
    texture.draw(pixmap, 0, 0);
}

From source file:com.jmstudios.pointandhit.GameScreen.java

License:Open Source License

public void setupMenus() {
    Texture buttonsTex = game.buttons;/*from ww  w  .j a  v a2s  . c om*/

    // Game running menu
    gameRunningStage = new Stage();
    TextureRegion pauseButtonTex = new TextureRegion(buttonsTex, 512, 256, 128, 128);
    pauseButton = new ImageButton(new TextureRegionDrawable(pauseButtonTex));
    pauseButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            pauseGame();
        }
    });
    Table pauseButtonTable = new Table();
    pauseButtonTable.setPosition(screenSize.x - (pauseButton.getWidth() * scale),
            screenSize.y - (pauseButton.getHeight() * scale));
    pauseButtonTable.add(pauseButton).size(pauseButton.getWidth() * scale);
    gameRunningStage.addActor(pauseButtonTable);

    // Set up font
    textFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_medium.fnt"));
    textFont.setColor(Color.WHITE);
    textFont.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
    textFont.setScale(scale);

    // Set up transparent shader
    Pixmap onePixTransparent = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    onePixTransparent.setColor(new Color(0, 0, 0, 0.6f));
    onePixTransparent.fill();
    transparentShader = new Texture(onePixTransparent);

    // Set up buttons
    TextureRegion resumeTex = new TextureRegion(buttonsTex, 0, 0, 256, 256),
            retryTex = new TextureRegion(buttonsTex, 256, 0, 256, 256),
            menuTex = new TextureRegion(buttonsTex, 512, 0, 256, 256);
    TextureRegionDrawable resumeDrawable = new TextureRegionDrawable(resumeTex),
            retryDrawable = new TextureRegionDrawable(retryTex),
            menuDrawable = new TextureRegionDrawable(menuTex);
    resumeButton = new ImageButton(resumeDrawable);
    retryButton = new ImageButton(retryDrawable);
    menuButton = new ImageButton(menuDrawable);

    // Click listeners
    resumeButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            gameState = GameState.Running;
            giveFocus();
        }
    });
    retryButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            retry();
        }
    });
    menuButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            goToMainMenu();
        }
    });

    // Set up pauseTable
    float padding = 20 * scale;
    this.pauseStage = new Stage();
    Table wholePauseTable = new Table();
    wholePauseTable.setFillParent(true);
    pauseTable = new Table();
    pauseTable.defaults().pad(padding).padTop(padding * 3).padBottom(padding * 3); // Different screen sizes
    pauseTable.add(resumeButton).size(resumeButton.getWidth() * scale);
    pauseTable.add(retryButton).size(retryButton.getWidth() * scale);
    pauseTable.add(menuButton).size(menuButton.getWidth() * scale);
    wholePauseTable.add(pauseTable).fill(10, 1f);
    pauseStage.addActor(wholePauseTable);

    // Set up game over menu
    gameOverStage = new Stage();
    gameOverTable = new Table();
    gameOverStage.addActor(gameOverTable);

    // Labels
    Label.LabelStyle scoreLabelStyle = new Label.LabelStyle(textFont, Color.WHITE);

    Label.LabelStyle gameOverLabelStyle = new Label.LabelStyle(scoreFont, Color.WHITE);
    gameOverText = new Label("Game over", gameOverLabelStyle);
    scoreTextLabel = new Label("Score: ", scoreLabelStyle);
    highScoreTextLabel = new Label("Highscore: ", scoreLabelStyle);
    scoreLabel = new Label("null", gameOverLabelStyle);
    highScoreLabel = new Label("null", scoreLabelStyle);

    // Buttons   
    gameOverRetryButton = new ImageButton(retryDrawable);
    gameOverMenuButton = new ImageButton(menuDrawable);
    gameOverRetryButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            retry();
        }
    });
    gameOverMenuButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            goToMainMenu();
        }
    });

    gameOverButtonsTable = new Table();
    gameOverButtonsTable.defaults().pad(padding * 2);
    gameOverButtonsTable.add(gameOverRetryButton).left().size(gameOverRetryButton.getWidth() * scale);
    gameOverButtonsTable.add(gameOverMenuButton).right().size(gameOverMenuButton.getHeight() * scale);

    gameOverTable.setFillParent(true);
    gameOverTable.setDebug(false);
    gameOverTable.defaults().pad(padding * 2);
    gameOverTable.add(gameOverText).colspan(3).center();
    gameOverTable.row();
    gameOverTable.add(scoreLabel).colspan(3).center().pad(8 * padding);
    gameOverTable.row();
    gameOverTable.add(highScoreLabel).colspan(3).center().padTop(0).padBottom(padding * 4);
    gameOverTable.row();
    gameOverTable.add(gameOverButtonsTable).center().fill(10f, 1f).padTop(padding * 8);
}

From source file:com.jmstudios.pointandhit.GameScreen.java

License:Open Source License

public void gameOver() {
    gameState = GameState.GameOver;/*from   w  w  w.  j  av  a 2s .c  om*/

    Pixmap gameOverButtonsBackground = new Pixmap(1, 1, Format.RGBA8888);
    Color gameOverButtonsBackgroundColor = targetManager.currentTheme.target.cpy();
    gameOverButtonsBackgroundColor.a = 0.8f;
    gameOverButtonsBackground.setColor(gameOverButtonsBackgroundColor);
    gameOverButtonsBackground.fill();
    TextureRegionDrawable gameOverButtonsBackgroundDrawable = new TextureRegionDrawable(
            new TextureRegion(new Texture(gameOverButtonsBackground)));
    gameOverButtonsTable.setBackground(gameOverButtonsBackgroundDrawable);

    scoreLabel.setText("" + targetManager.score);
    scoreLabel.setColor(targetManager.currentTheme.target.cpy().mul(1.2f));
    int highscore = game.getHighScore();
    if (targetManager.score > highscore) {
        game.setHighScore(targetManager.score);
        highscore = targetManager.score;
    }
    highScoreLabel.setText("Best: " + highscore); // Get HighScore
    highScoreLabel.setColor(targetManager.currentTheme.bullet);

    Gdx.input.setInputProcessor(gameOverMultiplexer);
}

From source file:com.jmstudios.pointandhit.GameScreen.java

License:Open Source License

public void pauseGame() {
    gameState = GameState.Paused;/*from w  w w  .  j a  v a 2 s  .  co m*/
    Gdx.input.setInputProcessor(gamePausedMultiplexer);
    Pixmap pauseMenuBackground = new Pixmap(1, 1, Format.RGBA8888);
    Color pauseMenuColor = targetManager.currentTheme.target.cpy();
    pauseMenuColor.a = 0.8f;
    pauseMenuBackground.setColor(pauseMenuColor);
    pauseMenuBackground.fill();
    pauseTable.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture(pauseMenuBackground))));
}

From source file:com.jmstudios.pointandhit.OptionsScreen.java

License:Open Source License

public OptionsScreen(final OneShotGame game) {
    this.game = game;
    this.scale = game.scale;
    Vector2 screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    // Font/*from ww  w  .j ava 2s .  c o  m*/
    textFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_medium.fnt"));
    textFont.setScale(scale);
    BitmapFont titleFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_large.fnt"));
    titleFont.setScale(scale);

    // Checkbox style
    Texture checkBoxes = new Texture(Gdx.files.internal("buttons/radiobutton.png"));
    TextureRegionDrawable checkBoxUnchecked = new TextureRegionDrawable(
            new TextureRegion(checkBoxes, 0, 0, 64, 64));
    TextureRegionDrawable checkBoxChecked = new TextureRegionDrawable(
            new TextureRegion(checkBoxes, 64, 0, 64, 64));
    checkBoxStyle = new CheckBox.CheckBoxStyle(checkBoxUnchecked, checkBoxChecked, textFont, Color.WHITE);

    CheckBox verySensitive = newRadioButton("Very sensitive"), sensitive = newRadioButton("Sensitive"),
            normal = newRadioButton("Normal"), forgiving = newRadioButton("Forgiving"),
            veryForgiving = newRadioButton("Very forgiving"),
            invertControls = newRadioButton("Invert the controls");

    sensitivityGroup = new ButtonGroup<CheckBox>(verySensitive, sensitive, normal, forgiving, veryForgiving,
            invertControls);

    int startSetting = game.preferences.getInteger("sensitivity", 2);
    sensitivityGroup.uncheckAll();
    sensitivityGroup.getButtons().get(startSetting).setChecked(true);

    float padding = 20 * scale;

    // Title
    Table titleTable = new Table();
    titleTable.align(Align.topLeft);
    Pixmap backgroundPixmap = new Pixmap(1, 1, Format.RGBA8888);
    backgroundPixmap.setColor(new Color(0.9f, 0.35f, 0.1f, 1));
    backgroundPixmap.fill();
    titleTable.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture(backgroundPixmap))));
    Label.LabelStyle titleLabelStyle = new Label.LabelStyle(titleFont, Color.WHITE);
    Label titleLabel = new Label("Control sensitivity", titleLabelStyle);
    titleLabel.setWrap(true);
    titleLabel.setWidth(screenSize.x - padding * 2);
    titleLabel.setAlignment(Align.center);
    titleTable.add(titleLabel).align(Align.topLeft).pad(2 * padding).width(screenSize.x - padding * 2);

    // Checkboxes
    optionsTable = new Table();
    optionsTable.align(Align.topLeft);
    optionsTable.defaults().align(Align.topLeft).pad(padding).padBottom(0).padLeft(2 * padding);
    optionsTable.row();
    optionsTable.add(verySensitive);
    optionsTable.row();
    optionsTable.add(sensitive);
    optionsTable.row();
    optionsTable.add(normal);
    optionsTable.row();
    optionsTable.add(forgiving);
    optionsTable.row();
    optionsTable.add(veryForgiving);
    optionsTable.row();
    optionsTable.add(invertControls);

    optionsTable.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            int newSensitivity = sensitivityGroup.getCheckedIndex();
            if (newSensitivity == -1)
                newSensitivity = 2;
            game.preferences.putInteger("sensitivity", newSensitivity);
            game.preferences.flush();
        }
    });

    mainTable = new Table();
    mainTable.setFillParent(true);
    mainTable.align(Align.top);
    mainTable.add(titleTable).pad(0).padBottom(padding * 4).fill(10, 1).align(Align.topLeft);
    mainTable.row();
    mainTable.add(optionsTable).align(Align.left);

    mainStage = new Stage();
    mainStage.addActor(mainTable);

    // Input
    inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.addProcessor(mainStage);
    inputMultiplexer.addProcessor(this);
}