convolve, glConvolutionFilter2DEXT and IR

New Message Reply Date view Thread view Subject view Author view

Olivier Schreiber (olivier++at++sgidev.mdc.com)
Fri, 17 Jan 1997 17:18:50 -0800


I have this simple minded example thanks to Nicolas Gauvin
for using convolve in IRIS GL with performer 2.*
It works fine on an RE2 but does not produce any effect on IR.
The man page for convolve does not specifically say whether
gl convolve is supported on IR.

Additionally, I am trying to convert it to OPEN GL.
The man page says results are unreliable.

Any suggestion appreciated.
Thanks.

ksh> more simple.C
// simpleC.C: simple Performer program for programmer's guide with
convolution
//
// $Revision: 1.3 $
// $Date: 1997/01/18 00:58:14 $
//

#include <math.h>
#include <stdlib.h>
#include <values.h>

#include <Performer/pf/pfChannel.h>
#include <Performer/pf/pfLightSource.h>
#include <Performer/pf/pfNode.h>
#include <Performer/pf/pfScene.h>

#include <Performer/pfutil.h>
#include <Performer/pfdu.h>

#include <gl.h>

//
// Usage() -- print usage advice and exit. This
// procedure is executed in the application process.
//
static void
Usage (void)
{
    pfNotify(PFNFY_FATAL, PFNFY_USAGE, "Usage: simpleC file.ext ...\n");
    exit(1);
}

static void
drawCB( pfChannel* chan, void* data )
{
   static int first = 1;
#define val7x7 0.020408163f
   static float blur7x7[] =
   {
      val7x7, val7x7, val7x7, val7x7, val7x7, val7x7, val7x7,
      val7x7, val7x7, val7x7, val7x7, val7x7, val7x7, val7x7,
      val7x7, val7x7, val7x7, val7x7, val7x7, val7x7, val7x7,
      val7x7, val7x7, val7x7, val7x7, val7x7, val7x7, val7x7,
      val7x7, val7x7, val7x7, val7x7, val7x7, val7x7, val7x7,
      val7x7, val7x7, val7x7, val7x7, val7x7, val7x7, val7x7,
      val7x7, val7x7, val7x7, val7x7, val7x7, val7x7, val7x7,
   };

   if (first) {
#ifdef CONVOLVE
#ifdef OPENGL
glConvolutionFilter2DEXT(
GL_CONVOLUTION_2D_EXT, /*has to be this value*/
GL_RGBA, /*filter kernel internal format*/
7, 7, /*width & height of image pixel array*/
GL_RGBA, /*image internal format*/
GL_FLOAT, /*type of image pixel data*/
(const void*)blur7x7 /* image itself*/
);
#else
      convolve (CV_GENERAL, CV_REDUCE, 7,7, blur7x7, 0.0f );
      pixmode (PM_INPUT_FORMAT, PM_BGR);
      pixmode (PM_OUTPUT_FORMAT, PM_BGR);
#endif
#endif

      first = 0;
   }

#ifdef OPENGL
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#else
  chan->clear();
#endif
  pfDraw();

#ifdef CONVOLVE
/* convolution is done during the rectcopy */
#ifdef OPENGL
glRasterPos2i(2,2);
glCopyPixels(0, 0, 640-0+1, 480-0+1, GL_COLOR);
#else
  rectcopy(0,0,640,480,2,2);
#endif
#endif
}

int
main (int argc, char *argv[])
{
    float t = 0.0f;

    if (argc < 2)
        Usage();

    // Initialize Performer
    pfInit();

    // Use default multiprocessing mode based on number of
    // processors.
    //
    pfMultiprocess( PFMP_DEFAULT );

    // Load all loader DSO's before pfConfig() forks
    pfdInitConverter(argv[1]);

    // initiate multi-processing mode set in pfMultiprocess call
    // FORKs for Performer processes, CULL and DRAW, etc. happen here.
    //
    pfConfig();

    // Append to Performer search path, PFPATH, files in
    // /usr/share/Performer/data */
     pfFilePath(".:/usr/share/Performer/data");

    pfNode *root = pfdLoadFile(argv[1]);
    if (root == NULL)
    {
        pfExit();
        exit(-1);
    }

    // Attach loaded file to a new pfScene
    pfScene *scene = new pfScene;
    scene->addChild(root);

    // Create a pfLightSource and attach it to scene
    scene->addChild(new pfLightSource);

    // Configure and open GL window
    pfPipe *p = pfGetPipe(0);
    pfPipeWindow *pw = new pfPipeWindow(p);
    pw->setWinType(PFPWIN_TYPE_X);
    pw->setName("IRIS Performer");
    pw->setOriginSize(300,400,640,480);
    pw->open();

    // Create and configure a pfChannel.
    pfChannel *chan = new pfChannel(p);
    chan->setScene(scene);
    chan->setFOV(45.0f, 0.0f);
    chan->setTravFunc(PFTRAV_DRAW, drawCB );

    // determine extent of scene's geometry
    pfSphere bsphere;
    root->getBound(&bsphere);
    chan->setNearFar(1.0f, 10.0f * bsphere.radius);

    // Simulate for twenty seconds.
    while (t < 60.0f)
    {
        pfCoord view;
        float s, c,t0;

        // Go to sleep until next frame time.
        pfSync();

        // Initiate cull/draw for this frame.
        pfFrame();

        // Compute new view position.
        t = pfGetTime();
        t0=t;
        pfSinCos(45.0f*t0, &s, &c);
        view.hpr.set(45.0f*t0, -10.0f, 0);
        view.xyz.set(2.0f * bsphere.radius * s,
                     -2.0f * bsphere.radius *c,
                     0.5f * bsphere.radius);
        chan->setView(view.xyz, view.hpr);
    }

    // Terminate parallel processes and exit
    pfExit();
    return 0;
}
ksh>

-- 
Olivier Schreiber olivier++at++sgidev.mdc.com 310 593 9739 FAX 593 0296
Military Transport Aircraft, McDonnell Douglas Corporation
Mail Code D041/0056, 2401 E. Wardlow Road Long Beach, CA 90807-5309
=======================================================================
List Archives, FAQ, FTP:  http://www.sgi.com/Technology/Performer/
            Submissions:  info-performer++at++sgi.com
        Admin. requests:  info-performer-request++at++sgi.com

New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:54:22 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.