- 积分
- 24
- 帖子
- 3
- 主题
- 1
- 精华
- 0
- 最后登录
- 2019-5-10
- 在线时间
- 4 小时
- 私信
|
发表时间 : 2010-4-29 16:10:58
|
浏览 : 1221 评论 : 2
vp中光照加入用opengl绘制的物体会闪烁
按照版上vp加入opengl的方法试验了一下,发现一个问题:光照加入后用opengl绘制的物体会闪烁,各位大牛如何解决?
附:代码如下:
void wApp::notify(vsChannel::Event event, const vsChannel *channel,vrDrawContext *context)
{
if (event == vsChannel::EVENT_PRE_DRAW)
{
}
else if (event == vsChannel::EVENT_POST_DRAW)
{
vrTransform::ElementProjection projectionElement;
projectionElement.m_matrix = channel->getVrChannel()->getProjectionMatrix();
vrTransform::ElementModelView modelViewElement;
modelViewElement.m_matrix = channel->getVrChannel()->getViewMatrixInverse();
context->pushElements(true);
context->setElement(vrTransform::ElementProjection::Id,&projectionElement, true);
vuMatrix<float> rotMat;
rotMat.makeRotate(0.0f,-90.0f,0.0f);
modelViewElement.m_matrix.postMultiply(rotMat);
context->setElement(vrTransform::ElementModelView::Id,&modelViewElement, true);
/************在此添加OPENGL代码**************/
glPushAttrib(GL_ALL_ATTRIB_BITS);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
GLfloat m_materialAmb[4];
GLfloat m_materialDif[4];
GLfloat m_materialSpe[4];
GLfloat m_matShininess;
m_materialAmb[0]=0.1f;
m_materialAmb[1]=0.1f;
m_materialAmb[2]=0.1f;
m_materialAmb[3]=1.0f;
m_materialDif[0]=0.9f;
m_materialDif[1]=0.9f;
m_materialDif[2]=0.9f;
m_materialDif[3]=1.0f;
m_materialSpe[0]=0.2f;
m_materialSpe[1]=0.2f;
m_materialSpe[2]=0.2f;
m_materialSpe[3]=1.0f;
m_matShininess=18.0;
glMaterialfv(GL_FRONT, GL_AMBIENT, m_materialAmb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, m_materialDif);
glMaterialfv(GL_FRONT, GL_SPECULAR, m_materialSpe);
glMaterialf(GL_FRONT, GL_SHININESS, m_matShininess);
GLfloat m_lightAmb[4], m_lightDif[4], m_lightSpe[4];
m_lightAmb[0] = 0.3f;
m_lightAmb[1] = 0.3f;
m_lightAmb[2] = 0.3f;
m_lightAmb[3] = 1.0f;
m_lightDif[0] = 0.9f;
m_lightDif[1] = 0.9f;
m_lightDif[2] = 0.9f;
m_lightDif[3] = 1.0f;
m_lightSpe[0] = 0.0f;
m_lightSpe[1] = 0.0f;
m_lightSpe[2] = 0.0f;
m_lightSpe[3] = 1.0f;
glLightfv(GL_LIGHT0, GL_AMBIENT, m_lightAmb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, m_lightDif);
glLightfv(GL_LIGHT0, GL_SPECULAR, m_lightSpe);
glutSolidSphere(20, 16, 8);
glPopAttrib();
/************在此添加OPENGL代码**************/
context->popElements();
}
} |
|