OpenGL snippets: Difference between revisions

From vegard.wiki
Jump to navigation Jump to search
Content added Content deleted
(new page)
 
Line 1: Line 1:
__TOC__
__TOC__


== Saving the framebuffer ==
== Saving the framebuffer to file ==


=== Python ===
=== Python ===

Revision as of 19:04, 18 December 2019

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.