Hi Raqin,<br><br>To enable/disabe modes in OSG you use:<br><br>   stateset->setMode(GLenum, osg::StateAttribute::ON/OFF);<br><br>In you case you probably want to disable back face culling.<br><br>  stateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);<br>
<br>Robert.<br><br><div class="gmail_quote">2009/3/18 Ruqin Zhang <span dir="ltr"><<a href="mailto:ruzhang@gmail.com">ruzhang@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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?<br>Something in example? Thanks!<div><div></div><div class="h5"><br><br>Ruqin<br>
<br><div class="gmail_quote">
2009/3/18 Robert Osfield <span dir="ltr"><<a href="mailto:robert.osfield@gmail.com" target="_blank">robert.osfield@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Hi Ruqin,<br><br>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?<br>

<font color="#888888">
<br>Robert.</font><div><div></div><div><br><br><div class="gmail_quote">2009/3/18 Ruqin Zhang <span dir="ltr"><<a href="mailto:ruzhang@gmail.com" target="_blank">ruzhang@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


Sorry about the confusion. Here is the openGL code that works:<br><br>                    <i>triangle t;</i><br><i>                    const float* pFltArrayN = t.getNormal();</i><br><i>                    const float* pFltArray1 = t.getVert1();</i><br>



<i>                    const float* pFltArray2 = t.getVert2();</i><br><i>                    const float* pFltArray3 = t.getVert3();</i><br><br><i>                    glNormal3fv(pFltArrayN);</i><br><i>                    glVertex3fv(pFltArray1);</i><br>



<i>                    glVertex3fv(pFltArray2);</i><br><i>                    glVertex3fv(pFltArray3);</i><br><i>        </i><br><i>                    a[0] = -pFltArrayN[0];</i><br><i>                    a[1] = -pFltArrayN[1];</i><br>



<i>                    a[2] = -pFltArrayN[2];</i><br><i>                    glNormal3fv(a);</i><br><i>                    glVertex3fv(pFltArray3);</i><br><i>                    glVertex3fv(pFltArray2);</i><br><i>                    glVertex3fv(pFltArray1);</i><br>



<br>I tried to do the same thing in osg, here is my code:<br><br><div style="margin-left: 120px;"><i>osg::ref_ptr<osg::Material> material = new osg::Material();  <br>material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4f(0.00f,0.00f,0.00f,0.00f));<br>



osg::ref_ptr<osg::PolygonMode> polymode = new osg::PolygonMode();<br>polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::FILL);<br>osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet();<br>



stateset->setAttributeAndModes(material.get(),osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);<br>stateset->setAttributeAndModes(polymode.get(),osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);<br>stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);<br>



stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);</i><br><br></div><div style="margin-left: 120px;"><i>for(int j = 0; j < mesh->getNumTriangles(); j ++)</i><br><i>{</i><br>



<i>        osg::DrawElementsUInt* frontTriElement = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES,0);</i><br><i>        frontTriElement->push_back(mesh->getTri(j).getVert1Index());</i><br><i>        frontTriElement->push_back(mesh->getTri(j).getVert2Index());</i><br>



<i>        frontTriElement->push_back(mesh->getTri(j).getVert3Index());</i><br><i>        meshGeometry->addPrimitiveSet(frontTriElement);</i><br><i>        osg::Vec3f normalVec(mesh->getTri(j).getNormalVec3().x, mesh->getTri(j).getNormalVec3().y,</i><br>



<i>                                                                mesh->getTri(j).getNormalVec3().z);</i><br><i>        normalArray->push_back(normalVec);</i><br><br><i>        osg::DrawElementsUInt* backTriElement = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES,0);</i><br>



<i>        backTriElement->push_back(mesh->getTri(j).getVert3Index());</i><br><i>        backTriElement->push_back(mesh->getTri(j).getVert2Index());</i><br><i>        backTriElement->push_back(mesh->getTri(j).getVert1Index());</i><br>



<i>        meshGeometry->addPrimitiveSet(backTriElement);</i><br><i>        normalArray->push_back(-normalVec);</i><br><i>}</i><br><i>meshGeometry->setStateSet(stateset.get());</i><br><i>meshGeometry->setVertexArray(vertexArray.get());</i><br>



<i>meshGeometry->setNormalArray(normalArray.get());</i><br><i>meshGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);</i><br></div><br>While seems this doesn't work. Any problem or mistake? Thanks a lot!<br>



<br>Ruqin<br><br><br><div class="gmail_quote"><div>2009/3/18 Robert Osfield <span dir="ltr"><<a href="mailto:robert.osfield@gmail.com" target="_blank">robert.osfield@gmail.com</a>></span><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">



Hi Ruqin,<div><div></div><div><br><br><div class="gmail_quote"><div>2009/3/18 Ruqin Zhang <span dir="ltr"><<a href="mailto:ruzhang@gmail.com" target="_blank">ruzhang@gmail.com</a>></span><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">




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<div><br>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.<br>





Is there an example of this? Thanks!<br></div></blockquote></div><br>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...<br>



<font color="#888888">
<br>Robert.<br>
</font><br></div></div><div>_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
<br></div></blockquote></div><br><br clear="all"><br>
<br>_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
<br></blockquote></div><br>
</div></div><br>_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
<br></blockquote></div><br><br>
</div></div><br>_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
<br></blockquote></div><br>