From: Denis Mohnhaupt (demohn++at++gmx.de)
Date: 12/03/2004 05:18:21
Hi,
I want to create procedural geometry during runtime of my program, but I
have difficulties rendering it correctly, maybe its just an understanding
problem.
I create a GeoState with enabled lighting, texturing and material for both
front and back (the same mat) and a GeoSet consisting of quads, having
arrays for vertices, normals and texture coordinates (no color because i
want it textured).
Now there are two problems,
1st, it doesent show the texture, allthough it seems to be loaded correctly,
in debug mode the pfTexture::LoadFile method returns TRUE.
2nd, the gsets change their appearance, depending on camera height, distance
and angle toward the gset. Also they seem to take over properties from
objects nearby, such as textures and lighting model. I suppose this has
something to do with the order, how the objects are rendered and with the
gstate inheritance but i dont want this, particulary when it changes during
runtime. How can i disable the inheritance?.
Here is the snippet of code from my testing routine
void CMyView::GSetTest()
{
pfTexture * ptex = new pfTexture;
ptex->loadFile("c:\\streckeneditor\\textures\\dummy4to1.rgb");
pfGeoState *pgstate = new pfGeoState;
pgstate->setMode(PFSTATE_ENTEXTURE, PF_ON);
pgstate->setAttr(PFSTATE_ENTEXTURE, ptex);
pfMaterial *pmat= new pfMaterial;
pmat->setColor(PFMTL_DIFFUSE, 0.0f, 0.5f, 0.5f);
pmat->setColor(PFMTL_SPECULAR, 1.0f, 0.0f, 0.0f);
pmat->setSide(PFMTL_BOTH);
pgstate->setAttr(PFSTATE_FRONTMTL, pmat);
pgstate->setAttr(PFSTATE_BACKMTL, pmat);
pgstate->setMode(PFSTATE_ENLIGHTING, PF_ON);
pgstate->apply(); //not sure if this is necessary, but doesent make a
difference
float xoffset = 670.0f; //for testing purposes
float yoffset = -30.0f;
pfBillboard* pbb = new pfBillboard;
pfVec3* pvec = new pfVec3[8];
pvec[0].set(0.0f,0.0f,0.0f);
pvec[1].set(5.0f,5.0f,5.0f);
pvec[2].set(10.0f,10.0f,10.0f);
pvec[3].set(-5.0f,5.0f,5.0f);
pvec[4].set(0.0f,0.0f,0.0f);
pvec[5].set(-5.0f,5.0f,5.0f);
pvec[6].set(10.0f,10.0f,10.0f);
pvec[7].set(5.0f,5.0f,5.0f);
pfVec3* pnorm = new pfVec3[8];
pnorm[0].set(0.0f,-0.5f,1.0f);
pnorm[0].normalize();
pnorm[1].set(0.5f,0.0f,2.0f);
pnorm[1].normalize();
pnorm[2].set(-0.5f,0.0f,2.0f);
pnorm[2].normalize();
pnorm[3].set(0.0f,0.5f,2.0f);
pnorm[3].normalize();
pnorm[4] = pnorm[0] * -1.0f;
pnorm[5] = pnorm[1] * -1.0f;
pnorm[6] = pnorm[2] * -1.0f;
pnorm[7] = pnorm[3] * -1.0f;
pfVec2 *ptexcoords = new pfVec2[8];
ptexcoords[0].set(0.0f,0.0f);
ptexcoords[1].set(1.0f,0.0f);
ptexcoords[2].set(1.0f,1.0f);
ptexcoords[3].set(0.0f,1.0f);
ptexcoords[4].set(0.0f,0.0f);
ptexcoords[5].set(1.0f,0.0f);
ptexcoords[6].set(1.0f,1.0f);
ptexcoords[7].set(0.0f,1.0f);
pfGeoSet* pgs = new pfGeoSet;
pgs->setPrimType(PFGS_QUADS);
pgs->setNumPrims(2);
pgs->setAttr(PFGS_COORD3, PFGS_PER_VERTEX, pvec, NULL);
pgs->setAttr(PFGS_NORMAL3, PFGS_PER_VERTEX, pnorm, NULL);
pgs->setAttr(PFGS_TEXCOORD2, PFGS_PER_VERTEX, ptexcoords, NULL);
pfGeode* pgeode = new pfGeode;
pfDCS* pdcs = new pfDCS;
pdcs->setTrans(xoffset,yoffset,0.0f);
pgeode->addGSet(pgs);
pbb->addGSet(pgs);
pfVec3 axis;
axis.set(0.0f,0.0f,1.0f);
pbb->setPos(0,pfVec3(10.0f,10.0f,10.0f));
pbb->setAxis(axis);
pdcs->addChild(pgeode);
pdcs->addChild(pbb);
m_MainGroup->addChild(pdcs);
}
The method creates a geoset consisting of a double-sided quad (so actually
its 2) with a geostate attached, which has diffuse color set to dark cyan
and specular to red and with a texture. The geode containing the geoset is
set twice into the scene, once directly as child to a dcs node and then as
child to a billboard, which is child of the dcs node as well. This is just
for testing a change in lighting easily, when moving the camera.
However, the texture is definately loaded (loadFile returns 1) but does not
appear on the object, and the quads are white and not lit, because they dont
change in intensity, when i switch global light source on and off (means
removing and adding it to the scene).
When i place another object to the scene, such as a railroad main signal
(containing a switch node which changes the light to have green, yellow or
red texture) the quads assume the same color (means the texture) and
depending on the position of the signal other textures of the signal object
as well (e.g. from an board attached to it). When I move farer away from the
quads, they return to white appearance, also they do it when i remove the
signal from the scene. I tested this kind of reciprocation between the
geosets and other nodes with several pfb-files, it happens often, but not
always, but i couldnt tell the difference between these files, according to
the phenomenon.
I have other, auxiliary geometry (such as grids), which only consist of
lines, they show similar behavior.
What am I doing wrong?
Any help would be highly appreciated.
Thanks in advance,
Denis
-- NEU +++ DSL Komplett von GMX +++ http://www.gmx.net/de/go/dsl GMX DSL-Netzanschluss + Tarif zum supergünstigen Komplett-Preis!
This archive was generated by hypermail 2b29 : Fri Dec 03 2004 - 05:18:29 PST