gpt4 book ai didi

java - LibGDX - 无法从 FrameBuffer 获取纹理

转载 作者:行者123 更新时间:2023-11-30 11:22:03 25 4
gpt4 key购买 nike

我尝试实现一些后处理,所以我需要使用 FrameBuffer 收集整张图片,然后使用着色器对其进行后处理。我在 LibGDX( Rendering a 3D model to texture in LibGDX ) 中找到了一些如何使用 FrameBuffer 的示例,但它不起作用。我得到黑屏。我的代码 fragment :

@Override
public void show() {
modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 1f, 1f, 0f, 1f));
environment.add(new DirectionalLight().set(1f, 0.0f, 0.0f, 0f, -2f, 0f));

cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(1f, 1f, 1f);
cam.lookAt(0,0,0);
cam.near = 0.1f;
cam.far = 300f;
cam.update();
com.badlogic.gdx.graphics.g3d.loader.ObjLoader loader =new ObjLoader();
model = loader.loadModel(Gdx.files.internal("cube/cube.obj"));

instance = new ModelInstance(model);

fbo = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
sb= new SpriteBatch();

camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);
}

@Override
public void render(float delta) {
fbo.begin();

camController.update();

Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
modelBatch.begin(cam);

modelBatch.render(instance, environment);
modelBatch.end();

fbo.end();

//getting texture
tex = fbo.getColorBufferTexture();

//render texture
spriteBatch.begin();
spriteBatch.draw(tex,0,0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
spriteBatch.end();
}

我做错了什么?

更新

我遇到了另一个问题。请看下面的图片:

enter image description here enter image description here

我看到了这个隐藏的风景 fragment 。我用

fb = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);

但是当我尝试打开 FrameBuffer 的深度时,它再次显示黑屏:

fb = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);

如何摆脱显示这个景观 fragment 以及为什么 FrameBuffer 不能使用 depth 参数?

最佳答案

您可以使用 ScreenUtils 函数来获取 framebuffer/

http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/ScreenUtils.html

ScreenUtils.getFrameBufferPixels(int x, int y, int w, int h, boolean flipY)

关于java - LibGDX - 无法从 FrameBuffer 获取纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21978314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com