Re: textures

New Message Reply Date view Thread view Subject view Author view

MLM Veraart (Veraart++at++fel.tno.nl)
Tue, 30 Mar 1999 20:04:06 +0200


Larry Ramey wrote:
>
> On to the problem:
>
> Given a GeoSet of the general shape:
>
> 1g 2g
> -----------
> | |
> | |
> | |
> -----------
> 3g 4g
>
> I want to map a texture onto it.
>
> 1t 2t
> _______
> | |
> | |
> | |
> -------
> 3t 4t
>
> Obviously the texture is a different size than the GeoSet. The simple
> solution is to distort the texture such that 1g lines up with 1t and 2g
> lines up with 2t, ect,ect. This will cause the texture to stretch or
> compress. This is very easy to do in OpenGL (in fact I have done this in
> the OpenGL version of our code) But how do I make Performer do this?
> Performer want to repeat or clip the texture as needed, yielding an
> undistorted texture, but one that doesn't fit the Geode.

I think you can find the solution in the sample program
/usr/share/Performer/src/pguide/libpf/C/texture.c

You have to set the PFGS_TEXCOORD2 attribute of the geoset.
Don't use TEXGEN, just specify the (u,v) coordinates that you want
for each vertex.

Mario
>
> Here is the relevant code:
>
> void sgManager::textureNode(char* name,char* filename,int nodeNumber){
> // -1 means texture this node, 0 means texture 0th child
> // 1 means texture 1st child,2 means texture 2nd child ect
>
> //This is a hack because ->find() doesn't work on pfNode unless it
> inherits from pfGroup.
> // So I cheated and textured something I "knew" was a Geode. Will have
> to fix later.
> pfNode* thisNode = scene->find(name,pfGeode::getClassType());
> if(thisNode==NULL){
> cout<<" Node named "<<name<<" not found. sgManager::textureNode\n";
> return;
> }
> pfTexture* texture = new pfTexture;
> pfTexEnv* tev = new pfTexEnv;
> if (texture == NULL || tev == NULL){
> pfDelete(texture);
> pfDelete(tev);
> cout<<"Out of performer memory in sgManager::textureNode\n";
> return;
> }
> if(!texture->loadFile(filename)){
> cout<<"File load failed, "<<filename<<" in sgManager::textureNode\n";
> pfDelete(texture);
> return;
> }
>
> pfGeode* textureNode=NULL;
> if (nodeNumber == -1) textureNode = (pfGeode*)thisNode;
> else {
> pfGroup* thisGroup = (pfGroup*) thisNode;
> textureNode = (pfGeode*) thisGroup->getChild(nodeNumber);
> }
> if(!textureNode){
> cout<<"Can't find Child # "<<nodeNumber<<" of Node "<<name<<"\n";
> pfDelete(texture);
> return;
> }
>
> tev->setMode(PFTE_DECAL);
>
> pfEnable(PFEN_TEXGEN);
> pfGeoSet* gSet=NULL;
> // C5D makes an assumtion here that we should texture the first GeoSet.
> // This may need to change later. LER
> gSet=textureNode->getGSet(0);
> pfGeoState* gState=NULL;
> gState = gSet->getGState();
> if (!gState) gState = new pfGeoState;
> gState->setAttr(PFSTATE_TEXTURE,texture);
> gState->setMode(PFSTATE_ENTEXTURE,PF_ON);
> gState->setAttr(PFSTATE_TEXENV, tev);
>
> pfTexGen* texGen = new pfTexGen;
> gState->setMode(PFSTATE_ENTEXGEN,PF_ON);
> gState->setAttr(PFSTATE_TEXGEN,texGen);
> 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);
>
> gSet->setGState(gState);
> }
>
>
>
>
> ---------------------------------------------------------------
> Larry E. Ramey ramey++at++ccpo.odu.edu
> 757-683-6276(office) 757-683-5335 (CAVE)
> "Count the heads man." - Zaphod Bebblebrox
> "Won't weigh you down, with good intentions" -Sarah McLachlan


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Tue Mar 30 1999 - 10:04:14 PST

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