Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
SoXtRenderArea Class Reference

The SoXtRenderArea class adds scenegraph handling and event management. More...

#include <Inventor/Xt/SoXtRenderArea.h>

Inheritance diagram for SoXtRenderArea:
SoXtGLWidget SoXtComponent SoXtObject SoXtViewer SoXtFullViewer SoXtConstrainedViewer SoXtExaminerViewer SoXtPlaneViewer SoXtFlyViewer

Public Member Functions

 SoXtRenderArea (Widget parent=NULL, const char *name=NULL, SbBool embed=TRUE, SbBool mouseInput=TRUE, SbBool keyboardInput=TRUE)
 
 ~SoXtRenderArea ()
 
virtual void setSceneGraph (SoNode *scene)
 
virtual SoNode * getSceneGraph (void)
 
void setOverlaySceneGraph (SoNode *scene)
 
SoNode * getOverlaySceneGraph (void)
 
void setBackgroundColor (const SbColor &color)
 
const SbColor & getBackgroundColor (void) const
 
void setBackgroundIndex (int idx)
 
int getBackgroundIndex (void) const
 
void setOverlayBackgroundIndex (int idx)
 
int getOverlayBackgroundIndex (void) const
 
void setColorMap (int start, int num, const SbColor *colors)
 
void setOverlayColorMap (int start, int num, const SbColor *colors)
 
void setViewportRegion (const SbViewportRegion &newRegion)
 
const SbViewportRegion & getViewportRegion (void) const
 
void setTransparencyType (SoGLRenderAction::TransparencyType type)
 
SoGLRenderAction::TransparencyType getTransparencyType (void) const
 
void setAntialiasing (SbBool smoothing, int numPasses)
 
void getAntialiasing (SbBool &smoothing, int &numPasses) const
 
void setClearBeforeRender (SbBool enable, SbBool zbEnable=TRUE)
 
SbBool isClearBeforeRender (void) const
 
SbBool isClearZBufferBeforeRender (void) const
 
void setClearBeforeOverlayRender (SbBool enable)
 
SbBool isClearBeforeOverlayRender (void) const
 
void setAutoRedraw (SbBool enable)
 
SbBool isAutoRedraw (void) const
 
void setRedrawPriority (uint32_t priority)
 
uint32_t getRedrawPriority (void) const
 
void render (void)
 
void renderOverlay (void)
 
void scheduleRedraw (void)
 
void scheduleOverlayRedraw (void)
 
void redrawOnSelectionChange (SoSelection *selection)
 
void redrawOverlayOnSelectionChange (SoSelection *selection)
 
void setEventCallback (SoXtRenderAreaEventCB *func, void *user=NULL)
 
void setSceneManager (SoSceneManager *manager)
 
SoSceneManager * getSceneManager (void) const
 
void setOverlaySceneManager (SoSceneManager *manager)
 
SoSceneManager * getOverlaySceneManager (void) const
 
void setGLRenderAction (SoGLRenderAction *action)
 
SoGLRenderAction * getGLRenderAction (void) const
 
void setOverlayGLRenderAction (SoGLRenderAction *action)
 
SoGLRenderAction * getOverlayGLRenderAction (void) const
 
SbBool sendSoEvent (const SoEvent *event)
 
void registerDevice (SoXtDevice *device)
 
void unregisterDevice (SoXtDevice *device)
 
- Public Member Functions inherited from SoXtGLWidget
void setBorder (const SbBool enable)
 
SbBool isBorder (void) const
 
virtual void setDoubleBuffer (const SbBool enable)
 
SbBool isDoubleBuffer (void) const
 
void setDrawToFrontBufferEnable (const SbBool enable)
 
SbBool isDrawToFrontBufferEnable (void) const
 
void setQuadBufferStereo (const SbBool enable)
 
SbBool isQuadBufferStereo (void) const
 
void setAccumulationBuffer (const SbBool enable)
 
SbBool getAccumulationBuffer (void) const
 
void setStencilBuffer (const SbBool enable)
 
SbBool getStencilBuffer (void) const
 
void setAlphaChannel (const SbBool enable)
 
SbBool getAlphaChannel (void) const
 
void setOverlayRender (const SbBool onoff)
 
SbBool isOverlayRender (void) const
 
void setSampleBuffers (const int numsamples)
 
int getSampleBuffers (void) const
 
void setStealFocus (SbBool enable)
 
SbBool isStealFocus (void) const
 
Widget getGLWidget (void) const
 
Widget getNormalWidget (void) const
 
Widget getOverlayWidget (void) const
 
SbBool hasOverlayGLArea (void) const
 
SbBool hasNormalGLArea (void) const
 
unsigned long getOverlayTransparentPixel (void)
 
void getPointSizeLimits (SbVec2f &range, float &granularity)
 
void getLineWidthLimits (SbVec2f &range, float &granularity)
 
GLXContext getNormalContext (void)
 
GLXContext getOverlayContext (void)
 
Window getNormalWindow (void)
 
Window getOverlayWindow (void)
 
int getOverlayColorMapSize (void)
 
int getColorMapSize (void)
 
virtual void setNormalVisual (XVisualInfo *visual)
 
XVisualInfo * getNormalVisual (void)
 
virtual void setOverlayVisual (XVisualInfo *visual)
 
XVisualInfo * getOverlayVisual (void)
 
- Public Member Functions inherited from SoXtComponent
virtual ~SoXtComponent ()
 
virtual void show (void)
 
virtual void hide (void)
 
virtual void setComponentCursor (const SoXtCursor &cursor)
 
SbBool isFullScreen (void) const
 
SbBool setFullScreen (const SbBool onoff)
 
SbBool isVisible (void)
 
SbBool isTopLevelShell (void) const
 
Widget getWidget (void) const
 
Widget getBaseWidget (void) const
 
Widget getShellWidget (void) const
 
Widget getParentWidget (void) const
 
void setSize (const SbVec2s size)
 
SbVec2s getSize (void) const
 
void setTitle (const char *const title)
 
const char * getTitle (void) const
 
void setIconTitle (const char *const title)
 
const char * getIconTitle (void) const
 
const char * getWidgetName (void) const
 
const char * getClassName (void) const
 
void setWindowCloseCallback (SoXtComponentCB *const func, void *const user=NULL)
 
Display * getDisplay (void)
 
void fitSize (const SbVec2s size)
 
void addWindowCloseCallback (SoXtComponentCB *callback, void *closure=NULL)
 
void removeWindowCloseCallback (SoXtComponentCB *callback, void *closure=NULL)
 
- Public Member Functions inherited from SoXtObject
virtual SoType getTypeId (void) const =0
 
SbBool isOfType (SoType type) const
 

Static Public Member Functions

static uint32_t getDefaultRedrawPriority (void)
 
- Static Public Member Functions inherited from SoXtComponent
static void setWidgetCursor (Widget w, const SoXtCursor &cursor)
 
static SoXtComponentgetComponent (Widget widget)
 
static void initClasses (void)
 
- Static Public Member Functions inherited from SoXtObject
static void initClass (void)
 
static SoType getClassTypeId (void)
 
static void init (void)
 

Protected Member Functions

 SoXtRenderArea (Widget parent, const char *name, SbBool embed, SbBool mouseInput, SbBool keyboardInput, SbBool build)
 
virtual void redraw (void)
 
virtual void actualRedraw (void)
 
virtual void redrawOverlay (void)
 
virtual void actualOverlayRedraw (void)
 
virtual SbBool processSoEvent (const SoEvent *const event)
 
virtual void processEvent (XAnyEvent *event)
 
virtual void initGraphic (void)
 
virtual void initOverlayGraphic (void)
 
virtual void sizeChanged (const SbVec2s &size)
 
virtual void widgetChanged (Widget widget)
 
virtual void afterRealizeHook (void)
 
Widget buildWidget (Widget parent)
 
virtual const char * getDefaultWidgetName (void) const
 
virtual const char * getDefaultTitle (void) const
 
virtual const char * getDefaultIconTitle (void) const
 
virtual SbBool glScheduleRedraw (void)
 
- Protected Member Functions inherited from SoXtGLWidget
 SoXtGLWidget (Widget const parent=NULL, const char *const name=NULL, const SbBool embed=TRUE, const int glmodes=SO_GL_RGB, const SbBool build=TRUE)
 
 ~SoXtGLWidget ()
 
Widget buildWidget (Widget parent)
 
void setGLSize (const SbVec2s size)
 
SbVec2s getGLSize (void) const
 
float getGLAspectRatio (void) const
 
void setGlxSize (const SbVec2s size)
 
SbVec2s getGlxSize (void) const
 
float getGlxAspectRatio (void) const
 
void setStereoBuffer (SbBool flag)
 
SbBool isStereoBuffer (void) const
 
SbBool isRGBMode (void)
 
void glLockNormal (void)
 
void glUnlockNormal (void)
 
void glLockOverlay (void)
 
void glUnlockOverlay (void)
 
void glSwapBuffers (void)
 
void glFlushBuffer (void)
 
int getDisplayListShareGroup (GLXContext context)
 
Widget getGlxMgrWidget (void)
 
- Protected Member Functions inherited from SoXtComponent
 SoXtComponent (Widget const parent=NULL, const char *const name=NULL, const SbBool embed=TRUE)
 
void setClassName (const char *const name)
 
void setBaseWidget (Widget widget)
 
void registerWidget (Widget widget)
 
void unregisterWidget (Widget widget)
 
void addVisibilityChangeCallback (SoXtComponentVisibilityCB *const func, void *const user=NULL)
 
void removeVisibilityChangeCallback (SoXtComponentVisibilityCB *const func, void *const user=NULL)
 
void invokeVisibilityChangeCallbacks (const SbBool enable) const
 
void invokeWindowCloseCallbacks (void) const
 
virtual void windowCloseAction (void)
 

Additional Inherited Members

- Static Protected Member Functions inherited from SoXtGLWidget
static void eventHandler (Widget, SoXtGLWidget *, XAnyEvent *, Boolean *)
 
- Protected Attributes inherited from SoXtGLWidget
SbBool waitForExpose
 
SbBool drawToFrontBuffer
 
- Protected Attributes inherited from SoXtComponent
SbBool firstRealize
 

Detailed Description

The SoXtRenderArea class adds scenegraph handling and event management.

The SoXtRenderArea class is a component that adds scenegraph management and input device event handling to the SoXtGLWidget component.

The class has many convenient methods for controlling aspects of the rendering, like for instance transparency, aliasing and for scheduling of redraws.

Native toolkit events are caught by SoXtRenderArea components, translated to Coin SoEvent instances and passed on to the scenegraph, in case the user is doing interactive operations on for instance Coin geometry draggers.

SoXtRenderArea is the first non-abstract component in it's inheritance hierarchy that you can use directly from client application code to set up a scenegraph viewer canvas.

For an SoXtRenderArea component to properly display your scenegraph, it must contain an SoCamera-derived node and at least one SoLight-derived lightsource node.

Here's a complete, stand-alone example on how to set up an SoXtRenderArea with a scenegraph:

#include <Inventor/Xt/SoXt.h>
#include <Inventor/Xt/SoXtRenderArea.h>
#include <Inventor/nodes/SoCube.h>
#include <Inventor/nodes/SoRotor.h>
#include <Inventor/nodes/SoArray.h>
#include <Inventor/nodes/SoDirectionalLight.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <Inventor/nodes/SoSeparator.h>
// Set up a simple scenegraph, just for demonstration purposes.
static SoSeparator *
get_scene_graph(void)
{
SoSeparator * root = new SoSeparator;
SoGroup * group = new SoGroup;
SoRotor * rotor = new SoRotor;
rotor->rotation = SbRotation(SbVec3f(0.2, 0.5, 0.9), M_PI/4.0);
group->addChild(rotor);
SoCube * cube = new SoCube;
group->addChild(cube);
SoArray * array = new SoArray;
array->origin = SoArray::CENTER;
array->addChild(group);
array->numElements1 = 2;
array->numElements2 = 2;
array->separation1 = SbVec3f(4, 0, 0);
array->separation2 = SbVec3f(0, 4, 0);
root->addChild(array);
return root;
}
int
main(int argc, char ** argv)
{
Widget window = SoXt::init(argv[0]);
SoSeparator * root = new SoSeparator;
root->ref();
SoPerspectiveCamera * camera;
root->addChild(camera = new SoPerspectiveCamera);
root->addChild(new SoDirectionalLight);
SoSeparator * userroot = get_scene_graph();
root->addChild(userroot);
SoXtRenderArea * renderarea = new SoXtRenderArea(window);
camera->viewAll(userroot, renderarea->getViewportRegion());
renderarea->setSceneGraph(root);
renderarea->setBackgroundColor(SbColor(0.0f, 0.2f, 0.3f));
if (argc > 1) {
renderarea->setTitle(argv[1]);
renderarea->setIconTitle(argv[1]);
}
renderarea->show();
SoXt::show(window);
delete renderarea;
root->unref();
return 0;
}

Constructor & Destructor Documentation

◆ SoXtRenderArea() [1/2]

SoXtRenderArea::SoXtRenderArea ( Widget  parent = NULL,
const char *  name = NULL,
SbBool  embed = TRUE,
SbBool  mouseInput = TRUE,
SbBool  keyboardInput = TRUE 
)

