我要发帖 回复

正式会员

1

主题

24

积分

0

专家分

:

私信
发表时间 : 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();
       
        }
}

最近VR访客

sichuanwww 评论于2010-4-29 21:07:01
我也发现了同样的问题,所以用VSG画.
努力挣钱,快乐生活!
jgy86324 评论于2010-5-20 14:18:35
我也出现这种情况,会闪烁,我把代码改成画一个简单的长方形,结果在VP中不能够显示,然后把那段需要让VP和IOPENGL的坐标一致的代码去掉又可以看到长方形了,不是VP和OPENGL中坐标的表示不是一样的嘛?没有搞明白

手机版|VR开发网 统计 津ICP备18009691号
网安备12019202000257

GMT+8, 2023-3-20 06:01 PM

返回顶部