From: Inge Kristian Eliassen (inge.eliassen++at++cmr.no)
Date: 01/12/2004 07:17:07
Hi,
We have a problem with transparent textures and the SGI texture color table extension under Performer. We want to use the texture color table to make parts of the texture transparent (for volume rendering). The problem is that we can not get the texture to become transparent for those texture index values that has alpha value 0 in the texture color table. (We have a pure OpenGL application where this works).
We enable the SGI texture color table in a preDraw function to the pfGeode that draws the polygon the texture is mapped on. If we adjust the color table, the colors on the texture is changing, so the color table is being used, but the transparency is not working.
We do the following in the code:
/*Creating the texture (3D texture):*/
pfTexture *tmpTexture = new pfTexture;
tmpTexture->setFilter(PFTEX_MINFILTER, PFTEX_POINT); // "nearest"
tmpTexture->setFilter(PFTEX_MAGFILTER, PFTEX_POINT); // "nearest"
tmpTexture->setFormat(PFTEX_INTERNAL_FORMAT, PFTEX_I_8);
tmpTexture->setRepeat(PFTEX_WRAP_S, PFTEX_CLAMP);
tmpTexture->setRepeat(PFTEX_WRAP_T, PFTEX_CLAMP);
tmpTexture->setRepeat(PFTEX_WRAP_R, PFTEX_CLAMP);
tmpTexture->setImage((uint *) (image), 1, size, size, size); // size is power of 2
/*create texture environment*/
m_texEnv = new pfTexEnv;
m_texEnv->setMode(GL_REPLACE); // GL_REPLACE == PFTE_REPLACE
/*create texture coordinate */
m_myTexGen = new pfTexGen;
m_myTexGen->setMode(PF_S, PFTG_OBJECT_LINEAR);
m_myTexGen->setMode(PF_T, PFTG_OBJECT_LINEAR);
m_myTexGen->setMode(PF_R, PFTG_OBJECT_LINEAR);
m_myTexGen->setMode(PF_Q, PFTG_OFF);
m_myTexGen->setPlane(PF_S, 0.5f, 0.0f, 0.0f, 0.5f);
m_myTexGen->setPlane(PF_T, 0.0f, 0.5f, 0.0f, 0.5f);
m_myTexGen->setPlane(PF_R, 0.0f, 0.0f, 0.5f, 0.5f);
/*create a geostate */
m_myGeoState = new pfGeoState;
m_myGeoState->setMode(PFSTATE_TRANSPARENCY, PFTR_BLEND_ALPHA); // high
quality transparency
m_myGeoState->setMode(PFSTATE_ENTEXTURE, PF_ON);
m_myGeoState->setMode(PFSTATE_ENLIGHTING, PF_OFF);
m_myGeoState->setMode(PFSTATE_CULLFACE,PFCF_OFF);
m_myGeoState->setAttr(PFSTATE_TEXENV, m_texEnv);
m_myGeoState->setMode(PFSTATE_ENTEXGEN, PF_ON);
m_myGeoState->setAttr(PFSTATE_TEXGEN, m_myTexGen);
/*create the GeoSet */
m_myGeoSet = new pfGeoSet;
m_myGeoSet->setAttr(PFGS_COORD3, PFGS_PER_VERTEX, m_myCoords, 0);
m_myColors = (pfVec4*) new(sizeof(pfVec4)) pfMemory;
(*m_myColors).set(1.0f, 1.0f, 1.0f, 1.0f); // white, opaque polygon color
m_myGeoSet->setAttr(PFGS_COLOR4, PFGS_OVERALL, m_myColors, 0);
m_myGeoSet->setPrimType(PFGS_QUADS);
m_myGeoSet->setNumPrims(m_numPlanes); // for testing m_numPlanes == 1
m_myGeoSet->setGState(m_myGeoState);
m_myGeoSet->setAttr(PFSTATE_TEXTURE, tmpTexture);
/* create the geode */
m_myGeode = new pfGeode;
m_myGeode->addGSet(m_myGeoSet);
/* add pre and post draw functions*/
m_myGeode->setTravData(PFTRAV_DRAW, (void*) m_cTab);
m_myGeode->setTravFuncs(PFTRAV_DRAW, DVRController::pfPreDraw,
DVRController::pfPostDraw);
CLASS::pfPreDraw(pfTraverser *pft, void *userData){
unsigned char* cTab = (unsigned char*) userData;
if(cTab) {
// load the texture colortable
pfNotify(PFNFY_DEBUG, PFNFY_PRINT, "Loading Colortable");
glColorTable(GL_TEXTURE_COLOR_TABLE_SGI, GL_RGBA,
256, GL_RGBA, GL_UNSIGNED_BYTE,
cTab);
}
glEnable(GL_TEXTURE_COLOR_TABLE_SGI);
return PFTRAV_CONT;
}
CLASS::pfPostDraw(pfTraverser *pft, void *userData){
glDisable(GL_TEXTURE_COLOR_TABLE_SGI);
return PFTRAV_CONT;
}
We are running on an SGI Onyx 3xxx with one IR3 pipe. We are using Performer 3.0.2 and CaveLib 2.7.
Note that if we set the alpha value of the polygon color (m_myColors) to a value < 1.0 we get semi-transparent rendering. Guess this means that transparency is o.k., but we still can not get the alpha value from the texture color table to work. It seems to us as if Performer does not notice that we are using GL_REPLACE mode for texture environment (pfTexEnv).
Can someone give us a hint on what is wrong? Maybe we have forgotten something or is there some trick we must do?
Thanks for any help,
Inge K. Eliassen
-- Inge Kristian Eliassen | inge.eliassen+-+at+-+cmr.no Christian Michelsen Research AS | http://www.cmr.no/ Fantoftvegen 38 | +47 55 57 42 58 (office) N-5072 Bergen | +47 55 57 40 41 (fax) Norway | +47 97 57 30 78 (mobile)
This archive was generated by hypermail 2b29 : Mon Jan 12 2004 - 08:51:29 PST