|
楼主 |
发表于 2013-4-1 21:35:46
|
显示全部楼层
void CPlane::drawImplementation(osg::RenderInfo& renderInfo) const
{
GLfloat knotsU[4]= { 0, 0, 1, 1 };
GLfloat knotsV[4]= { 0, 0, 1, 1 };
GLfloat textureCntrlPnt[2][2][2] = {
{{0.0f,0.0f},{0.0f,1.0f}},
{{1.0f,0.0f},{1.0f,1.0f}}
};
GLfloat BigPlanectrlp[2][2][3];
for(int i =0 ;i<2;i++)
for(int j =0;j<2 ;j++)
for(int k =0; k<3;k++)
{
BigPlanectrlp[i][j][k]=bigplane_ctrlp[i][j][k];
}
glPushAttrib(GL_ENABLE_BIT | GL_EVAL_BIT);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
GLUnurbsObj *theNurb = gluNewNurbsRenderer();
//////////////////回调函数用到的设置/////////////////////////////
gluNurbsProperty(theNurb,GLU_SAMPLING_METHOD,GLU_DOMAIN_DISTANCE);
gluNurbsProperty(theNurb,GLU_NURBS_MODE,GLU_NURBS_TESSELLATOR);
gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE,1000.0);
gluNurbsProperty(theNurb, GLU_U_STEP, 5);
gluNurbsProperty(theNurb, GLU_V_STEP, 5);
gluNurbsProperty(theNurb,GLU_DISPLAY_MODE,GLU_FILL);
gluNurbsCallback(theNurb, GLU_NURBS_BEGIN, (void (__stdcall *)())beginCallback_plane);
gluNurbsCallback(theNurb,GLU_NURBS_VERTEX,(void (__stdcall *)())vertexCallback_plane);
gluNurbsCallback(theNurb,GLU_NURBS_NORMAL,(void (__stdcall *)())normalCallback_plane);
gluNurbsCallback(theNurb,GLU_NURBS_END,(void (__stdcall *)())endCallback_plane);
///////////////////////////////////////////////
gluNurbsProperty(theNurb,GLU_SAMPLING_TOLERANCE,100.0);
gluNurbsProperty(theNurb,GLU_DISPLAY_MODE,GLU_FILL);
gluBeginSurface(theNurb);
gluNurbsSurface(theNurb, //// 用大平面控制点bigplane_ctrlp画大平面
4, knotsU, 4,knotsV,
2*3, 3, &BigPlanectrlp[0][0][0],
2, 2,GL_MAP2_VERTEX_3);
gluNurbsSurface(theNurb,4,knotsU,4,knotsV,4,2,
(float *)textureCntrlPnt,
2,2,
GL_MAP2_TEXTURE_COORD_2);
TrimFunction(theNurb);
gluEndSurface(theNurb);
glPopAttrib();
} 重载的这个函数,有纹理坐标,模仿的是例子里的茶壶,不过茶壶那个是用 beizier曲面画的,这个是nurbs。然后用 osg里边的添加贴图状态的函数。
plane->getOrCreateStateSet()->setTextureAttributeAndModes(0,new osg::Texture2D(osgDB::readImageFile(photoname)));
然后添加到根节点下。
刚开始用的 openGL1.0 的库, 可以贴上纹理,换成2.0后主要是那个openGL32.dll 后就没有纹理了 求解释!因为需要和面求交,要用到 openGL2.0的库。然后 就没纹理了怎么办啊?
|
|