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.jumpbuttonstudios.vikingdodge.network.ImageDownloader.java

License:Apache License

public static Texture convertToTexture(DownloadedImage downloadedImage) {
    byte[] bytes = downloadedImage.getBytes();
    int numbBytes = downloadedImage.getNumBytes();

    if (numbBytes != 0) {
        Pixmap tmp = new Pixmap(bytes, 0, numbBytes);
        return new Texture(tmp);

    }/*from  w w w .java 2 s  .  c  om*/
    return null;
}

From source file:com.jupiter.europa.screen.MainMenuScreen.java

License:Open Source License

private static void buildMainMenuSkin() {
    Skin skin = new Skin();

    // Fonts//  w w w.  ja  v  a  2 s. co  m
    skin.add(BUTTON_FONT_KEY, EuropaGame.game.getAssetManager()
            .get(FileLocations.FONTS_DIRECTORY.resolve(BUTTON_FONT).toString()));
    skin.add(TITLE_FANCY_FONT_KEY, EuropaGame.game.getAssetManager()
            .get(FileLocations.FONTS_DIRECTORY.resolve(TITLE_FANCY_FONT).toString()));
    skin.add(TITLE_FONT_KEY, EuropaGame.game.getAssetManager()
            .get(FileLocations.FONTS_DIRECTORY.resolve(TITLE_FONT).toString()));
    skin.add(LIST_FONT_KEY,
            EuropaGame.game.getAssetManager().get(FileLocations.FONTS_DIRECTORY.resolve(LIST_FONT).toString()));
    skin.add(TEXT_FIELD_FONT_KEY, EuropaGame.game.getAssetManager()
            .get(FileLocations.FONTS_DIRECTORY.resolve(TEXT_FIELD_FONT).toString()));
    skin.add(INFO_LABEL_FONT_KEY, EuropaGame.game.getAssetManager()
            .get(FileLocations.FONTS_DIRECTORY.resolve(INFO_LABEL_FONT).toString()));

    // Set the background texture
    Pixmap pixmap = new Pixmap(1, (int) 1, Pixmap.Format.RGB888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add(SOLID_TEXTURE_KEY, new Texture(pixmap));
    Drawable transparentDrawable = skin.newDrawable(SOLID_TEXTURE_KEY, TRANSPARENT);

    // Get values from the atlas
    skin.addRegions(
            EuropaGame.game.getAssetManager().get(MAIN_MENU_SKIN_DIRECTORY.resolve(ATLAS_KEY).toString()));

    // Colors
    Color textButtonFontColor = new Color(0.85f, 0.85f, 0.85f, 1.0f);

    // Set images
    Drawable textButtonBackground = new TextureRegionDrawable(
            skin.get(BUTTON_BACKGROUND_KEY, TextureRegion.class));
    textButtonBackground.setLeftWidth(32);
    textButtonBackground.setRightWidth(32);
    textButtonBackground.setTopHeight(5);
    textButtonBackground.setBottomHeight(5);
    skin.add(BUTTON_BACKGROUND_KEY, textButtonBackground);

    Drawable textButtonBackgroundDown = new TextureRegionDrawable(
            skin.get(BUTTON_DOWN_KEY, TextureRegion.class));
    textButtonBackgroundDown.setLeftWidth(32);
    textButtonBackgroundDown.setRightWidth(32);
    textButtonBackgroundDown.setTopHeight(5);
    textButtonBackgroundDown.setBottomHeight(5);
    skin.add(BUTTON_DOWN_KEY, textButtonBackgroundDown);

    Drawable listSelection = new TextureRegionDrawable(skin.get(LIST_SELECTION_KEY, TextureRegion.class));
    listSelection.setLeftWidth(7);
    listSelection.setRightWidth(7);
    listSelection.setTopHeight(0);
    listSelection.setBottomHeight(0);
    skin.add(LIST_SELECTION_KEY, listSelection);

    Drawable tabButtonBackground = new TextureRegionDrawable(
            skin.get(TAB_BUTTON_BACKGROUND_KEY, TextureRegion.class));
    tabButtonBackground.setLeftWidth(5);
    tabButtonBackground.setRightWidth(5);
    tabButtonBackground.setTopHeight(0);
    tabButtonBackground.setBottomHeight(0);
    skin.add(TAB_BUTTON_BACKGROUND_KEY, tabButtonBackground);

    Drawable tabButtonBackgroundSelected = new TextureRegionDrawable(
            skin.get(TAB_BUTTON_SELECTED_KEY, TextureRegion.class));
    tabButtonBackgroundSelected.setLeftWidth(5);
    tabButtonBackgroundSelected.setRightWidth(5);
    tabButtonBackgroundSelected.setTopHeight(0);
    tabButtonBackgroundSelected.setBottomHeight(0);
    skin.add(TAB_BUTTON_SELECTED_KEY, tabButtonBackgroundSelected);

    Drawable titleBackground = new TextureRegionDrawable(skin.get(TITLE_BACKGROUND_KEY, TextureRegion.class));
    titleBackground.setLeftWidth(10);
    titleBackground.setRightWidth(10);
    titleBackground.setTopHeight(0);
    titleBackground.setBottomHeight(0);
    skin.add(TITLE_BACKGROUND_KEY, titleBackground);

    Drawable numberIncreaseDrawable = new TextureRegionDrawable(
            skin.get(NUMBER_SELECTOR_INCREASE_KEY, TextureRegion.class));
    numberIncreaseDrawable.setLeftWidth(0);
    numberIncreaseDrawable.setRightWidth(0);
    numberIncreaseDrawable.setTopHeight(0);
    numberIncreaseDrawable.setBottomHeight(0);
    skin.add(NUMBER_SELECTOR_INCREASE_KEY, numberIncreaseDrawable);

    Drawable numberDecreaseDrawable = new TextureRegionDrawable(
            skin.get(NUMBER_SELECTOR_DECREASE_KEY, TextureRegion.class));
    numberDecreaseDrawable.setLeftWidth(0);
    numberDecreaseDrawable.setRightWidth(0);
    numberDecreaseDrawable.setTopHeight(0);
    numberDecreaseDrawable.setBottomHeight(0);
    skin.add(NUMBER_SELECTOR_DECREASE_KEY, numberDecreaseDrawable);

    skin.add(DIALOG_BACKGROUND_KEY,
            skin.newDrawable(new TextureRegionDrawable(skin.get(DIALOG_BACKGROUND_KEY, TextureRegion.class)),
                    new Color(1.0f, 1.0f, 1.0f, 1.0f)));
    skin.add(POPUP_BACKGROUND_KEY,
            skin.newDrawable(new TextureRegionDrawable(skin.get(POPUP_BACKGROUND_KEY, TextureRegion.class)),
                    new Color(1.0f, 1.0f, 1.0f, 1.0f)));
    skin.add(LIST_BACKGROUND_KEY,
            skin.newDrawable(new TextureRegionDrawable(skin.get(LIST_BACKGROUND_KEY, TextureRegion.class)),
                    new Color(1.0f, 1.0f, 1.0f, 1.0f)));
    skin.add(LIST_SELECTION_KEY,
            skin.newDrawable(new TextureRegionDrawable(skin.get(LIST_SELECTION_KEY, TextureRegion.class)),
                    new Color(1.0f, 1.0f, 1.0f, 1.0f)));
    skin.add(CREDITS_BACKGROUND_KEY,
            skin.newDrawable(new TextureRegionDrawable(skin.get(CREDITS_BACKGROUND_KEY, TextureRegion.class)),
                    new Color(1.0f, 1.0f, 1.0f, 1.0f)));

    Drawable dropdownListBackground = skin.newDrawable(
            new TextureRegionDrawable(skin.get(DROP_DOWN_LIST_BACKGROUND, TextureRegion.class)),
            new Color(1, 1, 1, 1));
    dropdownListBackground.setLeftWidth(28);
    dropdownListBackground.setRightWidth(28);
    dropdownListBackground.setTopHeight(0);
    dropdownListBackground.setBottomHeight(0);
    skin.add(DROP_DOWN_LIST_BACKGROUND, dropdownListBackground);

    // Create a Label style for the title
    Label.LabelStyle titleStyle = new Label.LabelStyle();
    titleStyle.background = transparentDrawable;
    titleStyle.font = skin.getFont(TITLE_FONT_KEY);
    titleStyle.fontColor = new Color(Color.BLACK);
    skin.add(DEFAULT_KEY, titleStyle);

    // Fancy Character Label Style
    Label.LabelStyle fancyTitleStyle = new Label.LabelStyle();
    fancyTitleStyle.background = transparentDrawable;
    fancyTitleStyle.font = skin.getFont(TITLE_FANCY_FONT_KEY);
    fancyTitleStyle.fontColor = new Color(Color.BLACK);
    skin.add(FANCY_KEY, fancyTitleStyle);

    // Create a Label style for dialogs
    LabelStyle infoStyle = new LabelStyle();
    infoStyle.background = transparentDrawable;
    infoStyle.font = skin.getFont(INFO_LABEL_FONT_KEY);
    infoStyle.fontColor = new Color(Color.BLACK);
    skin.add(INFO_STYLE_KEY, infoStyle);

    // Default Button Style
    TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.up = textButtonBackground;
    textButtonStyle.down = textButtonBackgroundDown;
    textButtonStyle.checked = textButtonBackground;
    textButtonStyle.over = textButtonBackgroundDown;
    textButtonStyle.disabled = textButtonBackground;
    textButtonStyle.font = skin.getFont(BUTTON_FONT_KEY);
    textButtonStyle.fontColor = textButtonFontColor;
    textButtonStyle.disabledFontColor = new Color(0.3f, 0.3f, 0.3f, 1.0f);
    //        textButtonStyle.pressedOffsetX = 2f;
    //        textButtonStyle.pressedOffsetY = -3f;
    skin.add(DEFAULT_KEY, textButtonStyle);

    // Tab Button Style
    TextButtonStyle tabButtonStyle = new TextButtonStyle();
    tabButtonStyle.up = tabButtonBackground;
    tabButtonStyle.down = tabButtonBackground;
    tabButtonStyle.checked = tabButtonBackgroundSelected;
    tabButtonStyle.over = tabButtonBackground;
    tabButtonStyle.disabled = tabButtonBackground;
    tabButtonStyle.font = skin.getFont(BUTTON_FONT_KEY);
    tabButtonStyle.fontColor = textButtonFontColor;
    tabButtonStyle.overFontColor = textButtonFontColor;
    tabButtonStyle.disabledFontColor = new Color(Color.GRAY);
    skin.add(TAB_STYLE_KEY, tabButtonStyle);

    // Create a TextField style
    TextFieldStyle textFieldStyle = new TextFieldStyle();
    textFieldStyle.background = skin.newDrawable(SOLID_TEXTURE_KEY, new Color(0f, 0f, 0f, 0.1f));
    textFieldStyle.selection = skin.newDrawable(SOLID_TEXTURE_KEY, new Color(0f, 0f, 1f, 0.3f));
    textFieldStyle.cursor = skin.newDrawable(SOLID_TEXTURE_KEY, Color.BLACK);
    textFieldStyle.font = skin.getFont(TEXT_FIELD_FONT_KEY);
    textFieldStyle.fontColor = Color.BLACK;
    skin.add(DEFAULT_KEY, textFieldStyle);

    // Create a List style
    ListStyle listStyle = new ListStyle();
    listStyle.font = skin.getFont(LIST_FONT_KEY);
    listStyle.fontColorSelected = Color.BLACK;
    listStyle.fontColorUnselected = Color.BLACK;
    listStyle.selection = listSelection;
    listStyle.background = transparentDrawable;
    skin.add(DEFAULT_KEY, listStyle);

    // Create a Scroll Pane Style
    ScrollPaneStyle scrollPaneStyle = new ScrollPaneStyle();
    scrollPaneStyle.background = transparentDrawable;
    //        scrollPaneStyle.vScroll = skin.newDrawable(MainMenuScreen.SCROLL_BAR_VERTICAL_KEY);
    //        scrollPaneStyle.vScrollKnob = skin.newDrawable(MainMenuScreen.SCROLL_BAR_VERTICAL_KNOB_KEY);
    skin.add(DEFAULT_KEY, scrollPaneStyle);

    // Create a Dialog Style
    WindowStyle dialogStyle = new WindowStyle();
    dialogStyle.background = new SpriteDrawable(
            new Sprite(EuropaGame.game.getAssetManager().get(BACKGROUND_FILE_NAME, Texture.class)));
    dialogStyle.titleFont = skin.getFont(TITLE_FONT_KEY);
    dialogStyle.titleFontColor = new Color(Color.BLACK);
    skin.add(DEFAULT_KEY, dialogStyle);

    // Popup Dialog Style
    WindowStyle popupStyle = new WindowStyle();
    popupStyle.titleFont = skin.getFont(TITLE_FONT_KEY);
    popupStyle.titleFontColor = new Color(Color.BLACK);
    skin.add(POPUP_DIALOG_STYLE_KEY, popupStyle);

    // Create a Slider Skin
    SliderStyle sliderStyle = new SliderStyle();
    sliderStyle.background = new TextureRegionDrawable(skin.get(SLIDER_BACKGROUND_KEY, TextureRegion.class));
    sliderStyle.knob = new TextureRegionDrawable(skin.get(SLIDER_KNOB_KEY, TextureRegion.class));
    skin.add(DEFAULT_KEY, sliderStyle);

    // Create a Drop Down Menu Skin
    SelectBoxStyle selectBoxStyle = new SelectBoxStyle();
    selectBoxStyle.background = textButtonBackground;
    selectBoxStyle.backgroundOpen = textButtonBackgroundDown;
    selectBoxStyle.backgroundOver = textButtonBackgroundDown;
    selectBoxStyle.scrollStyle = scrollPaneStyle;
    selectBoxStyle.font = skin.getFont(TEXT_FIELD_FONT_KEY);
    selectBoxStyle.fontColor = textButtonFontColor;
    ListStyle selectBoxListStyle = new ListStyle();
    selectBoxListStyle.font = skin.getFont(LIST_FONT_KEY);
    selectBoxListStyle.fontColorSelected = textButtonFontColor;
    selectBoxListStyle.fontColorUnselected = textButtonFontColor;
    selectBoxListStyle.selection = skin.newDrawable(SOLID_TEXTURE_KEY, SELECTION_COLOR);
    selectBoxListStyle.background = dropdownListBackground;
    selectBoxStyle.listStyle = selectBoxListStyle;
    skin.add(DEFAULT_KEY, selectBoxStyle);

    // NumberSelectorStyle
    NumberSelectorStyle numberStyle = new NumberSelectorStyle();
    numberStyle.decrease = numberDecreaseDrawable;
    numberStyle.increase = numberIncreaseDrawable;
    numberStyle.minimumNumberSize = 50;
    numberStyle.numberLabelStyle = infoStyle;
    numberStyle.spacing = COMPONENT_SPACING;
    skin.add(DEFAULT_KEY, numberStyle);

    // AttributeSelectorStyle
    MultipleNumberSelectorStyle attrStyle = new MultipleNumberSelector.MultipleNumberSelectorStyle();
    attrStyle.labelStyle = infoStyle;
    attrStyle.numberSelectorStyle = numberStyle;
    attrStyle.spacing = COMPONENT_SPACING;
    skin.add(DEFAULT_KEY, attrStyle);

    mainMenuSkin = skin;
}

From source file:com.jupiter.europa.screen.overlay.PauseMenu.java

License:Open Source License

private static void buildPauseMenuSkin() {
    Skin skin = new Skin();

    skin.add("button-font", EuropaGame.game.getAssetManager()
            .get(FileLocations.FONTS_DIRECTORY.resolve(BUTTON_FONT).toString()));
    skin.add("title-font", EuropaGame.game.getAssetManager()
            .get(FileLocations.FONTS_DIRECTORY.resolve(TITLE_FONT).toString()));

    // Set the background texture
    Pixmap pixmap = new Pixmap(1, (int) 1, Pixmap.Format.RGB888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();//w ww .j a v a  2 s.c om
    skin.add("background", new Texture(pixmap));

    // Create a Label style for the title
    Label.LabelStyle titleStyle = new Label.LabelStyle();
    titleStyle.background = skin.newDrawable("background", TRANSPARENT);
    titleStyle.font = skin.getFont("title-font");
    titleStyle.fontColor = Color.BLACK;
    skin.add("default", titleStyle);

    //Create a button style
    TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("background", TRANSPARENT);
    textButtonStyle.down = skin.newDrawable("background", TRANSPARENT);
    textButtonStyle.checked = skin.newDrawable("background", TRANSPARENT);
    textButtonStyle.over = skin.newDrawable("background", TRANSPARENT);
    textButtonStyle.disabled = skin.newDrawable("background", TRANSPARENT);
    textButtonStyle.font = skin.getFont("button-font");
    textButtonStyle.fontColor = Color.TEAL;
    textButtonStyle.overFontColor = Color.YELLOW;
    textButtonStyle.disabledFontColor = Color.GRAY;
    textButtonStyle.pressedOffsetX = 2f;
    textButtonStyle.pressedOffsetY = -3f;
    skin.add("default", textButtonStyle);
    //        
    //        skin = EmergenceGame.game.getAssetManager().get(
    //                new File(FileLocations.SKINS_DIRECTORY, "main_menu.skin").getPath());
    pauseMenuSkin = skin;
}

From source file:com.kotcrab.vis.ui.contrib.widget.file.ImgScalrFileChooserIconProvider.java

License:Apache License

public Pixmap imageToPixmap(BufferedImage image) {
    final int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
    final int width = image.getWidth();
    final int height = image.getHeight();
    final boolean hasAlphaChannel = image.getAlphaRaster() != null;

    Pixmap pixmap = new Pixmap(width, height, hasAlphaChannel ? Pixmap.Format.RGBA8888 : Pixmap.Format.RGB888);

    if (hasAlphaChannel) {
        for (int pixel = 0, row = 0, col = 0; pixel < pixels.length; pixel++) {

            Color.argb8888ToColor(tmpColor, pixels[pixel]);
            pixmap.drawPixel(col, row, Color.rgba8888(tmpColor));

            col++;//from   w w  w  .  ja va2  s  .  c  om
            if (col == width) {
                col = 0;
                row++;
            }
        }
    } else {
        for (int pixel = 0, row = 0, col = 0; pixel < pixels.length; pixel++) {
            int color = pixels[pixel];
            tmpColor.r = ((color & 0x00ff0000) >>> 16) / 255f;
            tmpColor.g = ((color & 0x0000ff00) >>> 8) / 255f;
            tmpColor.b = ((color & 0x000000ff)) / 255f;
            tmpColor.a = 1f;

            pixmap.drawPixel(col, row, Color.rgba8888(tmpColor));

            col++;
            if (col == width) {
                col = 0;
                row++;
            }
        }
    }

    return pixmap;
}

From source file:com.kotcrab.vis.ui.widget.color.ColorChannelWidget.java

License:Apache License

public ColorChannelWidget(ColorPickerStyle style, String label, int maxValue, boolean useAlpha,
        final ColorChannelWidgetListener drawer) {
    super(true);/*www.j  av a2s  . com*/

    this.style = style;
    this.value = 0;
    this.maxValue = maxValue;
    this.drawer = drawer;
    this.useAlpha = useAlpha;

    barListener = new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            value = bar.getValue();
            drawer.updateFields();
            inputField.setValue(value);
        }
    };

    if (useAlpha)
        pixmap = new Pixmap(maxValue, 1, Format.RGBA8888);
    else
        pixmap = new Pixmap(maxValue, 1, Format.RGB888);

    texture = new Texture(pixmap);
    add(new VisLabel(label)).width(10).center();
    add(inputField = new ColorInputField(maxValue, new ColorInputFieldListener() {
        @Override
        public void changed(int newValue) {
            value = newValue;
            drawer.updateFields();
            bar.setValue(newValue);
        }
    })).width(ColorPicker.FIELD_WIDTH);
    add(bar = createBarImage()).size(ColorPicker.BAR_WIDTH, ColorPicker.BAR_HEIGHT);

    inputField.setValue(0);
}

