[Bf-python] Reading Pixel Data From bgl FrameBuffer

Khalifa Lame khalibloo at gmail.com
Thu Oct 23 21:03:20 CEST 2014


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? [?]

On Thu, Oct 23, 2014 at 5:31 PM, Dalai Felinto <dfelinto at gmail.com> wrote:

> 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
>
>
> 2014-10-23 16:38 GMT+02:00 Khalifa Lame <khalibloo at gmail.com>:
> > 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
> > Bf-python at blender.org
> > http://lists.blender.org/mailman/listinfo/bf-python
> >
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
>



-- 
khalibloo®
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20141023/cb2c2934/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 338.png
Type: image/png
Size: 645 bytes
Desc: not available
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20141023/cb2c2934/attachment.png>


More information about the Bf-python mailing list