Discussion:
[Bf-python] Reading Pixel Data From bgl FrameBuffer
Khalifa Lame
2014-10-23 14:38:02 UTC
Permalink
glReadPixels() returns None. I'm sure it shouldn't be empty, I did some
clearing and drawing beforehand.
I even tried specifying the buffer to draw to using glDrawBuffer() and
glReadBuffer. Tried with GL_BACK and GL_AUX_BUFFERS. Both turn up empty.

Is there something i'm missing?
Another weird thing, the preview window shows some colored dots when in
fact, the data fed to it was the empty result from glReadPixels().

I'm new to openGL programming and even newer to bgl.
--
khalibloo®
Dalai Felinto
2014-10-23 16:31:57 UTC
Permalink
Hi Khalifa,

See if this sample file helps:
https://svn.blender.org/svnroot/bf-blender/trunk/lib/tests/gameengine_visual/lampRGB.blend

The code runs in the BGE (Blender Game Engine), but the BGE works the
same for Blender and for the BGE.

Apart from that BGL is simply a wrapper of OpenGL functions, so I
presume the error is in your OpenGL (bgl) code.

Regards,
Dalai
--
blendernetwork.org/dalai-felinto
www.dalaifelinto.com
Post by Khalifa Lame
glReadPixels() returns None. I'm sure it shouldn't be empty, I did some
clearing and drawing beforehand.
I even tried specifying the buffer to draw to using glDrawBuffer() and
glReadBuffer. Tried with GL_BACK and GL_AUX_BUFFERS. Both turn up empty.
Is there something i'm missing?
Another weird thing, the preview window shows some colored dots when in
fact, the data fed to it was the empty result from glReadPixels().
I'm new to openGL programming and even newer to bgl.
--
khalibloo®
_______________________________________________
Bf-python mailing list
http://lists.blender.org/mailman/listinfo/bf-python
Khalifa Lame
2014-10-23 19:03:20 UTC
Permalink
in the example, the drawing is done in the default buffer and magically
read back into a bgl.Buffer object

here's what my code looks like

def render_preview(self, scene):
pixelCount = self.size_x * self.size_y

# Setup
buffer = bgl.Buffer(bgl.GL_FLOAT, [pixelCount, 4])
bgl.glClearColor(1.0, 1.0, 1.0, 1.0)
bgl.glClear(bgl.GL_COLOR_BUFFER_BIT or bgl.GL_DEPTH_BUFFER_BIT)

# i should have a white screen already

bgl.glBegin(bgl.GL_TRIANGLES)
bgl.glVertex3f(2.0, 2.0, 0.0)
bgl.glVertex3f(2.0, 0.0, 0.0)
bgl.glVertex3f(0.0, 2.0, 0.0)
bgl.glEnd()

# Read pixel data
bgl.glReadPixels(0, 0, self.size_x, self.size_y, bgl.GL_RGBA,
bgl.GL_FLOAT, buffer)
print(str(buffer))

# After printing, i get a series of 0s

I'm doing something blatantly wrong, aren't I? [?]
Post by Dalai Felinto
Hi Khalifa,
https://svn.blender.org/svnroot/bf-blender/trunk/lib/tests/gameengine_visual/lampRGB.blend
The code runs in the BGE (Blender Game Engine), but the BGE works the
same for Blender and for the BGE.
Apart from that BGL is simply a wrapper of OpenGL functions, so I
presume the error is in your OpenGL (bgl) code.
Regards,
Dalai
--
blendernetwork.org/dalai-felinto
www.dalaifelinto.com
Post by Khalifa Lame
glReadPixels() returns None. I'm sure it shouldn't be empty, I did some
clearing and drawing beforehand.
I even tried specifying the buffer to draw to using glDrawBuffer() and
glReadBuffer. Tried with GL_BACK and GL_AUX_BUFFERS. Both turn up empty.
Is there something i'm missing?
Another weird thing, the preview window shows some colored dots when in
fact, the data fed to it was the empty result from glReadPixels().
I'm new to openGL programming and even newer to bgl.
--
khalibloo®
_______________________________________________
Bf-python mailing list
http://lists.blender.org/mailman/listinfo/bf-python
_______________________________________________
Bf-python mailing list
http://lists.blender.org/mailman/listinfo/bf-python
--
khalibloo®
Tom Edwards
2014-10-23 17:43:28 UTC
Permalink
The picture is what happens when you ask the GPU to draw random memory.
Memory like that at the address of Python's None object and beyond. :-)
Post by Khalifa Lame
glReadPixels() returns None. I'm sure it shouldn't be empty, I did
some clearing and drawing beforehand.
I even tried specifying the buffer to draw to using glDrawBuffer() and
glReadBuffer. Tried with GL_BACK and GL_AUX_BUFFERS. Both turn up empty.
Is there something i'm missing?
Another weird thing, the preview window shows some colored dots when
in fact, the data fed to it was the empty result from glReadPixels().
I'm new to openGL programming and even newer to bgl.
--
khalibloo®
_______________________________________________
Bf-python mailing list
http://lists.blender.org/mailman/listinfo/bf-python
Loading...