SOOFFSCREENRENDERER(3iv)

πŸ’– SoOffscreenRenderer β€” bestie, we're rendering OFF-SCREEN πŸ’–

okay so real talk, this is SoOffscreenRenderer(3IV) from the 3IV manual, and she's a whole vibe: she renders into an off-screen buffer so you can print stuff or generate texture images. no window, no drama, just pixels. ✨


🌸 INHERITS FROM 🌸

SoOffscreenRenderer

(yes bestie, she's that girl, no parent class listed, she stands alone πŸ’…)


✨ SYNOPSIS ✨

first, the invite:

#include <Inventor/SoOffscreenRenderer.h>

then the components menu, and listen, you get to pick your flavour:

enum Components {
     SoOffscreenRenderer::LUMINANCE

     SoOffscreenRenderer::LUMINANCE_TRANSPARENCY

     SoOffscreenRenderer::RGB
     SoOffscreenRenderer::RGB_TRANSPARENCY

}

and here's the full cast, the whole main-character lineup, Methods from class SoOffscreenRenderer:

                     SoOffscreenRenderer(const SbViewportRegion
                          &viewportRegion)
                     SoOffscreenRenderer(SoGLRenderAction *ra)
                     ~SoOffscreenRenderer()
static float         getScreenPixelsPerInch()
static SbVec2s       getMaximumResolution()
void                 setComponents(Components components)
Components           getComponents() const
void                 setViewportRegion(const SbViewportRegion
                          &region)
const SbViewportRegion &  getViewportRegion() const
void                 setBackgroundColor(const SbColor &c)
const SbColor &      getBackgroundColor() const
void                 setGLRenderAction(const SoGLRenderAction *ra)
SoGLRenderAction *   getGLRenderAction() const
SbBool               render(SoNode *scene)
SbBool               render(SoPath *scene)
unsigned char *      getBuffer() const
SbBool               writeToRGB(FILE *fp) const
SbBool               writeToPostScript(FILE *fp) const
SbBool               writeToPostScript(FILE *fp, const SbVec2f
                          &printSize) const

πŸ¦‹ DESCRIPTION πŸ¦‹

so what does she do? This class is used to render into an off-screen buffer to create a printable image or to generate a texture image. she uses X Pixmaps for rendering (yes, X Pixmaps, we love a retro icon πŸ‘‘). and she's got methods to write that buffer out to a file β€” either as an RGB image or as an encapsulated PostScript description. pick your fighter. πŸ’–


πŸŽ€ METHODS πŸŽ€

the constructors + destructor era

                     SoOffscreenRenderer(const SbViewportRegion
                          &viewportRegion)
                     SoOffscreenRenderer(SoGLRenderAction *ra)
                     ~SoOffscreenRenderer()

Constructors and destructor, obviously, it's giving birth-and-death arc. πŸ’€ here's the tea though: if you pass a render action to the constructor, that action gets used in all subsequent offscreen renderings. no takebacks, she's committed. otherwise, an internal instance of an SoGLRenderAction is maintained, with a viewport region set to the one you passed in by the constructor. 🫢

static float getScreenPixelsPerInch()

returns the number of pixels per inch (in the horizontal direction) of the current X device screen. horizontal only, bestie, that's the axis we care about. πŸ“

static SbVec2s getMaximumResolution()

gets you the maximum supported resolution of the viewport. that's the ceiling, the limit, the "don't even try it" number. 🌈

void setComponents(Components components) / Components getComponents() const

sets or returns the components to be rendered. that's it, that's the whole job. πŸ’…

void setViewportRegion(const SbViewportRegion &region) / const SbViewportRegion & getViewportRegion() const

sets or returns the viewport region used for rendering. BUT LISTEN: this will NOT be applied to the viewport region of any render action passed in. so if you handed her an action, that action's viewport stays exactly as it was. no sneaky edits. 🚫

void setBackgroundColor(const SbColor &c) / const SbColor & getBackgroundColor() const

sets or returns the background color for rendering. aesthetic choices matter. 🎨

void setGLRenderAction(const SoGLRenderAction *ra) / SoGLRenderAction * getGLRenderAction() const

set and get the render action to use for rendering. and this one's cute: this will return any render action passed in by the caller β€” so you get your action back, not a mystery one. ✨

SbBool render(SoNode *scene) / SbBool render(SoPath *scene)

renders the given scene, specified as a node or a path, into an off-screen buffer. node or path, she doesn't discriminate, she slays either way. πŸ”₯

unsigned char * getBuffer() const

returns the buffer containing the rendered image, and okay this one's important so let's go slow. the buffer is an array of unsigned characters. each pixel is stored sequentially by scanline, starting with the lower left corner (yes, bottom-left, not top-left, don't come for me πŸ™ˆ). the data stored for each pixel is determined by the Components set before rendering. pixels are stored in RGBA order and are packed without any padding between pixels or scanlines β€” zero gaps, tight as can be. and the buffer? it's allocated by the offscreen renderer class, and that space gets deleted when the instance is destructed. so do not free it yourself, she handles her own cleanup. πŸ’–

SbBool writeToRGB(FILE *fp) const

writes the buffer as a .rgb file to the given file pointer. simple, clean, iconic. 🌸

SbBool writeToPostScript(FILE *fp) const / SbBool writeToPostScript(FILE *fp, const SbVec2f &printSize) const

writes the buffer as encapsulated PostScript. and here's the nuance bestie: if a print size is not given, the size of the image in the buffer is adjusted so it is the same as the apparent size of the viewport region on the current device. so no print size = she eyeballs it to match your device's viewport. give her a printSize and she does exactly what you said. periodt. πŸ’…


quick recap for the girlies in the back: off-screen rendering, X Pixmaps, RGB or encapsulated PostScript output, buffer in RGBA order starting bottom-left, no padding, allocated and deleted by the class. memorize it, iykyk. πŸ‘‘

and that's the whole page, bestie! this was SoOffscreenRenderer(3IV) from the 3IV manual β€” the footer didn't hand us a date or a version stamp to brag about, just the name itself, so that's our sign-off. mwah, go render something gorgeous. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά