On 21 Aug 2014, at 17:56, Ivan Adanja <
ada...@gmail.com> wrote:
> Hey guys,
>
> I hope you can find some time to help an OpenGL newbie out by shedding some light on the questions below :)
>
> I'm looking at the examples/howto/offscreen.py (bleeding edge github @6f6bde03) and wondering what would it take to retrieve the a float buffer instead of an RGBA one?
>
> My understanding is that _screenshot() calls read_pixels(), which performs the following OpenGL call to retrieve the color buffer:
>
> im = gl.glReadPixels(x, y, w, h, gl.GL_RGB, gl.GL_UNSIGNED_BYTE)
>
> But I noticed that gl.glReadPixels only seem supports the following formats: GL_ALPHA, GL_RGB, GL_RGBA and only for GL_UNSIGNED_BYTE.
>
> [Q1] What need to be added to get a float image out? Where is the dtype of the numpy returned array set?
> im = gl.glReadPixels(x, y, w, h, gl.GL_ALPHA, gl.GL_UNSIGNED_BYTE)
With this you would get a (h,w,1) array with dtype np.uint8
>
> [Q2] Ultimately, my goal is to be able to write shaders that output a float (custome depth buffers) or triplets of floats (normal maps) into a texture that I can retrieve to the CPU.
> I don't understand the FrameBuffer mechanism enough to see what is missing to allow me to do that?
It depends on what you want to achieve with the depth or normal buffer. if you intend to use them in a shader, you'd better use texture for them and pass these texture as regular texture in your shader.
> The code in examples/howto/offscreen.py hints at this working, since the render texture, _rendertex, is a float. But the image returned by the shader and _screenshot is an RGBA.
For depth buffer, you will need a (h,w) texture, not a (h,w,3)
>
> [Q3] Also I've seen solution that retrieve textures using glGetTexImage insted of glReadPixel. Do you know what is the difference between these approaches?
glReadPixel read from the framebuffer (the screen in most situation) while glGetTexImage can read from a texture.
Hope that helps.
>
> Thanks in advance,
> Ivan
>
> --
> You received this message because you are subscribed to the Google Groups "vispy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
vispy+un...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.