Re: Incorporating Sound and Animated texture

New Message Reply Date view Thread view Subject view Author view

Angus Dorbie (dorbie++at++bitch.reading.sgi.com)
Sat, 22 Jun 1996 14:08:48 +0100


This Performer 2.0 code loads an animated sequence of images first time in
and draws them on a polygon in sequence, sustaining the last image and
fading it out. This function must be called from the draw process every
frame. The download is performed last in the hope of realising some
performance gain.

Call init explosion before pfConfig and start & position the animation by
writing to this structure from the app. You can worry about frame latencies
if that's important with your application.

The key to this is using the performer image loading, obtaining the
image data array from this and using pfTexLoadImage then pfLoadTex
to select a new image from the animation.

This code doesn't bother about a matching internal & external rgba4 format
so it could be better.

Ignore the bilboarding stuff on the geometry, this is for a fixed eyepoint.

There's a part #ifdef'd out which can be used where reloading the image
doesn't work.

On the audio front you can use the audio library to add sound to your
application, performer doesn't help. On an Onyx you can buy the ASO
(audio serial option) which will add sound capability. On low end systems
you have sound build in. The audio library should work with them all.

A package like audioworks 2 will allow you to build an audio scene graph
which mirrors what you are doing in performer, making your life easier.
You will also be able to drive other external sound devices for improved
quality & spatialised sound.

Rgds,
Angus.

typedef struct Exp_data {
  int type; /* what type of explosion, 0 = none */
  int frame; /* what image frame are we on */
  int first; /* first time in for explosion info */
  float alpha; /* explosion opacity */
  double start_time; /* the explosion start time */
  double current_time; /* the current time */
  pfVec3 c1; /* explosion polygon coordinates */
  pfVec3 c2; /* explosion polygon coordinates */
  pfVec3 c3; /* explosion polygon coordinates */
  pfVec3 c4; /* explosion polygon coordinates */
} Exp_data;

Exp_data *the_explosion;

void init_explosion( void )
{
  the_explosion = pfMalloc(sizeof(Exp_data), pfGetSharedArena());
  the_explosion->type = 0;
}

