3D textures in Performer

New Message Reply Date view Thread view Subject view Author view

Rachael Brady (rbrady++at++ncsa.uiuc.edu)
Mon, 23 Jun 1997 11:55:20 -0500 (CDT)


I am trying to use a 3D texture in Performer. I'm sure people have
been successfully doing this for some time. If anyone has some working
sample code, I'd appreciate seeing it. Otherwise, below is a modified
section of the texture.C example in the /usr/share space.
Everything works beautifully if the third dimension of the texture is
set to 1. As soon as I increase that value to some power of two, I
get an image which is equivalent to the first line of the 3D texture
replicated down the polygon.

Also, I've tried calling pfTexGen::apply() within this code.. that function
never returns. However, the texGen requests are getting applied somehow
because I get different images depending on the plane equations I set
(when using 2D (i.e. sz = 1) or 3D (i.e. sz = 32) textures).

Also note that the MINFILTER and MAGFILTER are not dependant on MIPMAPS.

I'm using an onyx IR system, IRIX 6.2.

Thanks

Rachael Brady
Senior Research Programmer
Biological Imaging Group, NCSA
rbrady++at++ncsa.uiuc.edu

------------------------------------------------------------------------

/usr/share/Performer/src/pguide/libpf/C++/texture.C
... begining of file removed ...
     
    // Set up textures & gstates structures
    pfTexture *tex = new pfTexture;
    pfTexEnv *tev;
    tex->setFilter(PFTEX_MINFILTER, PFTEX_TRILINEAR);
    tex->setFilter(PFTEX_MAGFILTER, PFTEX_TRILINEAR);
    tex->setFormat(PFTEX_INTERNAL_FORMAT, PFTEX_IA_8);
     
    pfGeoState *gstate = new pfGeoState;
    unsigned char *image;
    image = ReadImage() // returns a 256 x 256 x 32 array
                                // (2 bytes per voxel)
    int nc, sx, sy, sz;
         
    nc = 2; sx = 256; sy = 256; sz = 32;
    tex->setImage((uint *) (image), nc, sx, sy, sz);

    gstate->setMode(PFSTATE_TRANSPARENCY, PFTR_BLEND_ALPHA);
    gstate->setMode(PFSTATE_ALPHAFUNC, PFAF_NOTEQUAL);
    gstate->setVal(PFSTATE_ALPHAREF, 0.0f);
    gstate->setAttr(PFSTATE_TEXTURE, tex);
    gstate->setMode(PFSTATE_ENTEXTURE, PF_ON);
    gstate->setMode(PFSTATE_ENLIGHTING,0);
    gstate->setMode(PFSTATE_CULLFACE,PFCF_OFF);
         
    tev = new pfTexEnv;
    gstate->setAttr(PFSTATE_TEXENV, tev);

    // Set up geosets
    pfVec3 *coords = (pfVec3*) new(4*sizeof(pfVec3)) pfMemory;
    coords[0].set(-1.0f, 0.0f, -1.0f);
    coords[1].set( 1.0f, 0.0f, -1.0f );
    coords[2].set( 1.0f, 0.0f, 1.0f );
    coords[3].set(-1.0f, 0.0f, 1.0f );
     
    ushort *vertexlist = (ushort*) new(4*sizeof(ushort)) pfMemory;
    vertexlist[0] = 0;
    vertexlist[1] = 1;
    vertexlist[2] = 2;
    vertexlist[3] = 3;
     
    pfVec4 *colors = (pfVec4*) new(4*sizeof(pfVec4)) pfMemory;
    colors[0].set(1.0f, 1.0f, 1.0f, 1.0f);
    colors[1].set(0.0f, 0.0f, 1.0f, 1.0f);
    colors[2].set(1.0f, 0.0f, 0.0f, 1.0f);
    colors[3].set(0.0f, 1.0f, 0.0f, 1.0f);
     
    ushort *colorlist = (ushort*) new(4*sizeof(ushort)) pfMemory;
    colorlist[0] = 0;
    colorlist[1] = 1;
    colorlist[2] = 2;
    colorlist[3] = 3;
     
    // Use TexGen to gain access to 3D texture
    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_OBJECT_LINEAR);
    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.0f, 0.5f, 0.5f);
    texgen->setPlane(PF_R, 0.0f, 0.5f, 0.0f, 0.5f);
     
    pfGeoSet *gset = new pfGeoSet;
    gset->setAttr(PFGS_COORD3, PFGS_PER_VERTEX, coords, vertexlist);
    gset->setAttr(PFGS_COLOR4, PFGS_PER_VERTEX, colors, colorlist);
    gset->setPrimType(PFGS_QUADS);
    gset->setNumPrims(1);
    gset->setGState(gstate);

    // set up scene graph
    pfGeode *geode1 = new pfGeode;
    geode1->addGSet(gset);

texture.C sample file continues...
=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
            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:55:29 PDT

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