OpenGL snippets

From vegard.wiki
Jump to navigation Jump to search

Saving the framebuffer to file

Python

from PIL import Image

pixels = glReadPixels(0, 0, window_width, window_height, GL_RGB, GL_UNSIGNED_BYTE)
image = Image.frombytes(mode="RGB", size=(window_width, window_height), data=pixels)
image = image.transpose(Image.FLIP_TOP_BOTTOM)
image.save('output.png')

Note: This should work for any file type/extension that PIL supports.