Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :
C#
void Exercise::buildVB()
{
    //get Direct3D Device
    IDirect3DDevice9* _pDevice = m_pD3d->getDevice();

    //craete the vertex buffer
    HR(_pDevice->CreateVertexBuffer(6 * sizeof(VertexPos),D3DUSAGE_WRITEONLY,0,
        D3DPOOL_MANAGED,&m_pVB,0));

    //lock the vertex buffer
    VertexPos * _pData = NULL ;
    HR(m_pVB->Lock(0,0,(void**)&_pData,0));

    //set the vertex
    /*_pData[0] = VertexPos(0.0f, 0.0f, 0.0f);
    _pData[1] = VertexPos(1.0f, 0.0f, -3.0f);
    _pData[2] = VertexPos(3.0f, 0.0f, -2.0f);
    _pData[3] = VertexPos(2.0f, 0.0f, -1.0f);
    _pData[4] = VertexPos(2.5f, 0.0f, 1.0f);
    _pData[5] = VertexPos(1.0f, 0.0f, 3.0f);*/
    _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 );


    //unlock the vertex buffer
    HR(m_pVB->Unlock());
}



When I draw the image with the following method , it is OK . The image will display . Here is my code :
C#
void Exercise::draw()
{
    //get Direct3D Device
    IDirect3DDevice9* _pDevice = m_pD3d->getDevice();

    //set stream source
    HR(_pDevice->SetStreamSource(0,m_pVB,0,sizeof(VertexPos)));

    //set the index
    //HR(_pDevice->SetIndices(m_pIB));

    //set the vertex declaration
    HR(_pDevice->SetVertexDeclaration(VertexPos::_vertexDecl));

    //set the world matrix
    //D3DXMATRIX _worldM ;
    //HR(_pDevice->SetTransform(D3DTS_WORLD,D3DXMatrixIdentity(&_worldM)));

    //set the view matrix
    //HR(_pDevice->SetTransform(D3DTS_VIEW,&m_ViewM));

    //set the projection matrix
    //HR(_pDevice->SetTransform(D3DTS_PROJECTION,&m_ProjM));

    //set the render state
    HR(_pDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME));

    //draw the primitive
    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()
{
	//get Direct3D Device
	IDirect3DDevice9* _pDevice = m_pD3d->getDevice();

	//set stream source
	HR(_pDevice->SetStreamSource(0,m_pVB,0,sizeof(VertexPos)));

	//set the index
	//HR(_pDevice->SetIndices(m_pIB));

	//set the vertex declaration
	HR(_pDevice->SetVertexDeclaration(VertexPos::_vertexDecl));

	//set the world matrix
	D3DXMATRIX _worldM ;
	HR(_pDevice->SetTransform(D3DTS_WORLD,D3DXMatrixIdentity(&_worldM)));

	//set the view matrix
	HR(_pDevice->SetTransform(D3DTS_VIEW,&m_ViewM));

	//set the projection matrix
	HR(_pDevice->SetTransform(D3DTS_PROJECTION,&m_ProjM));

	//set the render state
	HR(_pDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME));

	//draw the primitive
	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 ?
Posted
Comments
UfnCod3r 21-Sep-13 4:31am    
Error 0x3434FA3 : Invalid FOV And ZNearPlane. check it ;)

1 solution

Yeah, I had solved it . How do you get the error code ? What method do you use ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900