Java Code Examples for com.badlogic.gdx.graphics.Pixmap#dispose()

The following examples show how to use com.badlogic.gdx.graphics.Pixmap#dispose() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FacedMultiCubemapData.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
@Override
public void consumeCubemapData () {
	for(int level = 0 ; level<levels ; level++){
		for (int i = 0; i < 6; i++) {
			int index = level * 6 + i;
			if (data[index].getType() == TextureData.TextureDataType.Custom) {
				data[index].consumeCustomData(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
			} else {
				Pixmap pixmap = data[index].consumePixmap();
				boolean disposePixmap = data[index].disposePixmap();
				if (data[index].getFormat() != pixmap.getFormat()) {
					Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), data[index].getFormat());
					tmp.setBlending(Blending.None);
					tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight());
					if (data[index].disposePixmap()) pixmap.dispose();
					pixmap = tmp;
					disposePixmap = true;
				}
				Gdx.gl.glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 1);
				Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, level, pixmap.getGLInternalFormat(), pixmap.getWidth(),
					pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels());
				if (disposePixmap) pixmap.dispose();
			}
		}
	}
}
 
Example 2
Source File: ScreenshotService.java    From talos with Apache License 2.0 6 votes vote down vote up
private void takeScreenshot() {
    byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), true);

    float scaleX = (float)Gdx.graphics.getBackBufferWidth()/Gdx.graphics.getWidth();
    float scaleY = (float)Gdx.graphics.getBackBufferHeight()/Gdx.graphics.getHeight();

    // This loop makes sure the whole screenshot is opaque and looks exactly like what the user is seeing
    for (int i = 4; i < pixels.length; i += 4) {
        pixels[i - 1] = (byte) 255;
    }

    Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888);
    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);

    color.set(pixmap.getPixel((int)(posX * scaleX), (int)(posY * scaleY)));

    pixmap.dispose();
}
 
Example 3
Source File: GLTFBinaryExporter.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
public void export(GLTFImage image, Texture texture, String baseName) {
	String fileName = baseName + ".png";
	image.uri = fileName;
	FileHandle file = folder.child(fileName);
	FrameBuffer fbo = new FrameBuffer(texture.getTextureData().getFormat(), texture.getWidth(), texture.getHeight(), false);
	fbo.begin();
	Gdx.gl.glClearColor(0, 0, 0, 0);
	Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
	SpriteBatch batch = new SpriteBatch();
	batch.getProjectionMatrix().setToOrtho2D(0, 0, 1, 1);
	batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
	batch.begin();
	batch.draw(texture, 0, 0, 1, 1, 0, 0, 1, 1);
	batch.end();
	Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, texture.getWidth(), texture.getHeight());
	fbo.end();
	batch.dispose();
	fbo.dispose();
	savePNG(file, pixmap);
	pixmap.dispose();
}
 
Example 4
Source File: PL2.java    From riiablo with Apache License 2.0 6 votes vote down vote up
public Texture render() {
  Pixmap pl2Pixmap = new Pixmap(Palette.COLORS, size, Pixmap.Format.RGBA8888);
  ByteBuffer buffer = pl2Pixmap.getPixels();
  for (int i = 0, j = 0; i < size; i++) {
    //buffer.put(colormaps[i]);
    for (int k = 0; k < Palette.COLORS; k++, j += 4) {
      buffer.put(j, colormaps[i][k]);
    }
  }

  buffer.rewind();
  Texture texture = new Texture(pl2Pixmap);
  //texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
  texture.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
  pl2Pixmap.dispose();
  return texture;
}
 
Example 5
Source File: BGDrawer.java    From libGDX-Path-Editor with Apache License 2.0 5 votes vote down vote up
public BGDrawer() {
	renderer = new ShapeRenderer();
	
	Pixmap p = new Pixmap(4, 4, Format.RGBA4444);
	p.setColor(0.698f, 0.698f, 0.698f, 1f);
	p.fill();
	overlay = new Texture(p);
	p.dispose();
	
	t = new Sprite(overlay);
	b = new Sprite(overlay);
	l = new Sprite(overlay);
	r = new Sprite(overlay);
}
 
