LIBGDX继续向终端打印“DefaultShaderProvider:Creating new shader”

时间:2013-07-18 19:13:42

标签: java opengl libgdx

我正在libGDX中创建一个3D游戏。出于某种原因,我的游戏一直在打印

DefaultShaderProvider: Creating new shader

在终端。这让我非常疯狂,因为我无法使用终端调试我的程序,因为该行的垃圾邮件。我检查了我的代码是否有任何可以打印的内容,但我找不到任何可能的内容。

有人能告诉我为什么会这样吗?

这是我的代码:

public class puppetDemo implements ApplicationListener {
public PerspectiveCamera camera;
public ModelBatch modelBatch;
public ModelInstance box;
public ModelInstance sphere;
public Array<ModelInstance> instances = new Array<ModelInstance>();
public AssetManager assets;
public Lights lights;
public CameraInputController camController;

public boolean loading = true;

@Override
public void create() {
    camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());
    camera.position.set(10f, 0f, -100f);
    camera.lookAt(0, 0, 0);
    camera.near = 0.1f;
    camera.far = 300f;
    camera.update();

    lights = new Lights();
    lights.ambientLight.set(0.4f, 0.4f, 0.4f, 1f);
    lights.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f,
            -0.2f));

    assets = new AssetManager();
    assets.load("data/box.obj", Model.class);
    assets.load("data/sphere.obj", Model.class);

}

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

}

@Override
public void render() {
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);


    modelBatch = new ModelBatch();

    modelBatch.begin(camera);// Begin Rendering
    modelBatch.render(instances, lights);
    modelBatch.end();// End Rendering
}

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void dispose() {
    modelBatch.dispose();
}
}

1 个答案:

答案 0 :(得分:2)

当您在new ModelBatch()方法中致电render时,这会创建DefaultShaderProvider的新实例:

public ModelBatch() {
  this(new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.ROUNDROBIN, 1)),
       new DefaultShaderProvider(),
       new DefaultRenderableSorter());
}

查看DefaultShaderProvider的来源,您会注意到createShader方法中的记录输出:

@Override
protected Shader createShader(final Renderable renderable) {
  Gdx.app.log("DefaultShaderProvider", "Creating new shader");
  // ...
}

modelBatch方法而不是在create中实例化render,我怀疑您只会看到输出一次。如果没有,可能值得提交一个问题,以删除日志记录,因为它似乎是不必要的。