Compilation and how to use

This information helps you to incorporate Shadow Engine into your Open Inventor (SIM Coin) application and compile it.

How to compile

Shadow Engine minimal application

This example shows the minimal code which adds Shadow Engine into your application.

/* ---------------------------------------------------------------------------
 * Authors:      Tomáš Burian (tburian _AT centrum.cz)            
 *
 * THIS SOFTWARE IS NOT COPYRIGHTED
 *
 * This source code is offered for use in the public domain.
 * You may use, modify or distribute it freely.
 *
 * This source code is distributed in the hope that it will be useful but
 * WITHOUT ANY WARRANTY.  ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
 * DISCLAIMED.  This includes but is not limited to warranties of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * If you find the source code useful, authors will kindly welcome
 * if you give them credit and keep their names with their source code,
 * but do not feel to be forced to do so.
 * ---------------------------------------------------------------------------
 */


//----------------------------------------------------------------------------
// INCLUDEs
//----------------------------------------------------------------------------

#define APPNAME "SE mini"
#define VERSION "v0.3"

#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <Inventor/manips/SoPointLightManip.h>
#include <Inventor/Win/viewers/SoWinExaminerViewer.h>
#include <Inventor/Win/SoWin.h>
#include <Inventor/SoDB.h>
//
#include "ShadowEngine/ShadowManager.h"

//----------------------------------------------------------------------------
// IMPLEMENTATION
//----------------------------------------------------------------------------

// Linker: Link with main (not WinMain)
// and use a console
#pragma comment(linker, "/entry:\"mainCRTStartup\"")
#pragma comment(linker, "/subsystem:\"console\"")

char title[50] = "";


int main(int argc, char **argv)
{
  SoDB::init();

  // Show FPS
  putenv("IV_SEPARATOR_MAX_CACHES=0");
  putenv("COIN_SHOW_FPS_COUNTER=1");

  // Initialisation
  HWND window = SoWin::init(argv[0]);
  if (window == NULL) exit(1);

  // This is the highest scene root (with shadow scene) that will
  // be shown in viewer; camera is added to it ass well
  SoSeparator * topRoot = new SoSeparator();
  topRoot->ref();

  // Root of the user's scene
  // create your scene under this root node
  SoSeparator * root = new SoSeparator();

  // Camera
  SoPerspectiveCamera * camera = new SoPerspectiveCamera;
  camera->position = SbVec3f(0.f, 20.f, 50.f);
  camera->pointAt(SbVec3f(0, 0, 0));

  // Light 1
  SoPointLightManip * light1 = new SoPointLightManip;
  light1->location.setValue(30.0f, 70.0f, 40.0f); 
  light1->intensity.setValue(0.5f);
  light1->color.setValue(SbColor(0.9f,0.9f,0.9f));
  light1->on = true;
  root->addChild(light1);

  // First, create a parent node for a new object
  SoSeparator * objectParent = new SoSeparator;  

  // Load object
  const char * filename = "stonehenge.iv";
  SoInput in;
  if (!in.openFile(filename)) {
    printf("Can not open input file '%s'.\n", filename);
    exit(-1);
  }
  SoSeparator *object = SoDB::readAll(&in);
  if (object == NULL) {
    printf("Can not read input file '%s'.\n", filename);
    exit(-1);
  }

  objectParent->addChild(object);

  root->addChild(objectParent);


// Shadow Manager (SM) ///////////////////////////////////////////////////////

  // Create Shadow manager based on user's scene root and environment node. 
  CShadowManager * shadowManager = new CShadowManager(root, NULL);

  // register lights and objects in SM
  shadowManager->addLight(light1);
  shadowManager->addObject(object);

  // select shadow computation algorithm
  shadowManager->setMethod(zfail);

  // create shadow scene 
  topRoot->addChild(camera);
  topRoot->addChild(shadowManager->getShadowSceneRoot());

// Shadow Manager end ////////////////////////////////////////////////////////

  // Create viewer
  SoWinExaminerViewer *viewer = new SoWinExaminerViewer(window);

  // Shadow Manager: TURN ON THE STENCIL BUFFER SUPPORT !!!
  // this must be done to see any shadows
  viewer->setStencilBuffer(TRUE);

  // because of render area, viewers do that automaticaly
  camera->viewAll(topRoot, viewer->getViewportRegion());


  viewer->setSceneGraph(topRoot); 
  sprintf(title,"%s %s", APPNAME, VERSION);
  viewer->setTitle(title);

  viewer->show();
 
  // Show window and start render loop
  SoWin::show(window);
  SoWin::mainLoop();

  // Free memory
  delete viewer;
  topRoot->unref();

  return 0;
}


Generated on Wed May 17 17:27:52 2006 for Shadow Engine by  doxygen 1.4.6-NO