From: Angus Dorbie (dorbie++at++sgi.com)
Date: 04/25/2001 04:27:13
Stephen Charles Huey wrote:
>
> 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();
No don't call apply here, it's for the draw process and is really an
immediate mode call, Performer is about building a persistent scene
graph. So, yes load the texture but then attach it to some specific
parts of the scene graph (vie a geostate), let Performer do the applying
when you direct it to draw the scene graph.
>
> 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();
Good, you've commented this out, same thing for texgen as for textures.
> 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);
YES! This is how you greate a persistant set of state in Performer, all
you need to do now is attach this state to your geosets.
>
> //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!!!
OK, you never actually take your state information and attach it to your
geosets.
Also you seem to be using the master DCS at the top of the scene as kind
of a viewing matrix. This will make the cull process slightly less
efficient but maybe you don't want to worry about that right now.
Cheers,Angus.
-- For Performer+OpenGL tutorials http://www.dorbie.com/"Whenever there is a conflict between human rights and property rights, human rights must prevail." --Abraham Lincoln
This archive was generated by hypermail 2b29 : Wed Apr 25 2001 - 04:27:46 PDT