Hi Raqin, To enable/disabe modes in OSG you use:
stateset->setMode(GLenum, osg::StateAttribute::ON/OFF); In you case you probably want to disable back face culling. stateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF); Robert. 2009/3/18 Ruqin Zhang <ruzh...@gmail.com> > Yes, the openGL code enabled the back face culling. I think I didn't do > this in osg, my bad. Where should I look for back face culling in osg? > Something in example? Thanks! > > > Ruqin > > 2009/3/18 Robert Osfield <robert.osfi...@gmail.com> > >> Hi Ruqin, >> >> I'm not going to review your code as it's pointless, it's not seeing the >> wood from the trees. Answer the question I asked, is it back face culling >> that you are talking about?? In your OpenGL app did you enable/disable back >> face culling? >> >> Robert. >> >> >> 2009/3/18 Ruqin Zhang <ruzh...@gmail.com> >> >>> Sorry about the confusion. Here is the openGL code that works: >>> >>> *triangle t;* >>> * const float* pFltArrayN = t.getNormal();* >>> * const float* pFltArray1 = t.getVert1();* >>> * const float* pFltArray2 = t.getVert2();* >>> * const float* pFltArray3 = t.getVert3();* >>> >>> * glNormal3fv(pFltArrayN);* >>> * glVertex3fv(pFltArray1);* >>> * glVertex3fv(pFltArray2);* >>> * glVertex3fv(pFltArray3);* >>> * * >>> * a[0] = -pFltArrayN[0];* >>> * a[1] = -pFltArrayN[1];* >>> * a[2] = -pFltArrayN[2];* >>> * glNormal3fv(a);* >>> * glVertex3fv(pFltArray3);* >>> * glVertex3fv(pFltArray2);* >>> * glVertex3fv(pFltArray1);* >>> >>> I tried to do the same thing in osg, here is my code: >>> >>> *osg::ref_ptr<osg::Material> material = new osg::Material(); >>> >>> material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4f(0.00f,0.00f,0.00f,0.00f)); >>> osg::ref_ptr<osg::PolygonMode> polymode = new osg::PolygonMode(); >>> >>> polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::FILL); >>> osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet(); >>> >>> stateset->setAttributeAndModes(material.get(),osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); >>> >>> stateset->setAttributeAndModes(polymode.get(),osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); >>> >>> stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); >>> >>> stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF); >>> * >>> >>> *for(int j = 0; j < mesh->getNumTriangles(); j ++)* >>> *{* >>> * osg::DrawElementsUInt* frontTriElement = new >>> osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES,0);* >>> * frontTriElement->push_back(mesh->getTri(j).getVert1Index());* >>> * frontTriElement->push_back(mesh->getTri(j).getVert2Index());* >>> * frontTriElement->push_back(mesh->getTri(j).getVert3Index());* >>> * meshGeometry->addPrimitiveSet(frontTriElement);* >>> * osg::Vec3f normalVec(mesh->getTri(j).getNormalVec3().x, >>> mesh->getTri(j).getNormalVec3().y,* >>> * >>> mesh->getTri(j).getNormalVec3().z);* >>> * normalArray->push_back(normalVec);* >>> >>> * osg::DrawElementsUInt* backTriElement = new >>> osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES,0);* >>> * backTriElement->push_back(mesh->getTri(j).getVert3Index());* >>> * backTriElement->push_back(mesh->getTri(j).getVert2Index());* >>> * backTriElement->push_back(mesh->getTri(j).getVert1Index());* >>> * meshGeometry->addPrimitiveSet(backTriElement);* >>> * normalArray->push_back(-normalVec);* >>> *}* >>> *meshGeometry->setStateSet(stateset.get());* >>> *meshGeometry->setVertexArray(vertexArray.get());* >>> *meshGeometry->setNormalArray(normalArray.get());* >>> *meshGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);* >>> >>> While seems this doesn't work. Any problem or mistake? Thanks a lot! >>> >>> Ruqin >>> >>> >>> 2009/3/18 Robert Osfield <robert.osfi...@gmail.com> >>> >>>> Hi Ruqin, >>>> >>>> >>>> 2009/3/18 Ruqin Zhang <ruzh...@gmail.com> >>>> >>>>> Thanks Robert. Alright, here is the deal. I'm trying to draw a 3D >>>>> triangular mesh with osg. For some mesh, the calculated normal points >>>>> to the inside. So, I want to draw both the front and back faces, which >>>>> have opposite normals. Then you can render the mesh visible. >>>>> Is there an example of this? Thanks! >>>>> >>>> >>>> Are you talking about two face lighting of back face culling here?? >>>> Originally your email sounded like you were talking about lighting at back >>>> face culling has nothing to do with normals, but this new emails sounds >>>> like >>>> you might be refering to back face culling... >>>> >>>> Robert. >>>> >>>> _______________________________________________ >>>> osg-users mailing list >>>> osg-users@lists.openscenegraph.org >>>> >>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >>>> >>>> >>> >>> >>> >>> _______________________________________________ >>> osg-users mailing list >>> osg-users@lists.openscenegraph.org >>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >>> >>> >> >> _______________________________________________ >> osg-users mailing list >> osg-users@lists.openscenegraph.org >> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >> >> > > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > >
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org