Render to texture in Canvas ?

liviucliviuc Posts: 2


Is is possible to render to a texture in Canvas ? I'd like to use InlineDrawing/OGL to render a mesh (with custom shaders) into a GL texture, which I should then be able to export to a file.

If it's not possible at that level, would there be a way to grab the OGL context of Canvas and perform render-to-texture from there ? I'd like to avoid writing a complete OGL renderer and rather reuse as much from InlineDrawing as possible.

Any pointer in the right direction is highly appreciated !


  • borjaborja Posts: 432 admin

    Hi @liviuc

    There is no builtin presets to do this, but @AlexanderM created a canvas graph to allow to save the viewport render to disk and shared it at

    We plan in the future to add this functionality to the builtin toolset of Fabric!

    Borja Morales
    Technical Product Manager
    Fabric Software Inc.

  • liviucliviuc Posts: 2

    Hi Borja - and thanks for your answer.

    Because I need to render many frames, ideally I'd like to be able to render to a framebuffer and the save the result to disk - while reusing InlineDrawing rendering. In the meanwhile I've figured out how to approach this, my code currently looks something like this:


    glBindFramebuffer(GL_FRAMEBUFFER, framebuffers[0]);
    SInt32 aiViewport[];
    glGetIntegerv(GL_VIEWPORT, aiViewport);
    glViewport(0,0,256,256); // Render on the whole framebuffer, complete from the lower left corner to the upper right

    *[render stuff using InlineDrawing API, shapes, etc. - actually, this does not render anything, it just adds shapes to the scene which should be rendered by the central render callback]


    image = Image2DRGBA();
    image.resize(256, 256);
    glReadPixels(0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE,;

    [save image using OpenImageOutput KL wrappers]

    I am currently stuck trying to trigger rendering the InlineDraw at *. It does look like the setting up the framebuffer and saving it to the disk works fine (I'm clearing it to green and the exported image is green :))

    In the docs I've found this:

    It suggests to use the Fabric C++ API to trigger the rendering. After creating the FabricCore::RTVal of the DrawContext (object) it says:

    "You will then need to fill all of its members accordingly. See the KL snippet below for more detail."

    However, there is no KL snippet below and I am totally puzzled as to what I should fill in. At the moment I call this function from KL right after setting up things, but it does not seem to render anything:

    FabricCore::RTVal drawContext = FabricSplice::constructObjectRTVal("DrawContext");
        printf("Now drawing OGL context \n");

    Could you please help me figure out how to trigger rendering of the InlineDrawing after setting up my framebuffer ?

    Thanks and regards,

Sign In or Register to comment.