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

The following examples show how to use com.badlogic.gdx.graphics.Texture#setFilter() . 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: GameOver.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
public GameOver (Invaders invaders) {
	super(invaders);
	spriteBatch = new SpriteBatch();
	background = new Texture(Gdx.files.internal("data/planet.jpg"));
	background.setFilter(TextureFilter.Linear, TextureFilter.Linear);

	logo = new Texture(Gdx.files.internal("data/title.png"));
	logo.setFilter(TextureFilter.Linear, TextureFilter.Linear);

	font = new BitmapFont(Gdx.files.internal("data/font16.fnt"), Gdx.files.internal("data/font16.png"), false);

	if (invaders.getController() != null) {
		invaders.getController().addListener(new ControllerAdapter() {
			@Override
			public boolean buttonUp(Controller controller,
					int buttonIndex) {
				controller.removeListener(this);
				isDone = true;
				return false;
			}
		});
	}
}
 
Example 3
Source File: MainMenu.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
public MainMenu (Invaders invaders) {
	super(invaders);

	spriteBatch = new SpriteBatch();
	background = new Texture(Gdx.files.internal("data/planet.jpg"));
	background.setFilter(TextureFilter.Linear, TextureFilter.Linear);

	logo = new Texture(Gdx.files.internal("data/title.png"));
	logo.setFilter(TextureFilter.Linear, TextureFilter.Linear);

	font = new BitmapFont(Gdx.files.internal("data/font16.fnt"), Gdx.files.internal("data/font16.png"), false);

	if (invaders.getController() != null) {
		invaders.getController().addListener(new ControllerAdapter() {
			@Override
			public boolean buttonUp(Controller controller, int buttonIndex) {
				controller.removeListener(this);
				isDone = true;
				return false;
			}
		});
	}
}
 
Example 4
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 5
Source File: CreditsScreen.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
private void retrieveAssets() {
	style = ui.getSkin().get(CreditScreenStyle.class);

	final Locale locale = Locale.getDefault();

	String localeFilename = MessageFormat.format("{0}_{1}.txt", CREDITS_FILENAME, locale.getLanguage());

	if (!EngineAssetManager.getInstance().assetExists(localeFilename))
		localeFilename = MessageFormat.format("{0}.txt", CREDITS_FILENAME);

	BufferedReader reader = EngineAssetManager.getInstance().getAsset(localeFilename).reader(4096, "utf-8");

	try {
		String line;
		while ((line = reader.readLine()) != null) {
			credits.add(line);
		}
	} catch (Exception e) {
		EngineLogger.error(e.getMessage());

		ui.setCurrentScreen(Screens.MENU_SCREEN);
	}

	scrollY += style.titleFont.getLineHeight();

	// Load IMAGES
	for (String s : credits) {
		if (s.indexOf('#') != -1 && s.charAt(0) == 'i') {
			s = s.substring(2);

			Texture tex = new Texture(EngineAssetManager.getInstance().getResAsset("ui/" + s));
			tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);

			images.put(s, tex);
		}
	}
}
 
Example 6
Source File: DebugStatistics.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private void init (int width, int height, float updateHz) {
	// assert (width < 256 && height < 256);

	final float oneOnUpdHz = 1f / updateHz;

	PanelWidth = width;
	PanelHeight = height;
	intervalNs = (long)(1000000000L * oneOnUpdHz);

	pixels = new Pixmap(PanelWidth, PanelHeight, Format.RGBA8888);
	texture = new Texture(width, height, Format.RGBA8888);
	texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
	region = new TextureRegion(texture, 0, 0, pixels.getWidth(), pixels.getHeight());

	// create data
	dataRenderTime = new float[PanelWidth];
	dataFps = new float[PanelWidth];
	dataPhysicsTime = new float[PanelWidth];
	dataTimeAliasing = new float[PanelWidth];

	// precompute constants
	ratio_rtime = ((float)PanelHeight / 2f) * Config.Physics.TimestepHz;
	ratio_ptime = ((float)PanelHeight / 2f) * Config.Physics.TimestepHz;
	ratio_fps = ((float)PanelHeight / 2f) * oneOnUpdHz;

	reset();
}
 
Example 7
Source File: DebugMeter.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public DebugMeter (int width, int height) {
	assert (width < 256 && height < 256);

	this.showLabel = true;
	this.name = "";
	this.width = width;
	this.height = height;
	this.pos = new Vector2();

	pixels = new Pixmap(this.width, this.height, Format.RGBA8888);
	texture = new Texture(width, height, Format.RGBA8888);
	texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
	region = new TextureRegion(texture, 0, 0, pixels.getWidth(), pixels.getHeight());
}
 
