Lighting in draw callback

New Message Reply Date view Thread view Subject view Author view

Bryan Walsh (bryanw++at++earthlink.net)
Fri, 15 Jan 1999 06:28:03 -0700


Hello pfFellows,

Because I need to draw some geometry in native OpenGL, and as a work around
to some sorting issues, I have several pfGroup draw callbacks. The geometry
drawn include pfdCones, pfdSpheres, as well as my native OpenGL geometry.
Everything works fine except the specular component of the material. i.e., I
don't see the highlighting/reflection from the material. Below is a sample
of what I'm trying to do. Any helpful suggestions would be greatly
appreciated.

typedef struct {
   int color;
   int visible;
   pfGeoSet *cone;
   pfMaterial *material;
   pfLightModel *lightmodel;
   pfLight *light[PF_MAX_LIGHTS];
   pfGeoState *state;
   int first;
} ConeData;

int drawCone(pfTraverser *, void *data) {
   ConeData *pd = (ConeData*)data;
   if (pd->first) {
//
// pd->cone = pfdNewCone called externally
// pfdNewCone includes normals
//
      pd->first = 0;
      float fcolor[4];
      fcolor[0] = (float)(pd->color & 0xff) / 0xff;
      fcolor[1] = (float)((pd->color >> 8) & 0xff) / 0xff;
      fcolor[2] = (float)((pd->color >> 16) & 0xff) / 0xff;
      fcolor[3] = 0.2;
      pd->material = new pfMaterial();
      pd->material->setAlpha(0.15f);
      pd->material->setShininess(40.0f);
      pd->material->setColor(PFMTL_DIFFUSE, fcolor[0],fcolor[1],fcolor[2]);
      pd->lightmodel = new pfLightModel();

      pd->light[0] = new pfLight();

      pfPushIdentMatrix();
      pd->light[0]->setPos(0.0f, 1.0f, 0.0f, 0.0f);
      pfPopMatrix();

      pd->lightmodel->setAmbient(0.8f, 0.8f, 0.8f);
      pd->lightmodel->setLocal(PF_OFF);
      pd->lightmodel->setTwoSide(PF_ON);
      pd->state = new pfGeoState();
      pd->state->setMode(PFSTATE_TRANSPARENCY, PFTR_HIGH_QUALITY);
      pd->state->setAttr(PFSTATE_FRONTMTL, pd->material);
      pd->state->setAttr(PFSTATE_BACKMTL, pd->material);
      pd->cone->setGState(pd->state);
   }

   pfPushState();
   pfPushMatrix();
   pfBasicState();

   pd->lightmodel->apply();
   pd->light[0]->on();

   glEnable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
   glDepthMask(GL_FALSE);
   pd->cone->draw();
   glDepthMask(GL_TRUE);

   pfPopMatrix();
   pfPopState();

   return PFTRAV_CONT;
}

Help would be greatly appreciated,

Thanks

Bryan Walsh


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Fri Jan 15 1999 - 05:22:31 PST

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