Problem:
I get a problem with the exercise in the 《Introduction To 3D Game Programming with DirectX 9.0, A shade Approach》. In the chapter 7 ,exercise 1 .
I want to draw polyline with the DrawPrimitive() method . Here is my code about the vertex buffer :
void Exercise::buildVB()
{
IDirect3DDevice9* _pDevice = m_pD3d->getDevice();
HR(_pDevice->CreateVertexBuffer(6 * sizeof(VertexPos),D3DUSAGE_WRITEONLY,0,
D3DPOOL_MANAGED,&m_pVB,0));
VertexPos * _pData = NULL ;
HR(m_pVB->Lock(0,0,(void**)&_pData,0));
_pData[0] = VertexPos(0.0f, 0.0f, 0.0f);
_pData[1] = VertexPos(0.1f, -0.3f,0.0f );
_pData[2] = VertexPos(0.3f, -0.2f, 0.0f);
_pData[3] = VertexPos(0.2f, -0.1f,0.0f );
_pData[4] = VertexPos(0.25f, 0.1f,0.0f );
_pData[5] = VertexPos(0.1f, 0.3f,0.0f );
HR(m_pVB->Unlock());
}
When I draw the image with the following method , it is OK . The image will display . Here is my code :
void Exercise::draw()
{
IDirect3DDevice9* _pDevice = m_pD3d->getDevice();
HR(_pDevice->SetStreamSource(0,m_pVB,0,sizeof(VertexPos)));
HR(_pDevice->SetVertexDeclaration(VertexPos::_vertexDecl));
HR(_pDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME));
HR(_pDevice->DrawPrimitive(D3DPT_LINESTRIP,0,6));
}
But , when I draw the image with the following code , I can not see image in screen .
void Exercise::draw()
{
IDirect3DDevice9* _pDevice = m_pD3d->getDevice();
HR(_pDevice->SetStreamSource(0,m_pVB,0,sizeof(VertexPos)));
HR(_pDevice->SetVertexDeclaration(VertexPos::_vertexDecl));
D3DXMATRIX _worldM ;
HR(_pDevice->SetTransform(D3DTS_WORLD,D3DXMatrixIdentity(&_worldM)));
HR(_pDevice->SetTransform(D3DTS_VIEW,&m_ViewM));
HR(_pDevice->SetTransform(D3DTS_PROJECTION,&m_ProjM));
HR(_pDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME));
HR(_pDevice->DrawPrimitive(D3DPT_LINESTRIP,0,6));
}
The view matrix and projection matrix is here :
void Exercise::buildViewM()
{
D3DXVECTOR3 _pos(0.0f,0.0f,-10);
D3DXVECTOR3 _target(0.0f,0.0f,0.0f);
D3DXVECTOR3 _up(0.0f,1.0f,0.0f);
D3DXMatrixLookAtLH(&m_ViewM,&_pos,&_target,&_up);
}
void Exercise::buildProjM()
{
float _width = m_pD3d->getD3dParam().BackBufferWidth;
float _height = m_pD3d->getD3dParam().BackBufferHeight;
D3DXMatrixPerspectiveFovLH(&m_ProjM,D3DX_PI,_width/_height,1.0f,1000.0f);
}
I draw a image in x-y plane , and then put the eye in the (0.0f,0.0f,-10.0f) . I do not understand why I can not see the image .
Is there anyone who can help me ?