Search in sources :

Example 1 with PixmapTextureData

use of com.badlogic.gdx.graphics.glutils.PixmapTextureData in project libgdx by libgdx.

the class DownloadTest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    HttpRequest request = new HttpRequest(HttpMethods.GET);
    request.setUrl("https://www.google.at/images/srpr/logo11w.png");
    Gdx.net.sendHttpRequest(request, new HttpResponseListener() {

        @Override
        public void handleHttpResponse(HttpResponse httpResponse) {
            final byte[] bytes = httpResponse.getResult();
            Gdx.app.postRunnable(new Runnable() {

                @Override
                public void run() {
                    Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
                    texture = new Texture(new PixmapTextureData(pixmap, pixmap.getFormat(), false, false, true));
                }
            });
        }

        @Override
        public void failed(Throwable t) {
            t.printStackTrace();
            Gdx.app.log("EmptyDownloadTest", "Failed", t);
        }

        @Override
        public void cancelled() {
            Gdx.app.log("EmptyDownloadTest", "Cancelled");
        }
    });
}
Also used : HttpRequest(com.badlogic.gdx.Net.HttpRequest) HttpResponse(com.badlogic.gdx.Net.HttpResponse) PixmapTextureData(com.badlogic.gdx.graphics.glutils.PixmapTextureData) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap) HttpResponseListener(com.badlogic.gdx.Net.HttpResponseListener)

Aggregations

HttpRequest (com.badlogic.gdx.Net.HttpRequest)1 HttpResponse (com.badlogic.gdx.Net.HttpResponse)1 HttpResponseListener (com.badlogic.gdx.Net.HttpResponseListener)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Texture (com.badlogic.gdx.graphics.Texture)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 PixmapTextureData (com.badlogic.gdx.graphics.glutils.PixmapTextureData)1