Open pascalr opened 3 years ago
I think pixels should be a string of length width*height*4
(I think float size is 4 bytes), and then to turn it into an array of floats you would call pixels.unpack('F*')
I should really just add a function to do this and output a ChunkyPNG object or something.
Possibly related to #75
That would be great if you manage to add a function that outputs a png!
I tried with the string, but I didn't get very far, somehow it made my application crash without any error messages.
I believe the length of the string should be width*height*4*3
in my case since I wanted RGB, but probably mutliplied by 4 for GL_RGBA for a png.
Oh right, I forgot about the number of channels 🤦♀️
I was finally able to do it with this:
module RendererPatch
def take_screenshot(x,y,width,height)
type_nb_bytes = 1 # for GL_UNSIGNED_BYTE (0 to 255)
nb_channels = 3 # for GL_RGB
pixels = ' '*width*height*type_nb_bytes*nb_channels
glReadPixels(x,y,width,height,GL_RGB,GL_UNSIGNED_BYTE,pixels)
png = ChunkyPNG::Image.from_rgb_stream(width, height, pixels)
png.flip_horizontally!
png.save('screenshot.png', :interlace => true)
end
end
Mittsu::OpenGLRenderer.include RendererPatch
Hello I was wondering how I can get the pixel values that are rendered to the screen. I got this so far:
But I don't understand what kind of variable pixels is supposed to be. It's complaining:
This is the method source code from opengl-bindings:
PS: Thanks for the great library!