Search in sources :

Example 1 with TextureFilter

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);
}
Also used : TextureFilter(com.badlogic.gdx.graphics.Texture.TextureFilter)

Example 2 with TextureFilter

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);
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) TextureFilter(com.badlogic.gdx.graphics.Texture.TextureFilter)

Example 3 with TextureFilter

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));
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) TextureFilter(com.badlogic.gdx.graphics.Texture.TextureFilter) Texture(com.badlogic.gdx.graphics.Texture) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) TextureParameter(com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter) File(java.io.File)

Aggregations

TextureFilter (com.badlogic.gdx.graphics.Texture.TextureFilter)3 TextureParameter (com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter)1 Texture (com.badlogic.gdx.graphics.Texture)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 GridBagConstraints (java.awt.GridBagConstraints)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1