void draw_explosion( pfChannel *chan )
{
  static short first = TRUE;
  static pfTexture *(animTex[32]);
  static uint *(imgarrays[32]);
  static pfTexture *Anim_Texture;
  static pfTexEnv *animTEnv1;
  char *ext;
  char fname[180];
  int i, dum, old_frame;
  float fx, fy, fz;
  int First = FALSE;

  if(first) /* first time in load the textures */
  {
    first = FALSE;
    /* create a texture environment */
    animTEnv1 = pfNewTEnv(NULL);
    for(i=0; i<NUMFRAMES; i++)
    {
      if(Visual_Mode == VISUAL_TI)
        ext = "inta";
      else
        ext = "rgba";
      animTex[i] = pfNewTex(NULL);
      if(i < 9)
        sprintf(fname, "Animation/sa0%d.%s", i+1, ext);
      else
        sprintf(fname, "Animation/sa%2d.%s", i+1, ext);
      pfLoadTexFile(animTex[i], fname);
      pfGetTexImage(animTex[i], &(imgarrays[i]), &dum, &dum, &dum, &dum);
    }

    /* set the first texture to animate */
    Anim_Texture = animTex[0];
    pfTexFilter(Anim_Texture, PFTEX_MAGFILTER, PFTEX_BILINEAR);
    pfTexFilter(Anim_Texture, PFTEX_MINFILTER, PFTEX_POINT);
    /* want to animate the first one */
    pfTexFormat(Anim_Texture, PFTEX_SUBLOAD_FORMAT, PF_ON);
    pfTexRepeat(Anim_Texture, PFTEX_WRAP, PFTEX_CLAMP);
    pfTexLoadImage(Anim_Texture, imgarrays[0]);
    pfFormatTex(Anim_Texture);
    pfLoadTex(Anim_Texture);
  }

  if(the_explosion->type)
  {

    if(the_explosion->first) /* do all timing in draw */
    {
      the_explosion->first = FALSE;
      the_explosion->current_time = the_explosion->start_time = pfGetTime();
      /* return after first frame, were downloading after the draw to
        save waiting on graphics so the load can take place for 'free'
        I hope. This means were one frame latent, we already have the
        first frame loaded so we don't need to load it, equally I don't
        want to draw it because the download for any given frame is
        performed on the previous frames timing information */
      First = TRUE;
    }

    if(the_explosion->type && !First)
    {
      pfTransparency(PFTR_FAST);

      pfDisable(PFEN_LIGHTING);

      if(the_explosion->type)
      {
        if(Visual_Mode == VISUAL_TI)
          glColor4f(0.5f, 0.5f, 0.5f, the_explosion->alpha);
        else
          glColor4f(1.0f, 1.0f, 1.0f, the_explosion->alpha);
        pfEnable(PFEN_TEXTURE);
        pfApplyTEnv(animTEnv1);

        /* apply the animated texture */
        pfApplyTex(Anim_Texture);
#if 0
        /* quick hack for low end rendering */
        if(the_explosion->frame < NUMFRAMES)
          pfApplyTex(animTex[the_explosion->frame]);
        else
          pfApplyTex(animTex[NUMFRAMES -1]);
#endif

        /* draw textured polygon */
        glBegin(GL_TRIANGLE_STRIP);
            glTexCoord2f(0.0f, 0.0f);
            glVertex3fv(the_explosion->c1);
            glTexCoord2f(1.0f, 0.0f);
            glVertex3fv(the_explosion->c2);
            glTexCoord2f(0.0f, 1.0f);
            glVertex3fv(the_explosion->c3);
            glTexCoord2f(1.0f, 1.0f);
            glVertex3fv(the_explosion->c4);
        glEnd();
        pfDisable(PFEN_TEXTURE);
        pfTransparency(PFTR_OFF);

        old_frame = the_explosion->frame;
        the_explosion->current_time = pfGetTime();
        /* determine the next frame based on timing */
        the_explosion->frame = (int) (SPEED * (the_explosion->current_time -
                                      the_explosion->start_time) );
        if(the_explosion->current_time < the_explosion->start_time)
        { /* stop the explosion */
          the_explosion->type = 0;
          /* start loading the first frame for the next explosion */
          pfTexLoadImage(Anim_Texture, imgarrays[0]);
          pfLoadTex(Anim_Texture);
        }
        else if (the_explosion->frame > (NUMFRAMES -1))
        { /* fade the opacity over a few frames don't bother with clock */
          the_explosion->alpha -= .05;
          if (the_explosion->alpha < 0.02f)
          { /* stop the explosion */
            the_explosion->type = 0;
            /* start loading the first frame for the next explosion */
            pfTexLoadImage(Anim_Texture, imgarrays[0]);
            pfLoadTex(Anim_Texture);
          }
        }
        else if ( the_explosion->frame != old_frame)
        { /* start loading the next frame */
          pfTexLoadImage(Anim_Texture, imgarrays[the_explosion->frame]);
          pfLoadTex(Anim_Texture);
        }
      }
    }
  }
}

On Jun 22, 11:32am, Tawfek Mukhtar wrote:
> Subject: Incorporating Sound and Animated texture
> Hi,
> Has anyone ever tries to incorporate sound and animated texture into their
> scene. Actually what I want to do is to create a walk through inside a
proposed
> theatre so to make it realistic i would like to incorporate short movie (I
> think by changing the texture (with a series of images)in a callback draw
> function) and sound ( with attenuation varies with distance). I am still new
in
> Performer and wish that I can show you my code ( + model) so that any mistake
> can be pointed out but my company contract with the client does not allow me
to
> do so.
> Can anyone show me any QD (quick and dirty) code that I can improvise ?
>
> As for incorporating sound with the database I think using Vega is the other
> alternative but still I'd like to know how to do it in Performer and (if
> neccessary ) what equipment to buy.
>
> Thanks for any reply.
> =======================================================================
> List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer.html
> Submissions: info-performer++at++sgi.com
> Admin. requests: info-performer-request++at++sgi.com
>-- End of excerpt from Tawfek Mukhtar

-- 
Angus Dorbie,
Software Development Manager,
The Reality Centre,
Silicon Graphics Ltd, UK
dorbie++at++reading.sgi.com
=======================================================================
List Archives, FAQ, FTP:  http://www.sgi.com/Technology/Performer.html
            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:53:02 PDT

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