Main Menu

Framebuffer

Started by Kgboi, July 20, 2021, 20:12:18

Previous topic - Next topic

Kgboi

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.


jakethesnake

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:
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.