Example 6
Source File: Palette.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public Texture render() {
  Pixmap palettePixmap = new Pixmap(COLORS, 1, Pixmap.Format.RGBA8888);
  palettePixmap.getPixels().asIntBuffer().put(colors);
  Texture texture = new Texture(palettePixmap);
  //texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
  texture.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
  palettePixmap.dispose();
  return texture;
}
 
Example 7
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Loads an image
 *
 * @param image
 * @return
 * @throws Exception
 */
public static Pixmap loadPixmap(String image, int width, int height) {        
    Pixmap pixmap = new Pixmap(Gdx.files.internal(image));
    Pixmap result = pixmap;
    if(pixmap.getWidth() != width || pixmap.getHeight() != height) {
        result = resizePixmap(pixmap, width, height);
        pixmap.dispose();
    }
    
    return result;
}
 
Example 8
Source File: LaneRenderer.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public LaneRenderer(BMSPlayer main, BMSModel model) {

		this.main = main;
		Pixmap hp = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
		hp.drawPixel(0, 0, Color.toIntBits(255, 255, 255, 255));
		blank = new TextureRegion(new Texture(hp));
		hp.dispose();

		FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
				Gdx.files.internal("skin/default/VL-Gothic-Regular.ttf"));
		FreeTypeFontParameter parameter = new FreeTypeFontParameter();
		parameter.size = 18;
		font = generator.generateFont(parameter);
		generator.dispose();

		this.skin = (PlaySkin) main.getSkin();
		this.conf = main.main.getPlayerResource().getConfig();
		this.config = main.main.getPlayerResource().getPlayerConfig();
		this.playconfig = config.getPlayConfig(model.getMode()).getPlayconfig().clone();

		init(model);

		for (CourseData.CourseDataConstraint i : main.main.getPlayerResource().getConstraint()) {
			if (i == NO_SPEED) {
				playconfig.setHispeed(1.0f);
				playconfig.setLanecover(0);
				playconfig.setLift(0);
				playconfig.setHidden(0);
			}
		}
	}
 
Example 9
Source File: Textures.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public Texture createTexture(Color color) {
  Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
  pixmap.setColor(color);
  pixmap.fill();
  Texture texture = new Texture(pixmap);
  pixmap.dispose();
  return texture;
}
 
Example 10
Source File: ShapeTextureCache.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a filled rectangular texture for the provided {@link LibgdxColor}
 *
 * @param color
 *            The {@link LibgdxColor} to fetch a texture of
 * @return A new {@link Texture} if this is first time it has been
 *         requested, otherwise it will return a cached instance of the
 *         {@link Texture} for the given {@link LibgdxColor}
 */
public Texture getFilledRectangleTexture(LibgdxColor color) {
	int bits = color.color.toIntBits();
	if (!filledRectangleTextures.containsKey(bits)) {
		Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
		pixmap.setColor(color.color);
		pixmap.fillRectangle(0, 0, 1, 1);
		filledRectangleTextures.put(bits, new Texture(pixmap));
		pixmap.dispose();
	}
	return filledRectangleTextures.get(bits);
}
 
Example 11
Source File: BitmapCache.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void clear() {
	for (Pixmap bmp:values()) {
		bmp.dispose();
	}
	super.clear();
}
 
Example 12
Source File: Ssao.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
/** Computes random field for the ssao shader */
private void createRandomField (int width, int height, Format format) {
	randomField = new Texture(width, height, format);
	randomField.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
	randomField.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);

	Pixmap pixels = new Pixmap(width, height, format);
	ByteBuffer bytes = pixels.getPixels();
	int wrote = 0;

	while (wrote < width * height * 4) {
		float x = (MathUtils.random() - 0.5f) * 2.0f;
		float y = (MathUtils.random() - 0.5f) * 2.0f;
		float z = (MathUtils.random() - 0.5f) * 2.0f;
		float l = (float)Math.sqrt(x * x + y * y + z * z);
		if (l <= 1.0f && l > 0.1f) {
			x = (x + 1.0f) * 0.5f;
			y = (y + 1.0f) * 0.5f;
			z = (z + 1.0f) * 0.5f;
			bytes.put((byte)(x * 255f));
			bytes.put((byte)(y * 255f));
			bytes.put((byte)(z * 255f));
			bytes.put((byte)255);
			wrote += 4;
		}
	}

	bytes.flip();
	randomField.draw(pixels, 0, 0);
	pixels.dispose();
}
 
Example 13
Source File: BitmapCache.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void clear() {
	for (Pixmap bmp:values()) {
		bmp.dispose();
	}
	super.clear();
}
 
Example 14
Source File: Utils.java    From skin-composer with MIT License 4 votes vote down vote up
public static Color averageColor(FileHandle file) {
    Pixmap pixmap = new Pixmap(file);
    Color returnValue = averageColor(pixmap);
    pixmap.dispose();
    return returnValue;
}
 
Example 15
Source File: MainMenuScreen.java    From Bomberman_libGdx with MIT License 4 votes vote down vote up
@Override
public void show() {
    viewport = new FitViewport(640, 480);
    stage = new Stage(viewport, batch);

    font = new BitmapFont(Gdx.files.internal("fonts/foo.fnt"));

    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);

    Label titleLabel = new Label("Bomberman", labelStyle);
    titleLabel.setFontScale(1.6f);
    titleLabel.setPosition(140, 360);

    Label easyLabel = new Label("Easy", labelStyle);
    easyLabel.setPosition((640 - easyLabel.getWidth()) / 2, 240);

    Label normalLabel = new Label("Normal", labelStyle);
    normalLabel.setPosition((640 - normalLabel.getWidth()) / 2, 180);

    Label hardLabel = new Label("Hard", labelStyle);
    hardLabel.setPosition((640 - hardLabel.getWidth()) / 2, 120);

    Pixmap pixmap = new Pixmap(640, 480, Pixmap.Format.RGB888);
    pixmap.setColor(240.0f / 255.0f, 128 / 255.0f, 0, 1.0f);
    pixmap.fill();
    backgroundTexture = new Texture(pixmap);
    pixmap.dispose();
    Image background = new Image(backgroundTexture);

    indicatorX = 160f;
    indicatorY = 240f;

    TextureAtlas textureAtlas = GameManager.getInstance().getAssetManager().get("img/actors.pack", TextureAtlas.class);
    indicator0 = new Image(new TextureRegion(textureAtlas.findRegion("MainMenuLogo"), 0, 0, 40, 26));
    indicator0.setSize(80f, 52f);
    indicator0.setPosition(indicatorX, indicatorY);

    indicator1 = new Image(new TextureRegion(textureAtlas.findRegion("MainMenuLogo"), 40, 0, 40, 26));
    indicator1.setSize(80f, 52f);
    indicator1.setPosition(indicatorX, indicatorY);
    indicator1.setVisible(false);
    
    indicationsTexture = new Texture("img/indications.png");
    indications = new Image(indicationsTexture);
    indications.setPosition(640f - indications.getWidth() - 12f, 12f);

    stage.addActor(background);
    stage.addActor(indications);
    stage.addActor(titleLabel);
    stage.addActor(easyLabel);
    stage.addActor(normalLabel);
    stage.addActor(hardLabel);
    stage.addActor(indicator0);
    stage.addActor(indicator1);

    currentSelection = 0;
    selected = false;
    
    GameManager.getInstance().playMusic("SuperBomberman-Title.ogg", true);
}
 
Example 16
Source File: PixmapResourcePool.java    From beatoraja with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void dispose(Pixmap resource) {
	resource.dispose();
}
 
Example 17
Source File: ShareChallenge.java    From Klooni1010 with GNU General Public License v3.0 4 votes vote down vote up
public boolean saveChallengeImage(final int score, final boolean timeMode) {
    final File saveAt = getShareImageFilePath();
    if (!saveAt.getParentFile().isDirectory())
        if (!saveAt.mkdirs())
            return false;

    final FileHandle output = new FileHandle(saveAt);

    final Texture shareBase = new Texture(Gdx.files.internal("share.png"));
    final int width = shareBase.getWidth();
    final int height = shareBase.getHeight();

    final FrameBuffer frameBuffer = new FrameBuffer(Pixmap.Format.RGB888, width, height, false);
    frameBuffer.begin();

    // Render the base share texture
    final SpriteBatch batch = new SpriteBatch();
    final Matrix4 matrix = new Matrix4();
    matrix.setToOrtho2D(0, 0, width, height);
    batch.setProjectionMatrix(matrix);

    Gdx.gl.glClearColor(Color.GOLD.r, Color.GOLD.g, Color.GOLD.b, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    batch.begin();
    batch.draw(shareBase, 0, 0);

    // Render the achieved score
    final Label.LabelStyle style = new Label.LabelStyle();
    style.font = new BitmapFont(Gdx.files.internal("font/x1.0/geosans-light64.fnt"));
    Label label = new Label("just scored " + score + " on", style);
    label.setColor(Color.BLACK);
    label.setPosition(40, 500);
    label.draw(batch, 1);

    label.setText("try to beat me if you can");
    label.setPosition(40, 40);
    label.draw(batch, 1);

    if (timeMode) {
        Texture timeModeTexture = new Texture("ui/x1.5/stopwatch.png");
        batch.setColor(Color.BLACK);
        batch.draw(timeModeTexture, 200, 340);
    }

    batch.end();

    // Get the framebuffer pixels and write them to a local file
    final byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, width, height, true);

    final Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);

    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
    PixmapIO.writePNG(output, pixmap);

    // Dispose everything
    pixmap.dispose();
    shareBase.dispose();
    batch.dispose();
    frameBuffer.end();

    return true;
}
 
Example 18
Source File: Hud.java    From Bomberman_libGdx with MIT License 4 votes vote down vote up
public Hud(SpriteBatch batch, float width, float height) {
    this.batch = batch;

    AssetManager assetManager = GameManager.getInstance().getAssetManager();
    textureAtlas = assetManager.get("img/actors.pack", TextureAtlas.class);
    bombSprite = new Sprite(new TextureRegion(textureAtlas.findRegion("Bomb"), 0, 0, 16, 16));
    bombSprite.setBounds(15.0f, 11.5f, 1, 1);

    Pixmap pixmap = new Pixmap(5, 15, Pixmap.Format.RGBA8888);
    pixmap.setColor(240.0f / 255.0f, 128 / 255.0f, 0, 1.0f);
    pixmap.fill();

    bgTexture = new Texture(pixmap);

    pixmap.setColor(1, 1, 1, 1);
    pixmap.fill();
    bombTimerTexture = new Texture(pixmap);
    pixmap.dispose();

    bombTimerSprite = new Sprite(bombTimerTexture);
    bombTimerSprite.setBounds(16f, 12.5f, 3.0f, 0.2f);

    TextureRegion itemTextureRegion = textureAtlas.findRegion("Items");
    powerSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 1, 0, 16, 16));
    powerSprite.setBounds(leftAlignment, 9.0f, 1, 1);

    speedSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 2, 0, 16, 16));
    speedSprite.setBounds(leftAlignment, 8.0f, 1, 1);

    kickSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 3, 0, 16, 16));
    kickSprite.setBounds(leftAlignment, 7.0f, 1, 1);

    remoteSprite = new Sprite(new TextureRegion(itemTextureRegion, 16 * 4, 0, 16, 16));
    remoteSprite.setBounds(leftAlignment, 6.0f, 1, 1);

    Array<TextureRegion> keyFrames = new Array<TextureRegion>();
    for (int i = 0; i < 5; i++) {
        keyFrames.add(new TextureRegion(textureAtlas.findRegion("Bomberman_big"), 32 * i, 0, 32, 48));
    }
    bigBombermanAnimation = new Animation(0.2f, keyFrames, Animation.PlayMode.LOOP_PINGPONG);
    bigBombermanSprite = new Sprite(bigBombermanAnimation.getKeyFrame(0));
    bigBombermanSprite.setBounds(17.5f, 0.5f, 2f, 3f);
    stateTime = 0;

    FitViewport viewport = new FitViewport(width * SCALE, height * SCALE);
    stage = new Stage(viewport, batch);
    font = new BitmapFont(Gdx.files.internal("fonts/foo.fnt"));
    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);
    fpsLabel = new Label("FPS:", labelStyle);
    fpsLabel.setFontScale(0.3f);
    fpsLabel.setPosition(16 * SCALE, -0.8f * SCALE);
    fpsLabel.setVisible(showFPS);
    
    levelLabel = new Label("Level", labelStyle);
    levelLabel.setPosition(15.5f * SCALE, 3 * SCALE);
    levelLabel.setFontScale(0.4f);

    playerLivesLabel = new Label("" + GameManager.playerLives, labelStyle);
    playerLivesLabel.setFontScale(0.5f);
    playerLivesLabel.setPosition(16.8f * SCALE, 12.8f * SCALE);

    Image bombermanImage = new Image(new TextureRegion(textureAtlas.findRegion("Items"), 16 * 5, 0, 16, 16));
    bombermanImage.setPosition(leftAlignment * SCALE, 13.5f * SCALE);

    xLabel = new Label("X", labelStyle);
    xLabel.setFontScale(0.4f);
    xLabel.setPosition(16.8f * SCALE, 6.3f * SCALE);

    zLabel = new Label("Z", labelStyle);
    zLabel.setFontScale(0.4f);
    zLabel.setPosition(16.8f * SCALE, 5.3f * SCALE);

    stage.addActor(fpsLabel);
    stage.addActor(levelLabel);
    stage.addActor(playerLivesLabel);
    stage.addActor(bombermanImage);
    stage.addActor(xLabel);
    stage.addActor(zLabel);
    
    stringBuilder = new StringBuilder();
    
}
 
Example 19
Source File: CCScrollView.java    From cocos-ui-libgdx with Apache License 2.0 4 votes vote down vote up
@Override
public Actor parse(CocoStudioUIEditor editor, ObjectData widget) {
    ScrollPaneStyle style = new ScrollPaneStyle();

    if (widget.getFileData() != null) {

        style.background = editor
            .findDrawable(widget, widget.getFileData());
    }

    ScrollPane scrollPane = new ScrollPane(null, style);

    if ("Vertical_Horizontal".equals(widget.getScrollDirectionType())) {
        scrollPane.setForceScroll(true, true);
    } else if ("Horizontal".equals(widget.getScrollDirectionType())) {
        scrollPane.setForceScroll(true, false);
    } else if ("Vertical".equals(widget.getScrollDirectionType())) {
        scrollPane.setForceScroll(false, true);
    }

    scrollPane.setClamp(widget.isClipAble());
    scrollPane.setFlickScroll(widget.isIsBounceEnabled());

    Table table = new Table();
    table.setSize(widget.getInnerNodeSize().getWidth(), widget
        .getInnerNodeSize().getHeight());

    if (widget.getComboBoxIndex() == 0) {// 无颜色

    } else if (widget.getComboBoxIndex() == 1) {// 单色

        Pixmap pixmap = new Pixmap((int) table.getWidth(),
            (int) table.getHeight(), Format.RGBA8888);
        Color color = editor.getColor(widget.getSingleColor(),
            widget.getBackColorAlpha());

        pixmap.setColor(color);

        pixmap.fill();

        Drawable drawable = new TextureRegionDrawable(new TextureRegion(
            new Texture(pixmap)));

        table.setBackground(drawable);
        pixmap.dispose();

    }
    scrollPane.setWidget(table);
    return scrollPane;
}
 
Example 20
Source File: CCParticleActor.java    From cocos-ui-libgdx with Apache License 2.0 4 votes vote down vote up
public static Texture getDefaultTexture() {
    Pixmap pImage = new Pixmap(__firePngData, 0, __firePngData.length);
    Texture texture = new Texture(pImage);
    pImage.dispose();
    return texture;
}