0

我正在 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();
}
}
4

1 回答 1

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");
  // ...
}

modelBatchcreate方法中而不是在方法中实例化,render我怀疑您只会看到一次输出。如果没有,可能值得提出一个问题来删除日志语句,因为这似乎没有必要。

于 2013-07-18T19:30:21.650 回答