LibGdx 不使用纹理(混合 OpenGL 原生和 LibGDX)

LibGdx not using textures (Mixing OpenGL native and LibGDX)

我正在尝试创建一款 AR 游戏。我正在使用此处描述的方法 https://github.com/chili-epfl/libgdx-sample/blob/master/core/src/ch/epfl/chili/libgdx_sample/LibgdxSample.java,但是在 deviceCameraControl.renderBackground() 之后;我要渲染舞台。

舞台目前包含一张图片。这会正确显示,直到首先绘制相机预览为止。一旦发生这种情况,它会再次显示相机预览,而不是加载的图像,缩小到图像的大小。所以看起来不是使用加载的图像,而是再次显示相机预览的纹理。

这可能是什么原因以及如何解决?

整个渲染方法目前看起来像这样(简化):

    if (crosshair == null) {
        crosshair = new Image(new Texture(Gdx.files.internal("data/image0008.png")));
        crosshair.setPosition(stage.getWidth() / 2 - crosshair.getWidth() - 2, stage.getHeight() / 2 - crosshair.getHeight() / 2);
        stage.addActor(crosshair);
    }
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    if (device_cam == null) {
        device_cam = new MobileCameraView(game, game.getCameraControler());
        device_cam.init((int) w, (int) h);
    } else if (device_cam.isStopped()) device_cam.start();
    else {
        device_cam.renderBackground();
    }

    camera.update(true);

    getStage().act(delta);
    getStage().draw();

所以对于所有 运行 相同的问题:Xoppa 的 "wild guess" 完全解决了这个问题。简化的代码将如下所示:

if (crosshair == null) {
    crosshair = new Image(new Texture(Gdx.files.internal("data/image0008.png")));
    crosshair.setPosition(stage.getWidth() / 2 - crosshair.getWidth() / 2, stage.getHeight() / 2 - crosshair.getHeight() / 2);
    stage.addActor(crosshair);
}
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
if (device_cam == null) {
    device_cam = new MobileCameraView(game, game.getCameraControler());
    device_cam.init((int) w, (int) h);
} else if (device_cam.isStopped()) device_cam.start();
else {
    device_cam.renderBackground();
}

camera.update(true);
Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0);
getStage().act(delta);
getStage().draw();