Example usage for com.badlogic.gdx.graphics Texture Texture

List of usage examples for com.badlogic.gdx.graphics Texture Texture

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics Texture Texture.

Prototype

public Texture(Pixmap pixmap, boolean useMipMaps) 

Source Link

Usage

From source file:at.tugraz.ist.catroid.plugin.Drone.other.DroneVideoCostume.java

License:Open Source License

public void initializeTexture() {
    Pixmap pixmap = new Pixmap(320, 240, Format.RGB888);
    pixmap.setColor(Color.BLUE);/*from  w  w  w.jav  a 2  s.co  m*/
    pixmap.fill();
    Texture texture = new Texture(pixmap, false);
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    this.region = new TextureRegion(texture);
    this.width = this.region.getRegionWidth();
    this.height = this.region.getRegionHeight();
    this.x -= (this.width / 2f);
    this.y -= (this.height / 2f);
    this.originX = (this.width / 2f);
    this.originY = (this.height / 2f);
    pixmap.dispose();
    firstStart = false;
}

From source file:com.andgate.ikou.utility.graphics.ShaderFont.java

License:Open Source License

private static TextureRegion loadTextureRegion(String pngFilename) {
    Texture texture = new Texture(Gdx.files.internal(pngFilename), true);
    texture.setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.Linear);
    return new TextureRegion(texture);
}

From source file:com.andgate.ikou.utility.Icon.java

License:Open Source License

public static ImageButton createIconButton(Ikou game, String upFilename, String downFilename,
        ClickListener listener) {// w w  w .  j ava  2 s.c om
    Texture buttonTexture = new Texture(Gdx.files.internal(upFilename), true);
    buttonTexture.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear);

    Texture buttonDownTexture = new Texture(Gdx.files.internal(downFilename), true);
    buttonDownTexture.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear);

    TextureRegionDrawable buttonDrawable = new TextureRegionDrawable(new TextureRegion(buttonTexture));
    TextureRegionDrawable buttonDownDrawable = new TextureRegionDrawable(new TextureRegion(buttonDownTexture));

    ImageButton button = new ImageButton(buttonDrawable, buttonDownDrawable);
    button.getImageCell().width(Constants.BUTTON_LENGTH * game.ppm);
    button.getImageCell().height(Constants.BUTTON_LENGTH * game.ppm);

    button.addListener(listener);

    return button;
}

From source file:com.badlogic.gdx.graphics.g3d.test.StillModelViewer.java

License:Apache License

