Opengl libgdx中使用帧缓冲区的结果不明确
对于libgdx中的类,我得到了以下奇怪的结果 下面是生成此结果的代码:Opengl libgdx中使用帧缓冲区的结果不明确,opengl,opengl-es,libgdx,framebuffer,fbo,Opengl,Opengl Es,Libgdx,Framebuffer,Fbo,对于libgdx中的类,我得到了以下奇怪的结果 下面是生成此结果的代码: // This is the rendering code @Override public void render(float delta) { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); stage.act(); stage.draw(); fbo.begin(); batch.b
// This is the rendering code
@Override
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
stage.act();
stage.draw();
fbo.begin();
batch.begin();
batch.draw(heart, 0, 0);
batch.end();
fbo.end();
test = new Image(fbo.getColorBufferTexture());
test.setPosition(256, 256);
stage.addActor(test);
}
//This is the initialization code
@Override
public void show() {
stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
atlas = Assets.getAtlas();
batch = new SpriteBatch();
background = new Image(atlas.findRegion("background"));
background.setFillParent(true);
heart = atlas.findRegion("fluttering");
fbo = new FrameBuffer(Pixmap.Format.RGBA8888, heart.getRegionWidth(), heart.getRegionHeight(), false);
stage.addActor(background);
Image temp = new Image(new TextureRegion(heart));
stage.addActor(temp);
}
为什么我在帧缓冲区上绘制的心脏会翻转,并且比原始心脏小,尽管帧缓冲区的宽度和高度与图像的宽度和高度相同(71 x 72)。要解决这个问题,帧缓冲区的宽度和高度必须与舞台的宽度和高度相等,如下所示:
fbo = new FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
您的SpriteBatch使用了错误的投影矩阵。由于要渲染到自定义大小的帧缓冲区,因此必须手动设置一个帧缓冲区
projectionMatrix = new Matrix4();
projectionMatrix.setToOrtho2D(0, 0, heart.getRegionWidth(), heart.getRegionHeight());
batch.setProjectionMatrix(projectionMatrix);
+1用于显示问题的注释图片。很好。这是正确的答案,另一个只是解决办法。在许多情况下,您可能希望使用尺寸与屏幕尺寸不匹配的FB。