use of com.badlogic.gdx.graphics.Texture.TextureFilter in project libgdx by libgdx.
the class BitmapFontDistanceFieldTest method drawFont.
private int drawFont(BitmapFont font, String description, boolean linearFiltering, boolean useShader, float smoothing, int x) {
int y = 10;
float maxWidth = 0;
spriteBatch.setShader(null);
descriptionFont.draw(spriteBatch, description, x, y);
spriteBatch.flush();
y += 10 + 2 * descriptionFont.getLineHeight();
// set filters for each page
TextureFilter minFilter = linearFiltering ? TextureFilter.MipMapLinearNearest : TextureFilter.Nearest;
TextureFilter magFilter = linearFiltering ? TextureFilter.Linear : TextureFilter.Nearest;
for (int i = 0; i < font.getRegions().size; i++) {
font.getRegion(i).getTexture().setFilter(minFilter, magFilter);
}
if (useShader) {
spriteBatch.setShader(distanceFieldShader);
} else {
spriteBatch.setShader(null);
}
for (float scale : SCALES) {
font.getData().setScale(scale);
layout.setText(font, TEXT);
maxWidth = Math.max(maxWidth, layout.width);
if (useShader) {
distanceFieldShader.setSmoothing(smoothing / scale);
}
font.draw(spriteBatch, layout, x, y);
y += font.getLineHeight();
spriteBatch.flush();
}
return (int) Math.ceil(maxWidth);
}
use of com.badlogic.gdx.graphics.Texture.TextureFilter in project libgdx by libgdx.
the class MipMapTest method createUI.
private void createUI() {
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
ui = new Stage();
String[] filters = new String[TextureFilter.values().length];
int idx = 0;
for (TextureFilter filter : TextureFilter.values()) {
filters[idx++] = filter.toString();
}
hwMipMap = new CheckBox("Hardware Mips", skin);
minFilter = new SelectBox(skin);
minFilter.setItems(filters);
magFilter = new SelectBox(skin.get(SelectBoxStyle.class));
magFilter.setItems("Nearest", "Linear");
Table table = new Table();
table.setSize(ui.getWidth(), 30);
table.setY(ui.getHeight() - 30);
table.add(hwMipMap).spaceRight(5);
table.add(new Label("Min Filter", skin)).spaceRight(5);
table.add(minFilter).spaceRight(5);
table.add(new Label("Mag Filter", skin)).spaceRight(5);
table.add(magFilter);
ui.addActor(table);
}
use of com.badlogic.gdx.graphics.Texture.TextureFilter in project libgdx by libgdx.
the class TextureLoaderPanel method initializeComponents.
@Override
protected void initializeComponents() {
super.initializeComponents();
JButton atlasButton = new JButton("Open Atlas");
JButton textureButton = new JButton("Open Texture");
JButton defaultTextureButton = new JButton("Default Texture");
final JCheckBox genMipMaps = new JCheckBox("Generate MipMaps");
final JComboBox minFilterBox = new JComboBox(new DefaultComboBoxModel(TextureFilter.values()));
final JComboBox magFilterBox = new JComboBox(new DefaultComboBoxModel(TextureFilter.values()));
minFilterBox.setSelectedItem(editor.getTexture().getMinFilter());
magFilterBox.setSelectedItem(editor.getTexture().getMagFilter());
ActionListener filterListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {
editor.getTexture().setFilter((TextureFilter) minFilterBox.getSelectedItem(), (TextureFilter) magFilterBox.getSelectedItem());
}
};
minFilterBox.addActionListener(filterListener);
magFilterBox.addActionListener(filterListener);
atlasButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
File file = editor.showFileLoadDialog();
if (file != null) {
TextureAtlas atlas = editor.load(file.getAbsolutePath(), TextureAtlas.class, null, null);
if (atlas != null) {
editor.setAtlas(atlas);
}
}
}
});
textureButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
File file = editor.showFileLoadDialog();
if (file != null) {
TextureParameter params = new TextureParameter();
params.genMipMaps = genMipMaps.isSelected();
params.minFilter = (TextureFilter) minFilterBox.getSelectedItem();
params.magFilter = (TextureFilter) magFilterBox.getSelectedItem();
Texture texture = editor.load(file.getAbsolutePath(), Texture.class, null, params);
if (texture != null) {
editor.setTexture(texture);
}
}
}
});
defaultTextureButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editor.setTexture(editor.assetManager.get(FlameMain.DEFAULT_BILLBOARD_PARTICLE, Texture.class));
}
});
contentPanel.add(new JLabel("Min. Filter"), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(minFilterBox, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(new JLabel("Mag. Filter"), new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(magFilterBox, new GridBagConstraints(1, 1, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(genMipMaps, new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(atlasButton, new GridBagConstraints(0, 3, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(textureButton, new GridBagConstraints(1, 3, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(defaultTextureButton, new GridBagConstraints(2, 3, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
}
Aggregations