Direct3D 9学习笔记(3)基本顶点绘制
2012-07-27 14:30 Clingingboy 阅读(1128) 评论(0) 编辑 收藏 举报
一.顶点缓存和索引缓存概念
二.顶点缓存
HRESULT CreateVertexBuffer(
[in] UINT Length,
[in] DWORD Usage,
[in] DWORD FVF,
[in] D3DPOOL Pool,
[out, retval] IDirect3DVertexBuffer9 **ppVertexBuffer,
[in] HANDLE *pSharedHandle
);
http://msdn.microsoft.com/en-us/library/windows/desktop/bb174364(v=vs.85).aspx
如下顶点数据结构
struct Vertex
{
Vertex(){}
Vertex(float x, float y, float z)
{
_x = x; _y = y; _z = z;
}
float _x, _y, _z;
static const DWORD FVF;
};
然后创建一个顶点缓存
Device->CreateVertexBuffer(
3 * sizeof(Vertex), // size in bytes
D3DUSAGE_WRITEONLY, // flags
Vertex::FVF, // vertex format
D3DPOOL_MANAGED, // managed memory pool
&Triangle, // return create vertex buffer
0); // not used - set to 0
三.向顶点缓存写数据
http://msdn.microsoft.com/en-us/library/windows/desktop/bb205915(v=vs.85).aspx
//
// Fill the buffers with the triangle data.
//
Vertex* vertices;
Triangle->Lock(0, 0, (void**)&vertices, 0);
vertices[0] = Vertex(-1.0f, 0.0f, 2.0f);
vertices[1] = Vertex( 0.0f, 1.0f, 2.0f);
vertices[2] = Vertex( 1.0f, 0.0f, 2.0f);
Triangle->Unlock();
四.获取顶点坐标信息
/* Vertex Buffer Description */
typedef struct _D3DVERTEXBUFFER_DESC
{
D3DFORMAT Format;
D3DRESOURCETYPE Type;
DWORD Usage;
D3DPOOL Pool;
UINT Size;
DWORD FVF;
} D3DVERTEXBUFFER_DESC;
D3DVERTEXBUFFER_DESC desc={};
Triangle->GetDesc(&desc);
五.设置绘制状态
使用IDirect3DDevice9接口的SetRenderState方法设置
Device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
比如顶点的绘制方法可以是点或填充,上面D3DFILL_WIREFRAME是以连接点来绘制
六.
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步