basic texture mapping

New Message Reply Date view Thread view Subject view Author view

From: Stephen Charles Huey (sirstevo++at++owlnet.rice.edu)
Date: 04/18/2001 04:44:53


Hey, I'm an undergrad who doesn't know how to do much of anything in
Performer. Right now, I'm loading a simple program that lets me
navigate "worlds" I load. The "world" I'm loading in this test case is
an object (a .iv file) that I created in 3D Studio Max and consists of a
hemisphere and a plane (representing my ground and sky). Note that I
have been successful in loading this object and can navigate even more
complex "worlds". I want to eventually be able to map distinct textures
to both of them (as well as to other objects I load), but for now I'd be
happy to just be able to get a single texture mapped to both of them.
So, I downloaded a sky.bmp texture and used gimp to convert it to
sky.rgb, and in my code, I just wasn't sure what I needed from all the
different things like setFilter, setRepeat, setMode, setAttr, etc, so
this is what I reverse-engineered from somewhere, and it just loads up
the object(s) without a texture:

void create_scene(pfChannel *chan,int argc,char **argv)
{
  Master_Scene = new pfScene;
  Master_Dcs = new pfDCS;

  /* Create a pfScene */
  pfGeoState *gstate = new pfGeoState;
    pfGeoSet *gset = new pfGeoSet;

  /* texture stuff */
  pfEnable(PFEN_TEXTURE);

  pfTexture *TiTex = new pfTexture;
  TiTex->setFilter(PFTEX_MINFILTER, PFTEX_MIPMAP_TRILINEAR);
  TiTex->setFilter(PFTEX_MAGFILTER, PFTEX_BILINEAR);
  TiTex->setRepeat(PFTEX_WRAP_S, PFTEX_CLAMP);
  TiTex->setRepeat(PFTEX_WRAP_T, PFTEX_CLAMP);
  TiTex->loadFile("sky.rgb");
  Titex->apply();

  pfTexGen *texgen = new pfTexGen;
  texgen->setMode(PF_S, PFTG_OBJECT_LINEAR);
  texgen->setMode(PF_T, PFTG_OBJECT_LINEAR);
  texgen->setMode(PF_R, PFTG_OFF);
  texgen->setMode(PF_Q, PFTG_OFF);
  texgen->setPlane(PF_S, 0.5f, 0.0f, 0.0f, 0.5f);
  texgen->setPlane(PF_T, 0.0f, 0.5f, 0.0f, 0.5f);

  pfTexEnv *tev = new pfTexEnv;
  //tev->apply();
  pfOverride(PFSTATE_TEXENV, PF_ON);

  gstate->setMode(PFSTATE_ENTEXTURE, PF_ON);
  gstate->setMode(PFSTATE_ENTEXGEN, PF_ON);
  gstate->setMode(PFSTATE_TRANSPARENCY, PFTR_OFF);
  gstate->setAttr(PFSTATE_TEXENV, tev);
  gstate->setAttr(PFSTATE_TEXGEN, texgen);
  gstate->setAttr(PFSTATE_TEXTURE, TiTex);

  //gset->setAttr(PFGS_TEXCOORD2, 10, 10);

  //pfGroup *group = new pfGroup;

  /* Set up the default GeoState to specify the how the geometry is to
     be displayed.
  */
  gstate->setMode(PFSTATE_ENLIGHTING, PF_ON);

  gstate->setMode(PFSTATE_CULLFACE, PFCF_OFF);

fprintf(stderr,"Master_Scene: %i",Master_Scene);
  Master_Scene->setGState(gstate);

  /* Add a light source to the scene as well as the dcs */
  pfLightSource *myLightSource = new pfLightSource;
  myLightSource->setPos(0,0,10,1);

  Master_Scene->addChild(myLightSource);

  /* Add a light with default settings */
  Master_Scene->addChild(new pfLightSource);

  /* Add the Master DCS, and load the objects under it */
  Master_Scene->addChild(Master_Dcs);
  load_objects(argc,argv,Master_Dcs);

  /* Spread the objects out so we have more of a "scene" */
  spread_objects(Master_Dcs);

  /* Move the whole scene deep into the CAVE */
  debug("moving whole scene: Master_Dcs->setTrans(0.0, 15.0, 0.0);");
  Master_Dcs->setTrans(0.0, 15.0, 0.0);

  /* Assign the Master_Scene to the display channel */
  chan->setScene(Master_Scene);

  /* set initial position and rotations of our channel/camera */
  pfVec3 *INITIALxyz = new pfVec3(INITIAL_X, INITIAL_Y, INITIAL_Z);
  pfVec3 *INITIALhpr = new pfVec3(INITIAL_H, INITIAL_P, INITIAL_R);
  chan->setView(*INITIALxyz, *INITIALhpr);
}

-------

Please help me figure out how to do this seemingly simple thing! I've
stayed up all night and can't get anywhere!!!

Thanks,
Stephen


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Apr 18 2001 - 04:45:03 PDT

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