Java Code Examples for com.badlogic.gdx.graphics.Texture#setWrap()

The following examples show how to use com.badlogic.gdx.graphics.Texture#setWrap() . 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: VfxFrameBufferPool.java    From gdx-vfx with Apache License 2.0 6 votes vote down vote up
public void setTextureParams(Texture.TextureWrap textureWrapU,
                             Texture.TextureWrap textureWrapV,
                             Texture.TextureFilter textureFilterMin,
                             Texture.TextureFilter textureFilterMag) {
    this.textureWrapU = textureWrapU;
    this.textureWrapV = textureWrapV;
    this.textureFilterMin = textureFilterMin;
    this.textureFilterMag = textureFilterMag;

    // Update the free textures'.
    for (int i = 0; i < freeBuffers.size; i++) {
        Texture texture = freeBuffers.get(i).getTexture();
        texture.setWrap(textureWrapU, textureWrapV);
        texture.setFilter(textureFilterMin, textureFilterMag);
    }
}
 
Example 2
Source File: DC6.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Override
public void loadDirection(int d, boolean combineFrames) {
  if (textures == null) textures = new Texture[header.directions][];
  else if (textures[d] != null) return;
  preloadDirection(d, combineFrames);

  Pixmap[] pixmaps = this.pixmaps[d];
  textures[d] = new Texture[pixmaps.length];
  for (int p = 0; p < pixmaps.length; p++) {
    Pixmap pixmap = pixmaps[p];
    Texture texture = new Texture(new PixmapTextureData(pixmap, null, false, false, false));
    //texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    texture.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
    textures[d][p] = texture;
  }

  regions[d] = new TextureRegion[pixmaps.length];
  for (int p = 0; p < pixmaps.length; p++) {
    regions[d][p] = new TextureRegion(textures[d][p]);
  }
}
 
Example 3
Source File: Palette.java    From riiablo with Apache License 2.0 6 votes vote down vote up
/**
 * Renders a pixmap as a sheet with each pixel taking {@code cellsize} square pixels. Used to show
 * a more user-readable representation of the palette.
 */
public Texture render(int cellsize) {
  final int cells   = 16;
  final int size    = cells * cellsize;
  final int rows    = cells;
  final int columns = cells;

  Pixmap pixmap = new Pixmap(size, size, Pixmap.Format.RGBA8888);
  for (int r = 0, i = 0, x = 0, y = 0; r < rows; r++, x = 0, y += cellsize) {
    for (int c = 0; c < columns; c++, i++, x += cellsize) {
      pixmap.setColor(colors[i] | 0xFF); // Removes alpha transparency
      pixmap.fillRectangle(x, y, cellsize, cellsize);
    }
  }

  Texture texture = new Texture(pixmap);
  texture.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
  pixmap.dispose();
  return texture;
}
 
Example 4
Source File: DCC.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@Override
public void loadDirection(int d, boolean combineFrames) {
  if (textures == null) textures = new Texture[header.directions][];
  else if (textures[d] != null) return;
  preloadDirection(d);

  textures[d] = new Texture[header.framesPerDir];
  for (int f = 0; f < header.framesPerDir; f++) {
    Pixmap pixmap = frames[d][f].pixmap;
    Texture texture = new Texture(new PixmapTextureData(pixmap, null, false, false, false));
    //texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    texture.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
    textures[d][f] = texture;
  }

  regions[d] = new TextureRegion[header.framesPerDir];
  for (int f = 0; f < header.framesPerDir; f++) {
    regions[d][f] = new TextureRegion(textures[d][f]);
  }
}
 
Example 5
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 6
Source File: PL2.java    From riiablo with Apache License 2.0 6 votes vote down vote up
public Texture render(Palette palette) {
  int[] colors = palette.get();
  Pixmap pl2Pixmap = new Pixmap(Palette.COLORS, size, Pixmap.Format.RGBA8888);
  IntBuffer buffer = pl2Pixmap.getPixels().asIntBuffer();
  for (int i = 0, j = 0; i < size; i++) {
    for (int k = 0; k < Palette.COLORS; k++) {
      buffer.put(j++, colors[colormaps[i][k] & 0xFF]);
    }
  }

  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 7
Source File: VfxFrameBufferPool.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
/** Called when a buffer is freed to clear the state of the buffer for possible later reuse. */
protected void resetBuffer(VfxFrameBuffer buffer) {
    buffer.clearRenderers();

    // Reset texture params to the default ones.
    Texture texture = buffer.getTexture();
    texture.setWrap(textureWrapU, textureWrapV);
    texture.setFilter(textureFilterMin, textureFilterMag);
}
 
Example 8
Source File: VfxFrameBufferQueue.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
/**
 * Restores buffer OpenGL parameters. Could be useful in case of OpenGL context loss.
 */
public void rebind() {
    for (int i = 0; i < buffers.size; i++) {
        VfxFrameBuffer wrapper = buffers.get(i);
        // FBOs might be null if the instance wasn't initialized with #resize(int, int) yet.
        if (wrapper.getFbo() == null) continue;

        Texture texture = wrapper.getFbo().getColorBufferTexture();
        texture.setWrap(wrapU, wrapV);
        texture.setFilter(filterMin, filterMag);
    }
}
 
Example 9
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 10
Source File: DT1.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void prepareTextures() {
  if (!loadData) return;
  Validate.validState(textures == null, "textures have already been prepared");
  textures = new Texture[header.numTiles];
  for (int i = 0; i < header.numTiles; i++) {
    Texture texture = new Texture(new PixmapTextureData(tiles[i].pixmap, null, false, false, false));
    //texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    texture.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
    tiles[i].texture = new TextureRegion(textures[i] = texture);
  }
}
 
Example 11
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 12
Source File: TextureUtils.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public static Texture loadMipmapTexture(FileHandle fileHandle, boolean tilable) {
    Texture texture = new Texture(fileHandle, true);
    texture.setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.MipMapLinearLinear);

    if (tilable) {
        texture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
    }

    return texture;
}
 
Example 13
Source File: PickerCommons.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 14
Source File: HeightMapModel.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
public HeightMapModel(HeightMap hm) {
	this.heightMap = hm;
	String groundTexName = "textures/hm_paint.png";
	groundTexture = new Texture(Gdx.files.internal(groundTexName), true);
	groundTexture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
	groundTexture.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.Linear);
	groundMat = new Material(TextureAttribute.createDiffuse(groundTexture)
			, ColorAttribute.createSpecular(specular)
	);
	createGround();
}
 
Example 15
Source File: LibgdxFrameBufferWrapper.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
@Override
protected Texture createTexture(FrameBufferTextureAttachmentSpec attachmentSpec) {
	GLOnlyTextureData data = new GLOnlyTextureData(bufferBuilder.width, bufferBuilder.height, 0, attachmentSpec.internalFormat, attachmentSpec.format, attachmentSpec.type);
	Texture result = new LibgdxTexture(data);
	result.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
	result.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
	return result;
}
 
Example 16
Source File: ServerConnectGUI.java    From Radix with MIT License 4 votes vote down vote up
@Override
public void init() {
    stage = new Stage();

    // TODO memory manage

    background = new Texture(Gdx.files.internal("textures/block/obsidian.png"));
    background.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);

    errorLabel = new Label(null, new LabelStyle(new BitmapFont(), Color.RED));

    TextFieldStyle fieldStyle = new TextFieldStyle();
    fieldStyle.font = new BitmapFont();
    fieldStyle.fontColor = Color.WHITE;
    TextField ipField = new TextField("IP:Port", fieldStyle);

    ImageTextButtonStyle btnStyle = RadixClient.getInstance().getSceneTheme().getButtonStyle();

    TextButton connectButton = new TextButton("Connect", btnStyle);
    connectButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            String[] ipPort = ipField.getText().split(":");

            if(ipPort.length != 2) {
                invalidIpSyntax();
                return;
            }

            try {
                RadixClient.getInstance().enterRemoteWorld(ipPort[0], Short.parseShort(ipPort[1]));
            } catch (NumberFormatException ex) {
                invalidPort();
            }
        }
    });

    Table table = new Table();
    table.setFillParent(true);
    table.add(ipField);
    table.row();
    table.add(errorLabel);
    table.row();
    table.add(connectButton);
    stage.addActor(table);
}