Rendering to "Rendered View" in Blender's Viewport

Is glDrawPixels (Drawing pixels to the screen) pretty much the defacto way of displaying images in Blender’s viewport? If so, I appear to be getting horrible results (Black and white/no colors except tiny rainbow pixels all over the place) with the code below. Any chance you’d know how to do this better? (For getting Arnold’s IPR working within Blender’s “rendered” viewport)

        (width, height), rect = ipr.update(width, height, data)

        v = bgl.Buffer(bgl.GL_FLOAT, 4)
        bgl.glGetFloatv(bgl.GL_VIEWPORT, v)
        vw = v[2]
        vh = v[3]
        bgl.glRasterPos2f(0, vh - 1.0)
        bgl.glPixelZoom(vw / width, -vh / height)
        bgl.glDrawPixels(width, height, bgl.GL_RGBA, bgl.GL_FLOAT,
                         bgl.Buffer(bgl.GL_FLOAT, len(rect), rect))
        bgl.glPixelZoom(1.0, 1.0)
        bgl.glRasterPos2f(0, 0)

Using the above code for the IPR gives me this result in blender’s viewport:

Considering Blender 2.8 to be moving towards OpenGL core though, it might make more sense to start developing this IPR for that though. As this will most likely be removed?

glDrawPixels is deprecated in OpenGL core profile, so in Blender 2.8 you’ll need to use OpenGL textures and GLSL shaders.

Not sure why it would draw like that though, I don’t see anything obviously wrong in the code.

1 Like

Are there any docs yet on migrating 2.79 addons to 2.8? Something a bit more efficient then comparing 2.79 cycles code to cycles 2.8 code, kek

No, as we have not implemented image support for our Python drawing API .

Having said that, you could try using bgl modules texture support, 2.8x is not really ready for porting scripts - YMMV.

1 Like

Maybe the pixel format from Arnold and the one you specify in glDrawPixels are different.

In the LuxCore addon I use textures: https://github.com/LuxCoreRender/BlendLuxCore/blob/master/draw/viewport.py
I would recommend this because it makes it possible to apply Blender’s color management in the viewport (with engine.bind_display_space_shader).

1 Like

Same result using textures, the same way you set up lux render :face_with_raised_eyebrow:

Update: Fixed colors - Now need to figure out how to get arnold shaders to render in IPR:

Hi, is this possible outside of custom engine creation? in my case I’m drawing from Eevee offscreen but want to maintain the color management. thnx