Example 8
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 9
Source File: Art.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public static Texture getFlag (String countryCode) {
	String filename = countryCode + ".png";
	FileHandle zip = Gdx.files.internal("data/flags.zip");
	ZipInputStream zin = new ZipInputStream(zip.read());
	ZipEntry ze = null;
	try {
		while ((ze = zin.getNextEntry()) != null) {
			if (ze.getName().equals(filename)) {
				ByteArrayOutputStream streamBuilder = new ByteArrayOutputStream();
				int bytesRead;
				byte[] tempBuffer = new byte[8192 * 2];
				while ((bytesRead = zin.read(tempBuffer)) != -1) {
					streamBuilder.write(tempBuffer, 0, bytesRead);
				}

				Pixmap px = new Pixmap(streamBuilder.toByteArray(), 0, streamBuilder.size());

				streamBuilder.close();
				zin.close();

				boolean mipMap = false;
				Texture t = new Texture(px);

				if (mipMap) {
					t.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Nearest);
				} else {
					t.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
				}

				px.dispose();
				return t;
			}
		}
	} catch (IOException e) {
	}

	return null;
}
 
Example 10
Source File: Art.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public static Texture newTexture (String name, boolean mipMap) {
	Texture t = new Texture(Gdx.files.internal(name), Format.RGBA8888, mipMap);

	if (mipMap) {
		t.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Nearest);
	} else {
		t.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
	}

	return t;
}
 
Example 11
Source File: SmartFontGenerator.java    From gdx-smart-font with MIT License 5 votes vote down vote up
/** Convenience method for generating a font, and then writing the fnt and png files.
 * Writing a generated font to files allows the possibility of only generating the fonts when they are missing, otherwise
 * loading from a previously generated file.
 * @param fontFile
 * @param fontSize
 */
private BitmapFont generateFontWriteFiles(String fontName, FileHandle fontFile, int fontSize, int pageWidth, int pageHeight) {
	FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);

	PixmapPacker packer = new PixmapPacker(pageWidth, pageHeight, Pixmap.Format.RGBA8888, 2, false);
	FreeTypeFontParameter parameter = new FreeTypeFontParameter();
	parameter.size = fontSize;
	parameter.characters = FreeTypeFontGenerator.DEFAULT_CHARS;
	parameter.flip = false;
	parameter.packer = packer;
	FreeTypeFontGenerator.FreeTypeBitmapFontData fontData = generator.generateData(parameter);
	Array<PixmapPacker.Page> pages = packer.getPages();
	Array<TextureRegion> texRegions = new Array<>();
	for (int i = 0; i < pages.size; i++) {
		PixmapPacker.Page p = pages.get(i);
		Texture tex = new Texture(
				new PixmapTextureData(p.getPixmap(), p.getPixmap().getFormat(), false, false, true)) {
			@Override
			public void dispose() {
				super.dispose();
				getTextureData().consumePixmap().dispose();
			}
		};
		tex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
		texRegions.add(new TextureRegion(tex));
	}
	BitmapFont font = new BitmapFont((BitmapFont.BitmapFontData) fontData, texRegions, false);
	saveFontToFile(font, fontSize, fontName, packer);
	generator.dispose();
	packer.dispose();
	return font;
}
 
Example 12
Source File: Filtering.java    From ud406 with MIT License 5 votes vote down vote up
@Override
public void create() {
    batch = new SpriteBatch();
    viewport = new ScreenViewport();
    nearest = new Texture("standing-right.png");
    linear = new Texture("standing-right.png");
    linear.setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
 
Example 13
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 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: InitScreen.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
protected void retrieveAssets() {
	tex = new Texture(EngineAssetManager.getInstance().getResAsset(FILENAME));
	tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
 
Example 16
Source File: ResourceManager.java    From TerraLegion with MIT License 4 votes vote down vote up
public void loadTexturedDrawable(String id, String file) {
	Texture t = new Texture(Gdx.files.internal(file));
	t.setFilter(TextureFilter.Linear, TextureFilter.Nearest);
	drawables.put(id, new TexturedDrawable(t));
}
 
Example 17
Source File: ResourceManager.java    From TerraLegion with MIT License 4 votes vote down vote up
public void loadTexture(String id, String file) {
	Texture t = new Texture(Gdx.files.internal(file));
	t.setFilter(TextureFilter.Linear, TextureFilter.Nearest);
	textures.put(id, t);
}
 
Example 18
Source File: Skin.java    From beatoraja with GNU General Public License v3.0 4 votes vote down vote up
private void setFilter(Texture image) {
	if(type == TYPE_LINEAR || type == TYPE_FFMPEG || type == TYPE_DISTANCE_FIELD) {
		image.setFilter(TextureFilter.Linear, TextureFilter.Linear);
	}
}
 
Example 19
Source File: UAtlasTmxMapLoader.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
private void setTextureFilters (TextureFilter min, TextureFilter mag) {
	for (Texture texture : trackedTextures) {
		texture.setFilter(min, mag);
	}
}
 
Example 20
Source File: TextureLoader.java    From StS-DefaultModBase with MIT License 3 votes vote down vote up
/**
 * Creates an instance of the texture, applies a linear filter to it, and places it in the HashMap
 *
 * @param textureString - String path to the texture you want to load relative to resources,
 *                      Example: "img/ui/missingtexture.png"
 * @throws GdxRuntimeException
 */
private static void loadTexture(final String textureString) throws GdxRuntimeException {
    logger.info("DefaultMod | Loading Texture: " + textureString);
    Texture texture = new Texture(textureString);
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    textures.put(textureString, texture);
}