Public constructor.

◆ ~SoXtRenderArea()

SoXtRenderArea::~SoXtRenderArea ( )

Destructor.

◆ SoXtRenderArea() [2/2]

SoXtRenderArea::SoXtRenderArea ( Widget  parent,
const char *  name,
SbBool  embed,
SbBool  mouseInput,
SbBool  keyboardInput,
SbBool  build 
)
protected

Protected constructor used by derived classes.

Member Function Documentation

◆ setSceneGraph()

void SoXtRenderArea::setSceneGraph ( SoNode *  scene)
virtual

This method sets the scene graph to be rendered in the normal bitmap planes.

See also
getSceneGraph(), setOverlaySceneGraph()

Reimplemented in SoXtViewer.

◆ getSceneGraph()

SoNode * SoXtRenderArea::getSceneGraph ( void  )
virtual

This method returns a reference to the scene graph root node as set by the user.

See also
SoXtRenderArea::getSceneManager()

Reimplemented in SoXtViewer.

◆ setOverlaySceneGraph()

void SoXtRenderArea::setOverlaySceneGraph ( SoNode *  scene)

This method sets the scene graph to render for the overlay bitmap planes.

It will automatically take care of setting up overplay planes in the OpenGL canvas if the OpenGL hardware and driver supports it.

Important note: not all graphics hardware and / or drivers for graphics hardware support overlay planes, so application programmers are adviced to find some other way of accomplishing what they want to do before resorting to using overlay planes. Using overlay planes will in practice severely limit the portability of applications which depend on them being available.

See also
setSceneGraph(), getOverlaySceneGraph()

◆ getOverlaySceneGraph()

SoNode * SoXtRenderArea::getOverlaySceneGraph ( void  )

This method returns the scene graph for the overlay scene.

◆ setBackgroundColor()

void SoXtRenderArea::setBackgroundColor ( const SbColor &  color)

This method sets the background color of the scene.

◆ getBackgroundColor()

const SbColor & SoXtRenderArea::getBackgroundColor ( void  ) const

This method returns the background color for the scene.

◆ setBackgroundIndex()

void SoXtRenderArea::setBackgroundIndex ( int  idx)

This method sets the index of the background color for the scene.

◆ getBackgroundIndex()

int SoXtRenderArea::getBackgroundIndex ( void  ) const

This method returns the index of the background color for the scene.

◆ setOverlayBackgroundIndex()

void SoXtRenderArea::setOverlayBackgroundIndex ( int  idx)

This method sets the index of the background for the overlay scene.

◆ getOverlayBackgroundIndex()

int SoXtRenderArea::getOverlayBackgroundIndex ( void  ) const

This method returns the index of the background for the overlay scene.

◆ setColorMap()

void SoXtRenderArea::setColorMap ( int  start,
int  num,
const SbColor *  colors 
)

This method sets the colormap for the scene.

◆ setOverlayColorMap()

void SoXtRenderArea::setOverlayColorMap ( int  start,
int  num,
const SbColor *  colors 
)

This method sets the colormap for the overlay scene.

◆ setViewportRegion()

void SoXtRenderArea::setViewportRegion ( const SbViewportRegion &  region)

This method sets the viewport region.

◆ getViewportRegion()

const SbViewportRegion & SoXtRenderArea::getViewportRegion ( void  ) const

This method returns the viewport region.

◆ setTransparencyType()

void SoXtRenderArea::setTransparencyType ( SoGLRenderAction::TransparencyType  type)

This method sets the transparency type to be used for the scene.

◆ getTransparencyType()

SoGLRenderAction::TransparencyType SoXtRenderArea::getTransparencyType ( void  ) const

This method returns the transparency type used for the scene.

◆ setAntialiasing()

void SoXtRenderArea::setAntialiasing ( SbBool  smoothing,
int  numPasses 
)

This method sets the antialiasing used for the scene.

The smoothing flag signifies whether or not line and point aliasing should be turned on. See documentation of SoGLRenderAction::setSmoothing(), which will be called from this function.

numPasses gives the number of re-renderings to do of the scene, blending together the results from slight "jitters" of the camera view, into the OpenGL accumulation buffer. For further information, see documentation of SoGLRenderAction::setNumPasses() and SoXtGLWidget::setAccumulationBuffer().

◆ getAntialiasing()

void SoXtRenderArea::getAntialiasing ( SbBool &  smoothing,
int &  numPasses 
) const

This method returns the antialiasing used for the scene.

◆ setClearBeforeRender()

void SoXtRenderArea::setClearBeforeRender ( SbBool  enable,
SbBool  zbEnable = TRUE 
)

This method sets whether the render buffer should be cleared before rendering.

The first argument specifies whether or not to clear out the pixels in the buffer, the second argument specifies whether or not the z-buffer values should be cleared between renderings.

Setting the first argument to FALSE can for instance be used when you want to clear out the buffer yourself, for instance by drawing a background image "under" the 3D scene rendered by Coin / Inventor.

◆ isClearBeforeRender()

SbBool SoXtRenderArea::isClearBeforeRender ( void  ) const

This method returns whether the render buffer is cleared before each render.

◆ isClearZBufferBeforeRender()

SbBool SoXtRenderArea::isClearZBufferBeforeRender ( void  ) const

This method returns whether the render buffer's Z buffer is cleared before each render.

◆ setClearBeforeOverlayRender()

void SoXtRenderArea::setClearBeforeOverlayRender ( SbBool  enable)

This method sets whether the overlay render buffer should be cleared before each render or not.

◆ isClearBeforeOverlayRender()

SbBool SoXtRenderArea::isClearBeforeOverlayRender ( void  ) const

This method returns whether the overlay render buffer is cleared before each redraw or not.

◆ setAutoRedraw()

void SoXtRenderArea::setAutoRedraw ( SbBool  enable)

This method sets whether redrawing should be handled automatically or not when data in the scenegraph changes.

The default setting causes the renderarea to automatically trigger a redraw of the scenegraph contents.

◆ isAutoRedraw()

SbBool SoXtRenderArea::isAutoRedraw ( void  ) const

This method returns whether redrawing is handled automatically not.

◆ setRedrawPriority()

void SoXtRenderArea::setRedrawPriority ( uint32_t  priority)

This method sets the redraw priority.

◆ getRedrawPriority()

uint32_t SoXtRenderArea::getRedrawPriority ( void  ) const

This method returns the redraw priority.

◆ getDefaultRedrawPriority()

uint32_t SoXtRenderArea::getDefaultRedrawPriority ( void  )
static

This function returns the default redraw priority.

◆ render()

void SoXtRenderArea::render ( void  )

This method causes the immediate rendering of the scene, by calling SoXtRenderArea::redraw().

◆ renderOverlay()

void SoXtRenderArea::renderOverlay ( void  )

This method renders the overlay scene.

◆ scheduleRedraw()

void SoXtRenderArea::scheduleRedraw ( void  )