From source file:com.kotcrab.vis.ui.widget.color.internal.PickerCommons.java

License:Apache License

private void createPixmap() {
    Pixmap whitePixmap = new Pixmap(2, 2, Format.RGB888);
    whitePixmap.setColor(Color.WHITE);
    whitePixmap.drawRectangle(0, 0, 2, 2);
    whiteTexture = new Texture(whitePixmap);
    whiteTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
    whitePixmap.dispose();//www. j av a 2 s.co  m
}

From source file:com.laststandstudio.space.Levels.Menus.MainMenu.java

License:Open Source License

public MainMenu(Game game) {
    super(game);/*  w w  w.  java 2s  .  c om*/
    SpaceShooter.mode = SpaceShooter.GameMode.MENU_MAIN;
    SpaceShooter.logger.logDebug("Main Menu: Creating Main Menu Screen");
    this.batch = new SpriteBatch();
    this.titleFont = super.loadFont("fonts/Gtek_Technology_free.ttf", (Gdx.graphics.getHeight() / 12));
    SpaceShooter.logger.logDebug("Main Menu: Creating Button Tables & Fonts");
    this.menuFont = new BitmapFont();
    this.pixmap = new Pixmap((Gdx.graphics.getWidth() / 2) - (Gdx.graphics.getWidth() / 10),
            (Gdx.graphics.getHeight() / 12), Pixmap.Format.RGB888);
    this.skin = new Skin();
    this.stage = new Stage();
    this.table = new Table();
    this.labelStyle = new Label.LabelStyle(titleFont, Color.BLACK);
    this.textButtonStyle = new TextButton.TextButtonStyle();

    skin.add("default", menuFont);
    pixmap.setColor(Color.MAROON);
    pixmap.fill();
    skin.add("background", new Texture(pixmap));

    SpaceShooter.logger.logDebug("Main Menu: Building Button Style");
    textButtonStyle.up = skin.newDrawable("background", Color.GRAY);
    textButtonStyle.down = skin.newDrawable("background", Color.DARK_GRAY);
    textButtonStyle.checked = skin.newDrawable("background", Color.DARK_GRAY);
    textButtonStyle.over = skin.newDrawable("background", Color.LIGHT_GRAY);
    textButtonStyle.font = skin.getFont("default");

    skin.add("default", textButtonStyle);

    SpaceShooter.logger.logDebug("Main Menu: Building Buttons");
    this.title = new Label("space shooter", labelStyle);
    this.btnSinglePlayer = new TextButton("Single Player", skin);
    this.btnMultiplayer = new TextButton("Multiplayer", skin);
    this.btnOptions = new TextButton("Options", skin);
    this.btnTexturePacks = new TextButton("Texture Packs", skin);
    this.btnMods = new TextButton("Mods", skin);
    this.btnExit = new TextButton("Exit", skin);
}

From source file:com.maplescot.loggerbill.game.world.StarryNight.java

License:Creative Commons License

public StarryNight() {
    int w = (int) Constants.VIEW_WIDTH;
    int h = (int) Constants.VIEW_HEIGHT;
    Gdx.app.log(TAG, "Generating stars...");
    skyImage = new Pixmap(w, h, Pixmap.Format.RGBA8888);
    skyImage.setColor(0, 0, 0, 1f);//from ww  w .j ava 2s . co  m
    skyImage.fillRectangle(0, 0, w, h);
    // Draw some stars
    for (int i = 0; i < 10000; i++) {
        float b = rnum.nextFloat(); // Brightness
        skyImage.setColor(b * .9f, b * 0.9f, b, 1f);
        skyImage.drawPixel(rnum.nextInt(w), rnum.nextInt(h));
    }

    skyTex = new Texture(skyImage, Pixmap.Format.RGBA8888, false);
    skyTex.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    moonX = (rnum.nextFloat() * Constants.VIEW_WIDTH) - (Constants.VIEW_WIDTH / 2);

}

From source file:com.mbrlabs.mundus.assets.EditorAssetManager.java

License:Apache License

public PixmapTextureAsset createPixmapTextureAsset(int size) throws IOException {
    String pixmapFilename = "pixmap_" + UUID.randomUUID().toString() + ".png";
    String metaFilename = pixmapFilename + ".meta";

    // create meta file
    String metaPath = FilenameUtils.concat(rootFolder.path(), metaFilename);
    MetaFile meta = createNewMetaFile(new FileHandle(metaPath), AssetType.PIXMAP_TEXTURE);

    // create pixmap
    String pixmapPath = FilenameUtils.concat(rootFolder.path(), pixmapFilename);
    Pixmap pixmap = new Pixmap(size, size, Pixmap.Format.RGBA8888);
    FileHandle pixmapAssetFile = new FileHandle(pixmapPath);
    PixmapIO.writePNG(pixmapAssetFile, pixmap);
    pixmap.dispose();/*  w w  w . ja  v a2s . co m*/

    // load & return asset
    PixmapTextureAsset asset = new PixmapTextureAsset(meta, pixmapAssetFile);
    asset.load();
    addAsset(asset);

    return asset;
}

From source file:com.mbrlabs.mundus.editor.tools.picker.BasePicker.java

License:Apache License

public Pixmap getFrameBufferPixmap(Viewport viewport) {
    int w = viewport.getScreenWidth();
    int h = viewport.getScreenHeight();
    int x = viewport.getScreenX();
    int y = viewport.getScreenY();
    final ByteBuffer pixelBuffer = BufferUtils.newByteBuffer(w * h * 4);

    Gdx.gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, fbo.getFramebufferHandle());
    Gdx.gl.glReadPixels(x, y, w, h, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE, pixelBuffer);
    Gdx.gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, 0);

    final int numBytes = w * h * 4;
    byte[] imgLines = new byte[numBytes];
    final int numBytesPerLine = w * 4;
    for (int i = 0; i < h; i++) {
        pixelBuffer.position((h - i - 1) * numBytesPerLine);
        pixelBuffer.get(imgLines, i * numBytesPerLine, numBytesPerLine);
    }//from   ww  w  . j  a va2  s. c  om

    Pixmap pixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888);
    BufferUtils.copy(imgLines, 0, pixmap.getPixels(), imgLines.length);

    return pixmap;
}