简体   繁体   中英

Shaperenderer crash libgdx

I'm developing a new application with libgdx and in my source code i'm using the shaperenderer class but since I've bought my new tablet (Acer Iconia One 10 B3-A20), my application always crash without displaying any errors after calling the "shaperenderer.end()" method . Even when I create a simple class as the following one, have I missing something?

public class Test implements Screen {
    private ShapeRenderer shapeRenderer = new ShapeRenderer();

    @Override
    public void show() {

    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
        shapeRenderer.rect(30,30,200,200);
        shapeRenderer.end();

    }

    @Override
    public void resize(int width, int height) {

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {
        shapeRenderer.dispose();

    }
}

Thanks

EDIT:

After placing some breakpoints into the "shaperenderer.end()"method i have noticed that the program crash after calling the "mesh.render()" method, and particularly when it call the "bind" method of the Mesh class (for binding the shaders).

Is it normal?

You need to create a camera first on your show method:

OrthographicCamera camera;
[...]
camera = new OrthographicCamera();
camera.setToOrtho(false);

and on render method set the projectionMatrix before draw:

    camera.update();
    shapeRenderer.setProjectionMatrix(camera.combined);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM