Hello Guest

Framebuffer

  • 1 Replies
  • 5008 Views
Framebuffer
« on: July 20, 2021, 20:12:18 »
I've got my project setup with ImGUI and want to render to a texture instead of GLFW, so I can put that texture in a ImGUI image widget. I basically want to know how I render my scene to a framebuffer, but I still need ImGUI to render to GLFW.


Re: Framebuffer
« Reply #1 on: July 24, 2021, 16:49:44 »
You mean you want to render not to the screen, but to a texture.

You can't render to a texture, but you can render to a FBO.
First you create a FBO.
Then bind that, check out GL_DRAW_FRAMEBUFFER
Render
Get the data:
Code: [Select]
ByteBuffer getFramePixels(int width, int height){

glReadBuffer(GL_COLOR_ATTACHMENT0);
int bpp = 4;
ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
return buffer;
}
Turn the data into a texture.