Rendering of 3d scene to framebuffer

Anything libgdx related goes here!

Rendering of 3d scene to framebuffer

Postby limmon » Thu Jan 16, 2020 2:46 pm

I want to render 3d scene to framebuffer and render framebuffer's texture on screen.

Code: Select all
if (framebuffer == null) {
    framebuffer = new FrameBuffer(Pixmap.Format.RGBA8888, screenWidth, screenHeight, true)
}

framebuffer.begin()

Gdx.gl.glClearColor(1f, 0f, 0f, 1f) // red background
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT  | GL20.GL_DEPTH_BUFFER_BIT)

// render 3d scene

Bitmap bitmap = readBitmap() // read pixels using ScreenUtils.getFrameBufferPixels() and convert to Android bitmap for debugging. I see this bitmap using Android Studio’s debugger. It contains correct 3d scene.

framebuffer.end()


spriteBatch.begin()

TextureRegion region = new TextureRegion(fbo.colorBufferTexture)
region.flip(false, true)

spriteBatch.draw(region, 0f, 0f)
spriteBatch.end()




But I just get red screen and no 3d scene.
Using Android Studio’s debugger I see in Android bitmap my scene. But screen is red.

I successfully render my 3d scene to screen without framebuffer.

Any ideas?
limmon
 
Posts: 3
Joined: Wed Aug 07, 2019 2:56 pm

Re: Rendering of 3d scene to framebuffer

Postby shatterblast » Thu Jan 16, 2020 3:10 pm

Here is the basic flow in 1 render() method cycle for what you are asking.

1) Render your 3D scene as normal to a SpriteBatch.
2) The SpriteBatch does not render to the graphics card. Instead, you have it render to the FrameBuffer.
3) Render from the FrameBuffer object to a Texture object. You might need a SpriteBatch for this, too.
4) Do the normal stuff for putting the Texture in a secondary Stage object. Make sure the Texture fits your Viewport of choice from edge to edge.
5) Use another SpriteBatch that accepts input from the secondary Stage.
6) Use that secondary SpriteBatch to render to the graphics card as normal.

This is how I understand the process. I have not done it myself, so the process might be off a little. I highlighted elsewhere in this forum about FrameBuffer objects and 3D, so you might give it a look.

Using this layout, you can also do fancy stuff with squares and cubes. However, the input needs to be a frame ahead to do so, which means you would render everything delayed behind by 1 render() method cycle. However, that's just for exploration.
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm

Re: Rendering of 3d scene to framebuffer

Postby limmon » Fri Jan 17, 2020 11:41 am

I found my problem. I use DirectionalShadowLight which unbinds my framebuffer and binds its framebuffer.
limmon
 
Posts: 3
Joined: Wed Aug 07, 2019 2:56 pm

Re: Rendering of 3d scene to framebuffer

Postby shatterblast » Fri Jan 17, 2020 2:52 pm

I am glad you found your solution.
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm


Return to Libgdx

Who is online

Users browsing this forum: Google [Bot], MSN [Bot] and 1 guest