DirectX一个很基础很基础的问题。。。。。。
时间:2011-11-11
来源:互联网
我才开始学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->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();
各位大大看一看,帮帮忙啊。。。
作者: p418801086 发布时间: 2011-11-11
绘制代码缺
device->Present(0, 0, 0, 0);
作者: freeman040921 发布时间: 2011-11-11
在绘制代码最后加device->Present(0, 0, 0, 0);
作者: freeman040921 发布时间: 2011-11-11
device->Present(0, 0, 0, 0);我是加了的。。。还是没有画出来啊。。。
作者: p418801086 发布时间: 2011-11-11
1检查你的绕序
2把你的backfuffer设为其他颜色
2把你的backfuffer设为其他颜色
作者: Baesky 发布时间: 2011-11-11
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28