This method schedules a redraw to happen at a later time (when the application has processed it's other events first).

◆ scheduleOverlayRedraw()

void SoXtRenderArea::scheduleOverlayRedraw ( void  )

This method schedules a redraw of the overlay scene.

◆ redrawOnSelectionChange()

void SoXtRenderArea::redrawOnSelectionChange ( SoSelection *  selection)

Do automatic redraw of the scenegraph when a selection under the SoSelection node is changed.

Pass NULL to deactivate.

(Only one SoSelection node can be monitored at any given time. This is obviously a rather silly design flaw. We choose to match the original Inventor API here, but this will probably change in the next major revision of the library.)

◆ redrawOverlayOnSelectionChange()

void SoXtRenderArea::redrawOverlayOnSelectionChange ( SoSelection *  selection)

Do automatic redraw of the scenegraph in the overlay planes when a selection under the SoSelection node is changed.

Pass NULL to deactivate.

See also
SoXtRenderArea::redrawOnSelectionChange()

◆ setEventCallback()

void SoXtRenderArea::setEventCallback ( SoXtRenderAreaEventCB *  func,
void *  user = NULL 
)

This method sets the render area event callback.

◆ setSceneManager()

void SoXtRenderArea::setSceneManager ( SoSceneManager *  manager)

This method sets the normal scene SoSceneManager object.

The previous set scene manager is deleted, and there is no way to currently avoid that. This might change in the future.

◆ getSceneManager()

SoSceneManager * SoXtRenderArea::getSceneManager ( void  ) const

This method returns the normal scene SoSceneManager object.

Having a reference to the SoSceneManager instance is useful for getting at the real root node of the rendering scenegraph, including camera, headlight and miscellaneous drawstyle nodes. The getSceneGraph() method will only return the user scenegrah for SoXtRenderArea subclass SoXtViewer and further subclasses. The reason this is not always what you want is because certain actions (like the SoRayPickAction) needs to traverse a valid camera if it should work as expected.

If you need to get a pointer to the real root node use this method to get the SoSceneManager instance reference used by the SoXtRenderArea, then use SoSceneManager::getSceneGraph() to get the root node Coin uses for rendering.

◆ setOverlaySceneManager()

void SoXtRenderArea::setOverlaySceneManager ( SoSceneManager *  manager)

This method sets the overlay scene SoSceneManager object.

The previous set scene manager is not freed and will leak unless the user frees it.

◆ getOverlaySceneManager()

SoSceneManager * SoXtRenderArea::getOverlaySceneManager ( void  ) const

This method returns the overlay scene SoSceneManager object.

◆ setGLRenderAction()

void SoXtRenderArea::setGLRenderAction ( SoGLRenderAction *  action)

This method sets the SoGLRenderAction object for the normal scene.

◆ getGLRenderAction()

SoGLRenderAction * SoXtRenderArea::getGLRenderAction ( void  ) const

This method returns the SoGLRenderAction object for the normal scene.

◆ setOverlayGLRenderAction()

void SoXtRenderArea::setOverlayGLRenderAction ( SoGLRenderAction *  action)

This method sets the SoGLRenderAction object for rendering the overlay scenegraph.

◆ getOverlayGLRenderAction()

SoGLRenderAction * SoXtRenderArea::getOverlayGLRenderAction ( void  ) const

This method returns the SoGLRenderAction object for the overlay scene graph.

◆ sendSoEvent()

SbBool SoXtRenderArea::sendSoEvent ( const SoEvent *  event)

This method posts and processes an SoEvent object to the SoXtRenderArea-based component and returns the result value from the event handler. This is a synchronous operation.

◆ registerDevice()

void SoXtRenderArea::registerDevice ( SoXtDevice device)

This method adds device to the list of devices handling events for this component.

◆ unregisterDevice()

void SoXtRenderArea::unregisterDevice ( SoXtDevice device)

This method removes device from the list of devices handling events for this component.

◆ redraw()

void SoXtRenderArea::redraw ( void  )
protectedvirtual

This method is called from the render() method and takes care of setting up the context for OpenGL rendering (by making the OpenGL canvas the current context and specifying either the front or back buffer for rendering, depending on whether we're in singlebuffer or doublebuffer mode).

After setting up the OpenGL context, it calls actualRedraw() for the actual scenegraph rendering to take place.

Finally, the OpenGL buffers are either swapped back-to-front (for doublebuffering) or flushed (for singlebuffering), and our OpenGL context is unlocked.

The application programmer may override this method if extreme low-level control of the rendering process is necessary. Usually, you should be able to get away with overriding actualRedraw() for special cases, though.

Implements SoXtGLWidget.

◆ actualRedraw()

void SoXtRenderArea::actualRedraw ( void  )
protectedvirtual

This method instantly redraws the normal (non-overlay) scenegraph by calling SoSceneManager::render().

Subclasses may override this method to add their own rendering before or after Coin renders it's scenegraph.

The following is a complete example that demonstrates one way of adding both a background image and foreground (overlay) geometry to the "normal" rendering:

// This example shows how to put a permanent background image on
// your viewer canvas, below the 3D graphics, plus overlay
// foreground geometry. Written by mortene.
// Copyright Kongsberg Oil & Gas Technologies 2002.
// *************************************************************************
#include <Inventor/Xt/SoXt.h>
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
#include <Inventor/nodes/SoBaseColor.h>
#include <Inventor/nodes/SoCone.h>
#include <Inventor/nodes/SoCube.h>
#include <Inventor/nodes/SoImage.h>
#include <Inventor/nodes/SoLightModel.h>
#include <Inventor/nodes/SoOrthographicCamera.h>
#include <Inventor/nodes/SoRotationXYZ.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoTranslation.h>
#include <GL/gl.h>
// *************************************************************************
class MyExaminerViewer : public SoXtExaminerViewer {
public:
MyExaminerViewer(Widget parent, const char * filename);
~MyExaminerViewer();
protected:
virtual void actualRedraw(void);
private:
SoSeparator * bckgroundroot;
SoSeparator * foregroundroot;
SoRotationXYZ * arrowrotation;
};
MyExaminerViewer::MyExaminerViewer(Widget parent, const char * filename)
{
// Coin should not clear the pixel-buffer, so the background image
// is not removed.
this->setClearBeforeRender(FALSE, TRUE);
// Set up background scenegraph with image in it.
this->bckgroundroot = new SoSeparator;
this->bckgroundroot->ref();
SoOrthographicCamera * cam = new SoOrthographicCamera;
cam->position = SbVec3f(0, 0, 1);
cam->height = 1;
// SoImage will be at z==0.0.
cam->nearDistance = 0.5;
cam->farDistance = 1.5;
SoImage * img = new SoImage;
img->vertAlignment = SoImage::HALF;
img->horAlignment = SoImage::CENTER;
img->filename = filename;
this->bckgroundroot->addChild(cam);
this->bckgroundroot->addChild(img);
// Set up foreground, overlayed scenegraph.
this->foregroundroot = new SoSeparator;
this->foregroundroot->ref();
SoLightModel * lm = new SoLightModel;
lm->model = SoLightModel::BASE_COLOR;
SoBaseColor * bc = new SoBaseColor;
bc->rgb = SbColor(1, 1, 0);
cam = new SoOrthographicCamera;
cam->position = SbVec3f(0, 0, 5);
cam->height = 10;
cam->nearDistance = 0;
cam->farDistance = 10;
const double ARROWSIZE = 2.0;
SoTranslation * posit = new SoTranslation;
posit->translation = SbVec3f(-2.5 * ARROWSIZE, 1.5 * ARROWSIZE, 0);
arrowrotation = new SoRotationXYZ;
arrowrotation->axis = SoRotationXYZ::Z;
SoTranslation * offset = new SoTranslation;
offset->translation = SbVec3f(ARROWSIZE/2.0, 0, 0);
SoCube * cube = new SoCube;
cube->width = ARROWSIZE;
cube->height = ARROWSIZE/15.0;
this->foregroundroot->addChild(cam);
this->foregroundroot->addChild(lm);
this->foregroundroot->addChild(bc);
this->foregroundroot->addChild(posit);
this->foregroundroot->addChild(arrowrotation);
this->foregroundroot->addChild(offset);
this->foregroundroot->addChild(cube);
}
MyExaminerViewer::~MyExaminerViewer()
{
this->bckgroundroot->unref();
this->foregroundroot->unref();
}
void
MyExaminerViewer::actualRedraw(void)
{
// Must set up the OpenGL viewport manually, as upon resize
// operations, Coin won't set it up until the SoGLRenderAction is
// applied again. And since we need to do glClear() before applying
// the action..
const SbViewportRegion vp = this->getViewportRegion();
SbVec2s origin = vp.getViewportOriginPixels();
SbVec2s size = vp.getViewportSizePixels();
glViewport(origin[0], origin[1], size[0], size[1]);
const SbColor col = this->getBackgroundColor();
glClearColor(col[0], col[1], col[2], 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Render our scenegraph with the image.
SoGLRenderAction * glra = this->getGLRenderAction();
glra->apply(this->bckgroundroot);
// Render normal scenegraph.
// Increase arrow angle with 1/1000 � every frame.
arrowrotation->angle = arrowrotation->angle.getValue() + (0.001 / M_PI * 180);
// Render overlay front scenegraph.
glClear(GL_DEPTH_BUFFER_BIT);
glra->apply(this->foregroundroot);
}
// *************************************************************************
int
main(int argc, char ** argv)
{
if (argc != 2) {
(void)fprintf(stderr, "\n\n\tUsage: %s <image-filename>\n\n", argv[0]);
exit(1);
}
Widget window = SoXt::init(argv[0]);
MyExaminerViewer * viewer = new MyExaminerViewer(window, argv[1]);
viewer->setSceneGraph(new SoCone);
viewer->show();
SoXt::show(window);
delete viewer;
return 0;
}
// *************************************************************************

Reimplemented in SoXtViewer, SoXtExaminerViewer, SoXtFlyViewer, and SoXtPlaneViewer.

◆ redrawOverlay()

void SoXtRenderArea::redrawOverlay ( void  )
protectedvirtual

This method redraws the overlay scene.

Reimplemented from SoXtGLWidget.

◆ actualOverlayRedraw()

void SoXtRenderArea::actualOverlayRedraw ( void  )
protectedvirtual

This method renders the overlay scene.

◆ processSoEvent()

SbBool SoXtRenderArea::processSoEvent ( const SoEvent *const  event)
protectedvirtual

Toolkit-native events are attempted converted to Coin-generic events in the SoXtRenderArea::processEvent() method. If this succeeds, they are forwarded to this method.

This is a virtual method, and is overridden in it's subclasses to catch events of particular interest to the viewer classes, for instance.

Return TRUE iff the event was processed. If not it should be passed on further up in the inheritance hierarchy by the caller. This last point is extremely important to take note of if you are expanding the toolkit with your own viewer class.

This method is not part of the original SGI InventorXt API. Note that you can still override the toolkit-native processEvent() method instead of this "generic" method.

Reimplemented in SoXtViewer, SoXtFullViewer, SoXtExaminerViewer, SoXtFlyViewer, and SoXtPlaneViewer.

◆ processEvent()

void SoXtRenderArea::processEvent ( XAnyEvent *  event)
protectedvirtual

Overrides SoXtGLWidget::processEvent() to attempt to convert toolkit-native events to Coin-generic events. If this succeeds, the generic SoEvent is forwarded to SoXtRenderArea::processSoEvent().

Reimplemented from SoXtGLWidget.

◆ initGraphic()

void SoXtRenderArea::initGraphic ( void  )
protectedvirtual

This method is invoked to initialize the normal graphics.

Reimplemented from SoXtGLWidget.

◆ initOverlayGraphic()

void SoXtRenderArea::initOverlayGraphic ( void  )
protectedvirtual

This method is invoked to initialize the overlay graphics.

Reimplemented from SoXtGLWidget.

◆ sizeChanged()

void SoXtRenderArea::sizeChanged ( const SbVec2s &  size)
protectedvirtual

Called internally from within the SoXt library when the widget embedded in a component changes it size, which is usually triggered by end-user interaction.

This method is then invoked to notify the component that the size has changed. It is called from the top and all the way down to the bottom, the size being adjusted to take into account extra decorations having been added at each level in the component class hierarchy.

Reimplemented from SoXtGLWidget.

Reimplemented in SoXtViewer, and SoXtFullViewer.

◆ widgetChanged()

void SoXtRenderArea::widgetChanged ( Widget  widget)
protectedvirtual

This is the method which gets called whenever we change which OpenGL widget is used.

Should be overridden in subclasses which directly or indirectly store the return value from the SoXtGLWidget::getGLWidget() method.

See also
sizeChanged()

This method is invoked when a widget in the component is changed.

Reimplemented from SoXtGLWidget.

◆ afterRealizeHook()

void SoXtRenderArea::afterRealizeHook ( void  )
protectedvirtual

A function "hook" / callback invoked just after the window for the component has been realized.

Override this if you need specific initialization for your own component or viewer class to happen right after it has been made visible, but remember to call upwards in the inheritance hierarchy:

void
MyLittleViewer::afterRealizeHook(void)
{
<superclass>::afterRealizeHook();
// [own initialization here]
}

Reimplemented from SoXtComponent.

Reimplemented in SoXtExaminerViewer, SoXtPlaneViewer, and SoXtFlyViewer.

◆ getDefaultWidgetName()

const char * SoXtRenderArea::getDefaultWidgetName ( void  ) const
protectedvirtual

This method returns the default name of a component widget class.

It should be overridden by derived non-abstract classes for the topmost widget in the component to have a proper name.

Reimplemented from SoXtComponent.

Reimplemented in SoXtExaminerViewer, SoXtFlyViewer, and SoXtPlaneViewer.

◆ getDefaultTitle()

const char * SoXtRenderArea::getDefaultTitle ( void  ) const
protectedvirtual

This method returns the default window caption string of the component.

It should be overridden by derived non-abstract classes so the window and popup menu will get a proper title.

Reimplemented from SoXtComponent.

Reimplemented in SoXtExaminerViewer, SoXtFlyViewer, and SoXtPlaneViewer.

◆ getDefaultIconTitle()

const char * SoXtRenderArea::getDefaultIconTitle ( void  ) const
protectedvirtual

This method returns the default icon title of the component.

It should be overridden by derived non-abstract classes so icons will get proper titles.

Reimplemented from SoXtComponent.

Reimplemented in SoXtExaminerViewer, SoXtFlyViewer, and SoXtPlaneViewer.

◆ glScheduleRedraw()

SbBool SoXtRenderArea::glScheduleRedraw ( void  )
protectedvirtual

Will be called whenever scene graph needs to be redrawn. If this method return FALSE, redraw() will be called immediately.

Default method simply returns FALSE. Override this method to schedule a redraw and return TRUE if you're trying to do The Right Thing.

Will be called whenever scene graph needs to be redrawn(). If this method return FALSE, redraw() will be called immediately.

Default method simply returns FALSE. Overload this method to schedule a redraw and return TRUE if you're trying to do The Right Thing.

Reimplemented from SoXtGLWidget.


The documentation for this class was generated from the following files: