455
社区成员
发帖
与我相关
我的任务
分享
LPDIRECT3DTEXTURE9 m_lpTexture;
LPDIRECT3DSURFACE9 m_lpOffScreenSurface;
// 以下为m_lpDevice和m_lpBackSurface定义,在初始化过程中已经正常获取到对象
// LPDIRECT3DDEVICE9 m_lpDevice;
// LPDIRECT3DSURFACE9 m_lpBackSurface;
// m_lpTexture->GetSurfaceLevel(0, &m_lpOffScreenSurface);
m_lpDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &m_lpBackSurface);
m_lpDevice->SetRenderTarget(0, m_lpOffScreenSurface);
// 将材质清空成纯红色
m_lpDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(200, 0, 0), 1.0f, 0);
D3DXMATRIXA16 w;
m_lpDevice->BeginScene();
m_lpDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
// 以下为m_projection和m_viewport定义
// D3DXMATRIX m_projection;
// D3DXMATRIX m_viewport;
m_lpDevice->SetTransform(D3DTS_PROJECTION, &m_projection);
m_lpDevice->SetTransform(D3DTS_VIEW, &m_viewport);
m_lpDevice->EndScene();
m_lpDevice->SetRenderTarget(0, m_lpBackSurface);
m_lpDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 200, 0), 1.0f, 0);
m_lpDevice->BeginScene();
m_lpDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
// D3DXMatrixPerspectiveFovLH(&m_projection, 45.0f, WINDOW_WIDTH / WINDOW_HEIGHT, .1f, 1000.0f);
m_lpDevice->SetTransform(D3DTS_PROJECTION, &m_projection);
D3DXMatrixRotationY(&w, 120);
m_lpDevice->SetTransform(D3DTS_WORLD, &w);
// 以下为viewport的生成过程
/*D3DXVECTOR3 cameraPos(.0f, .0f, -4.0f);
D3DXVECTOR3 lookAtPos(.0f, .0f, .0f);
D3DXVECTOR3 upDir(.0f, 1.0f, .0f);
D3DXMatrixLookAtLH(&m_viewport, &cameraPos, &lookAtPos, &upDir);*/
m_lpDevice->SetTransform(D3DTS_VIEW, &m_viewport);
m_lpDevice->SetTexture(0, m_lpTexture);
// 以下为三角条带的生成过程
/*D3DVERTEX square[] =
{
{-1, 1, -1, D3DCOLOR_XRGB(255, 255, 255), 0, 0},
{1, 1, -1, D3DCOLOR_XRGB(255, 255, 255), 1, 0},
{-1, -1, -1, D3DCOLOR_XRGB(255, 255, 255), 0, 1},
{1, -1, -1, D3DCOLOR_XRGB(255, 255, 255), 1, 1}
};
m_lpDevice->CreateVertexBuffer(sizeof(square), 0, D3DFVF_VERTEX, D3DPOOL_DEFAULT, &m_lpBuffer, NULL);
void* pData = NULL;
m_lpBuffer->Lock(0, sizeof(square), (void**)&pData, 0);
memcpy(pData, square, sizeof(square));
m_lpBuffer->Unlock();*/
m_lpDevice->SetStreamSource(0, m_lpBuffer, 0, sizeof(D3DVERTEX));
m_lpDevice->SetFVF(D3DFVF_VERTEX);
m_lpDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
m_lpDevice->EndScene();
// 问题来了,材质我已经清空成了纯红色,为何绘制出的三角条带仍然是m_lpTexture携带的原有内容
m_lpDevice->Present(NULL, NULL, NULL, NULL);