@Override
public void create() {
    long start = System.nanoTime();
    model = ModelLoaderRegistry.loadStillModel(Gdx.files.internal(fileName));
    Gdx.app.log("StillModelViewer", "loading took: " + (System.nanoTime() - start) / 1000000000.0f);

    for (StillSubMesh mesh : model.subMeshes) {
        mesh.mesh.scale(0.1f, 0.1f, 0.1f);
    }/*from   w  ww  .j  ava  2 s.c om*/

    if (!fileName.endsWith(".g3d")) {
        G3dExporter.export(model, Gdx.files.absolute(fileName + ".g3d"));
        start = System.nanoTime();
        model = G3dLoader.loadStillModel(Gdx.files.absolute(fileName + ".g3d"));
        Gdx.app.log("StillModelViewer", "loading binary took: " + (System.nanoTime() - start) / 1000000000.0f);
    }

    if (textureFileNames.length != 0) {
        textures = new Texture[textureFileNames.length];
        for (int i = 0; i < textureFileNames.length; i++) {
            textures[i] = new Texture(Gdx.files.internal(textureFileNames[i]), i > 0 ? false : true);
        }
    }
    hasNormals = hasNormals();

    model.getBoundingBox(bounds);
    float len = bounds.getDimensions().len();
    System.out.println("bounds: " + bounds);

    cam = new PerspectiveCamera(60, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(bounds.getCenter().cpy().add(len / 2, len / 2, len / 2));
    cam.lookAt(bounds.getCenter().x, bounds.getCenter().y, bounds.getCenter().z);
    cam.near = 0.1f;
    cam.far = 1000;

    renderer = new ImmediateModeRenderer10();
    batch = new SpriteBatch();
    font = new BitmapFont();
}

From source file:com.badlogic.gdx.graphics.g3d.test.StillModelViewerGL20.java

License:Apache License

@Override
public void create() {
    long start = System.nanoTime();
    model = ModelLoaderRegistry.loadStillModel(Gdx.files.internal(fileName));
    Gdx.app.log("StillModelViewer", "loading took: " + (System.nanoTime() - start) / 1000000000.0f);

    if (textureFileNames.length != 0) {
        textures = new Texture[textureFileNames.length];
        for (int i = 0; i < textureFileNames.length; i++) {
            textures[i] = new Texture(Gdx.files.internal(textureFileNames[i]), i > 0 ? false : true);
        }//from   w  w  w .  j  a va2s  . c  o m
    }

    model.getBoundingBox(bounds);
    float len = bounds.getDimensions().len();
    System.out.println("bounds: " + bounds);

    cam = new PerspectiveCamera(60, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(bounds.getCenter().cpy().add(len / 2, len / 2, len / 2));
    cam.lookAt(bounds.getCenter().x, bounds.getCenter().y, bounds.getCenter().z);
    cam.near = 0.1f;
    cam.far = 64;

    batch = new SpriteBatch();
    font = new BitmapFont();

    // shader1 = ShaderLoader.createShader("light", "light");
    // shader2 = ShaderLoader.createShader("vertexpath", "vertexpath");

    lightManager = new LightManager(4, LightQuality.VERTEX);
    lightManager.dirLight = new DirectionalLight();
    lightManager.dirLight.color.set(0.09f, 0.07f, 0.09f, 0);
    lightManager.dirLight.direction.set(-.4f, -1, 0.03f).nor();

    for (int i = 0; i < 4; i++) {
        PointLight l = new PointLight();
        l.position.set(-MathUtils.random(8) + 4, MathUtils.random(3), -MathUtils.random(6) + 3);

        l.color.r = MathUtils.random();
        l.color.b = MathUtils.random();
        l.color.g = MathUtils.random();
        l.intensity = 3;
        lightManager.addLigth(l);
    }
    lightManager.ambientLight.set(.03f, 0.05f, 0.06f, 0);

    protoRenderer = new PrototypeRendererGL20(lightManager);
    protoRenderer.cam = cam;

    MaterialAttribute c1 = new ColorAttribute(new Color(0.5f, 0.51f, 0.51f, 1.0f), ColorAttribute.specular);
    MaterialAttribute c2 = new ColorAttribute(new Color(0.95f, 0.95f, 0.95f, 1.0f), ColorAttribute.diffuse);
    MaterialAttribute t0 = new TextureAttribute(textures[0], 0, TextureAttribute.diffuseTexture);
    Material material = new Material("basic", c1, c2, t0);

    model.setMaterial(material);
    instance = new StillModelNode();
    instance.getTransform().translate(-len / 2, -1, 2);
    instance.radius = bounds.getDimensions().len() / 2;

    instance2 = new StillModelNode();
    instance2.getTransform().translate(len / 2, -1, -7);

    instance2.radius = instance.radius;

}

From source file:com.badlogic.gdx.physics.bullet.demo.screens.DemoScreen.java

public DemoScreen(Game game) {
    // Physics is configured when super() finishes
    super();//w  w w  .ja  v a2  s  . co  m

    this.game = game;
    this.input = new DemoScreenInput(this, Gdx.input);

    Gdx.app.getInput().setInputProcessor(input);

    // Ambient light
    Gdx.gl10.glLightModelfv(GL10.GL_LIGHT_MODEL_AMBIENT, new float[] { .2f, .2f, .2f, 1 }, 0);

    // One directional light
    Gdx.gl10.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, new float[] { .2f, .2f, .2f, 1 }, 0);
    Gdx.gl10.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, new float[] { 1, 1, 1, 1 }, 0);
    Gdx.gl10.glLightfv(GL10.GL_LIGHT0, GL10.GL_SPECULAR, new float[] { 1, 1, 1, 1 }, 0);
    Gdx.gl10.glLightf(GL10.GL_LIGHT0, GL10.GL_CONSTANT_ATTENUATION, 1);
    Gdx.gl10.glLightf(GL10.GL_LIGHT0, GL10.GL_LINEAR_ATTENUATION, 0);
    Gdx.gl10.glLightf(GL10.GL_LIGHT0, GL10.GL_QUADRATIC_ATTENUATION, 0);
    Gdx.gl10.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, new float[] { -10, -10, 10, 1 }, 0);
    Gdx.gl10.glEnable(GL10.GL_LIGHT0);

    PerspectiveCamera camera = getPerspectiveCamera();
    camera.position.set(-25, 0, 20);
    camera.lookAt(0, 0, 0);
    camera.up.set(0, 0, 1);
    camera.fieldOfView = 60;
    camera.update();

    // Load meshes
    cubeMesh = ObjLoader.loadObj(Gdx.app.getFiles().classpath("models/cube.obj").read(), false);
    icosphereMesh = ObjLoader.loadObj(Gdx.app.getFiles().classpath("models/icosphere.obj").read(), false);
    terrainMesh = ObjLoader.loadObj(Gdx.app.getFiles().classpath("models/terrain.obj").read(), false);

    // Load textures
    cubeTexture = new Texture(Gdx.files.classpath("textures/weird.png"), true);
    cubeTexture.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Nearest);
    icosphereTexture = new Texture(Gdx.files.classpath("textures/blue.png"), true);
    icosphereTexture.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Nearest);
    terrainTexture = new Texture(Gdx.files.classpath("textures/grass.png"), true);
    terrainTexture.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Nearest);
    terrainTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
}

From source file:com.badlogic.gdx.tests.gles2.MipMap2D.java

License:Apache License

private void createTexture() {
    Pixmap pixmap = new Pixmap(256, 256, Format.RGB565);
    boolean useRed = true;
    for (int y = 0; y < 256; y += 8) {
        for (int x = 0; x < 256; x += 8) {
            pixmap.setColor(useRed ? 1 : 0, 0, useRed ? 0 : 1, 1);
            pixmap.fillRectangle(x, y, 8, 8);
            useRed = !useRed;/*w  w w.  ja  va  2s . c o m*/
        }
        useRed = !useRed;
    }
    texture = new Texture(pixmap, true);
    texture.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear);
}

From source file:com.betmansmall.game.gameLogic.mapLoader.MapLoader.java

License:Apache License

/** Loads the {@link TiledMap} from the given file. The file is resolved via the {@link FileHandleResolver} set in the
 * constructor of this class. By default it will resolve to an internal file.
 * @param fileName the filename//from w w w  . ja  v a2  s  .co  m
 * @param parameters specifies whether to use y-up, generate mip maps etc.
 * @return the TiledMap */
public TiledMap load(String fileName, MapLoader.Parameters parameters) {
    try {
        this.convertObjectToTileSpace = parameters.convertObjectToTileSpace;
        this.flipY = parameters.flipY;
        FileHandle tmxFile = resolve(fileName);
        root = xml.parse(tmxFile);
        ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
        Array<FileHandle> textureFiles = loadTilesets(root, tmxFile);
        textureFiles.addAll(loadImages(root, tmxFile));

        for (FileHandle textureFile : textureFiles) {
            Texture texture = new Texture(textureFile, parameters.generateMipMaps);
            texture.setFilter(parameters.textureMinFilter, parameters.textureMagFilter);
            textures.put(textureFile.path(), texture);
        }

        DirectImageResolver imageResolver = new DirectImageResolver(textures);
        TiledMap map = loadTilemap(root, tmxFile, imageResolver);
        map.setOwnedResources(textures.values().toArray());
        return map;
    } catch (IOException e) {
        throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
    }
}

From source file:com.bladecoder.engine.util.RectangleRenderer.java

License:Apache License

private static Texture makePixel() {
    Texture _temp;//from  w  w  w .  j  ava 2s.  co m
    Pixmap p = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    p.setColor(Color.WHITE);
    p.fillRectangle(0, 0, 1, 1);
    _temp = new Texture(p, true);
    p.dispose();
    return _temp;
}

From source file:com.blindtigergames.werescrewed.graphics.particle.ParticleEffect.java

License:Apache License

protected Texture loadTexture(FileHandle file) {
    return new Texture(file, false);
}