CEGUI与DX(Direct3D)渲染的冲突问题

  今天在工程里直接调用D3D的API画了一个旋转的三角体(可以理解为金字塔),但是一调用CEGUI的渲染之后,金字塔就无法渲染出来,只要不调用CEGUI::System的renderGUI(),就可以渲染出来,所以觉得应该是跟CEGUI内部渲染有冲突。

        查了下网上的资料,果然有反映说CEGUI更改了渲染状态,但没有改回来导致渲染失败。看了下CEGUI的源码,如下:

void Direct3D9Renderer::beginRendering()
{
d_device->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);

// no shaders initially
d_device->SetVertexShader(0);
d_device->SetPixelShader(0);

// set device states
d_device->SetRenderState(D3DRS_LIGHTING, FALSE);

     d_device->SetRenderState(D3DRS_FOGENABLE, FALSE);
d_device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
d_device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
d_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
d_device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
d_device->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);
d_device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);

// setup texture addressing settings
d_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
d_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);

// setup colour calculations
d_device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
d_device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
d_device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);

// setup alpha calculations
d_device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
d_device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
d_device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);

// setup filtering
d_device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
d_device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);

// disable texture stages we do not need.
d_device->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);

// setup scene alpha blending
d_device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
d_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
d_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

// set view matrix back to identity.
d_device->SetTransform(D3DTS_VIEW, &s_identityMatrix);

}

//----------------------------------------------------------------------------//

void Direct3D9Renderer::endRendering()
{
}

果然如此,结束时并没有对更改过的渲染状态做任何改变。于是在渲染自己的东西前,增加以下代码:

    // Revert RenderState 

m_pDirect3DDevice->SetRenderState(D3DRS_LIGHTING, true);
m_pDirect3DDevice -> SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW );
m_pDirect3DDevice -> SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE );

    // Position and aim the camera.

D3DXVECTOR3 pos(0.0f, 1.0f, -3.0f);
D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMATRIX V;
D3DXMatrixLookAtLH(&V, &pos, &target, &up);
m_pDirect3DDevice->SetTransform(D3DTS_VIEW, &V);

// Set the projection matrix.

D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(
&proj,
D3DX_PI * 0.5f, // 90 - degree
(float)800 / (float)600,
1.0f,
1000.0f);
m_pDirect3DDevice->SetTransform(D3DTS_PROJECTION, &proj);

最终成功~~哦也~~

总结解决办法:

1 更改CEGUI源代码,使用完CEGUI后将其更改过的状态全部设置回来(不靠谱,因为不知道哪些改变过,哪些其实并没改变过)、

2 在调用DX渲染之前,务必将所有应该设置的渲染状态,还有摄像机镜头位置等设置一遍,要意识到CEGUI有对其经行过改动。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值