DirectX一个很基础很基础的问题。。。。。。
我才开始学DirectX,,一来就遇到了麻烦,,我绘制一个正方形,用了四个顶点,六个索引,但是无论怎样试,它就是不画。。。很无语。。。主要的代码是这样的。。。
//这是顶点和索引的初始化
device->CreateVertexBuffer(
4* sizeof(Vertex),
D3DUSAGE_WRITEONLY,
Vertex::FVF,
D3DPOOL_MANAGED,
&vb,
0 );
device->CreateIndexBuffer(
6* sizeof(WORD),
D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&ib,
0 );
vb->Lock(0, 0, (void** ) &vertexs, 0);
vertexs[0] = Vertex(-1.0f, -1.0f, 5.0f);
vertexs[1] = Vertex(1.0f, -1.0f, 5.0f);
vertexs[1] = Vertex(1.0f, 1.0f, 5.0f);
vertexs[1] = Vertex(-1.0f, 1.0f, 5.0f);
vb->Unlock();
ib->Lock(0, 0, (void** ) &indices, 0);
indices[0] = 0;
indices[1] = 2;
indices[2] = 1;
indices[3] = 0;
indices[4] = 3;
indices[5] = 2;
ib->Unlock();
//这是场景初始化
D3DXVECTOR3 position(0.0f, 0.0f, -5.0f);
D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMATRIX _V;
D3DXMatrixLookAtLH(&_V, &position, &target, &up);
device->SetTransform(D3DTS_VIEW, &_V);
D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(
&proj,
D3DX_PI * 0.5f, // 90 - degree
(float)800 / (float)600,
1.0f,
1000.0f);
device->SetTransform(D3DTS_PROJECTION, &proj);
device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
//绘制代码
device->BeginScene();
device->SetStreamSource(0, vb, 0, sizeof(Vertex));
device->SetIndices(ib);
device->SetFVF(Vertex::FVF);
device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 6, 0, 4);
device->EndScene();
各位大大看一看,帮帮忙啊。。。
[解决办法]
在绘制代码最后加device->Present(0, 0, 0, 0);
[解决办法]
1检查你的绕序
2把你的backfuffer设为其他颜色