[D3D]DrawPrimitive无法显示绘图问题
时间:2011-08-02
来源:互联网
code 如下:
const DWORD ColorVertex::FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
IDirect3DDevice9* Device = NULL;
IDirect3DVertexBuffer9* VB = NULL;
D3DXMATRIX world;
struct ColorVertex
{
ColorVertex(){};
ColorVertex(float x,float y,float z,D3DCOLOR cl)
{
_x = x;_y = y;_z = z;_color = cl;
}
float _x,_y,_z;
D3DCOLOR _color;
static const DWORD FVF;
};
BOOL Setup()
{
Device->CreateVertexBuffer(3 * sizeof(ColorVertex),D3DUSAGE_WRITEONLY,ColorVertex::FVF,D3DPOOL_MANAGED,&VB,0);
ColorVertex* v;
VB->Lock(0,0,(void**)&v,0);
v[0] = ColorVertex(-1.0f,0.0f,2.0f,RED);
v[1] = ColorVertex(0.0f,1.0f,2.0f,GREEN);
v[2] = ColorVertex(1.0f,0.0f,2.0f,BLUE);
VB->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 Vi;
D3DXMatrixLookAtLH(&Vi,&position,&target,&up);
Device->SetTransform(D3DTS_VIEW,&Vi);
//投影矩阵
D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(&proj,D3DX_PI * 0.5f,600/800,1.0f,1000.0f);
Device->SetTransform(D3DTS_PROJECTION,&proj);
//渲染模式
//Device->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
//屏蔽灯光
Device->SetRenderState(D3DRS_LIGHTING,FALSE);
return TRUE;
}
BOOL Display(float timeDetal)
{
if (Device)
{
Device->Clear(0,0,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,0xffffffff,1.0f,0);
Device->BeginScene();
Device->SetFVF(Vertex::FVF);
Device->SetStreamSource(0,VB,0,sizeof(Vertex));
D3DXMatrixTranslation(&world,-1.25f,0.0f,0.0f);
Device->SetTransform(D3DTS_WORLD,&world);
Device->SetRenderState(D3DRS_SHADEMODE,D3DSHADE_FLAT);
Device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
D3DXMatrixTranslation(&world,1.25f,0.0f,0.0f);
Device->SetTransform(D3DTS_WORLD,&world);
Device->SetRenderState(D3DRS_SHADEMODE,D3DSHADE_GOURAUD);
Device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
Device->EndScene();
Device->Present(0,0,0,0);
}
return TRUE;
}
进行了视图,投影,世界的转换,屏蔽了灯光,运行效果是:什么都没有,编译通过,请问是哪出问题?
const DWORD ColorVertex::FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
IDirect3DDevice9* Device = NULL;
IDirect3DVertexBuffer9* VB = NULL;
D3DXMATRIX world;
struct ColorVertex
{
ColorVertex(){};
ColorVertex(float x,float y,float z,D3DCOLOR cl)
{
_x = x;_y = y;_z = z;_color = cl;
}
float _x,_y,_z;
D3DCOLOR _color;
static const DWORD FVF;
};
BOOL Setup()
{
Device->CreateVertexBuffer(3 * sizeof(ColorVertex),D3DUSAGE_WRITEONLY,ColorVertex::FVF,D3DPOOL_MANAGED,&VB,0);
ColorVertex* v;
VB->Lock(0,0,(void**)&v,0);
v[0] = ColorVertex(-1.0f,0.0f,2.0f,RED);
v[1] = ColorVertex(0.0f,1.0f,2.0f,GREEN);
v[2] = ColorVertex(1.0f,0.0f,2.0f,BLUE);
VB->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 Vi;
D3DXMatrixLookAtLH(&Vi,&position,&target,&up);
Device->SetTransform(D3DTS_VIEW,&Vi);
//投影矩阵
D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(&proj,D3DX_PI * 0.5f,600/800,1.0f,1000.0f);
Device->SetTransform(D3DTS_PROJECTION,&proj);
//渲染模式
//Device->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
//屏蔽灯光
Device->SetRenderState(D3DRS_LIGHTING,FALSE);
return TRUE;
}
BOOL Display(float timeDetal)
{
if (Device)
{
Device->Clear(0,0,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,0xffffffff,1.0f,0);
Device->BeginScene();
Device->SetFVF(Vertex::FVF);
Device->SetStreamSource(0,VB,0,sizeof(Vertex));
D3DXMatrixTranslation(&world,-1.25f,0.0f,0.0f);
Device->SetTransform(D3DTS_WORLD,&world);
Device->SetRenderState(D3DRS_SHADEMODE,D3DSHADE_FLAT);
Device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
D3DXMatrixTranslation(&world,1.25f,0.0f,0.0f);
Device->SetTransform(D3DTS_WORLD,&world);
Device->SetRenderState(D3DRS_SHADEMODE,D3DSHADE_GOURAUD);
Device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
Device->EndScene();
Device->Present(0,0,0,0);
}
return TRUE;
}
进行了视图,投影,世界的转换,屏蔽了灯光,运行效果是:什么都没有,编译通过,请问是哪出问题?
作者: lf723 发布时间: 2011-08-02
把代码格式化一下啊, 这样看着头疼。
作者: ilysony 发布时间: 2011-08-02
回复了不能编辑了? 一些创建在Setup里面做的,Display负责画出来
作者: lf723 发布时间: 2011-08-02
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28